'use client'; import { useState } from 'react'; import { ActionIcon, Drawer, Tooltip, Stack, Title, Text, Alert, ScrollArea, Box, Group, CloseButton, Skeleton, Button, Anchor, Container, } from '@mantine/core'; import { TbBook2, TbExternalLink, TbLink, TbLinkOff } from 'react-icons/tb'; import { MdErrorOutline } from 'react-icons/md'; import { fetchReaderContent, type ReaderState, } from '../../lib/fetchReaderContent'; import styles from './ReaderButton.module.css'; interface Props { url: string; } const FONT_SIZE_MIN = 14; const FONT_SIZE_MAX = 24; const FONT_SIZE_STEP = 2; const FONT_SIZE_DEFAULT = 17; function ArticleSkeleton() { return ( {[100, 95, 88, 100, 92, 78, 100, 96, 83, 60].map((w, i) => ( ))} {[100, 91, 100, 85, 100, 72].map((w, i) => ( ))} ); } export default function ReaderButton({ url }: Props) { const [opened, setOpened] = useState(false); const [state, setState] = useState({ status: 'idle' }); const [fontSize, setFontSize] = useState(FONT_SIZE_DEFAULT); const [removeLinks, setRemoveLinks] = useState(false); const displayedHtml = state.status === 'success' ? removeLinks ? state.data.content.replace(/]*>([\s\S]*?)<\/a>/g, '$1') : state.data.content : ''; function openReader() { setOpened(true); if (state.status === 'success' || state.status === 'loading') return; fetchReaderContent(url, setState); } function handleClose() { setOpened(false); } return ( <> {/* ── Scrollable article area ── */} {state.status === 'loading' && } {state.status === 'error' && ( } title="Could not load reader" color="red" variant="light" > {state.message} )} {state.status === 'success' && ( {state.data.siteName && ( {state.data.siteName} )} {state.data.title && ( {state.data.title} )} {state.data.byline && ( {state.data.byline} )} )} {/* ── Sticky bottom bar ── */} {/* Left: font size + link toggle */} setFontSize((s) => Math.max(FONT_SIZE_MIN, s - FONT_SIZE_STEP), ) } disabled={fontSize <= FONT_SIZE_MIN} aria-label="Decrease font size" > A- setFontSize((s) => Math.min(FONT_SIZE_MAX, s + FONT_SIZE_STEP), ) } disabled={fontSize >= FONT_SIZE_MAX} aria-label="Increase font size" > A+ setRemoveLinks((v) => !v)} aria-label={removeLinks ? 'Show links' : 'Remove links'} > {removeLinks ? : } {/* Right: open original + close */} ); }