import { Trans } from "@lingui/react/macro" import { Anchor, Box, Button, Code, Container, Divider, Group, Input, Alert as MantineAlert, NumberInput, Stack, Text, TextInput, Title, } from "@mantine/core" import { useForm } from "@mantine/form" import { openConfirmModal } from "@mantine/modals" import { useEffect } from "react" import { useAsync, useAsyncCallback } from "react-async-hook" import { TbAlertTriangle, TbDeviceFloppy, TbTrash } from "react-icons/tb" import { useParams } from "react-router-dom" import { client, errorToStrings } from "@/app/client" import { redirectToRootCategory, redirectToSelectedSource } from "@/app/redirect/thunks" import { useAppDispatch, useAppSelector } from "@/app/store" import { reloadTree } from "@/app/tree/thunks" import type { FeedModificationRequest } from "@/app/types" import { Alert } from "@/components/Alert" import { CategorySelect } from "@/components/content/add/CategorySelect" import { FilteringExpressionEditor } from "@/components/content/edit/FilteringExpressionEditor" import { Loader } from "@/components/Loader" import { RelativeDate } from "@/components/RelativeDate" export function FeedDetailsPage() { const { id } = useParams() if (!id) throw new Error("id required") const apiKey = useAppSelector(state => state.user.profile?.apiKey) const dispatch = useAppDispatch() const query = useAsync(async () => await client.feed.get(id), [id]) const feed = query.result?.data const form = useForm() const { setValues } = form const modifyFeed = useAsyncCallback(client.feed.modify, { onSuccess: () => { dispatch(reloadTree()) dispatch(redirectToSelectedSource()) }, }) const unsubscribe = useAsyncCallback(client.feed.unsubscribe, { onSuccess: () => { dispatch(reloadTree()) dispatch(redirectToRootCategory()) }, }) const openUnsubscribeModal = () => { const feedName = feed?.name openConfirmModal({ title: Unsubscribe, children: ( Are you sure you want to unsubscribe from {feedName}? ), labels: { confirm: Confirm, cancel: Cancel }, confirmProps: { color: "red" }, onConfirm: () => { unsubscribe.execute({ id: +id }) }, }) } useEffect(() => { if (!feed) return setValues(feed) }, [setValues, feed]) if (!feed) return return ( {modifyFeed.error && ( )} {unsubscribe.error && ( )}
{feed.name} Feed URL}> {feed.feedUrl} Website}> {feed.feedLink} Last refresh}> Last refresh message}> {feed.message ?? N/A} Next refresh}> Generated feed url}> {apiKey && ( Link )} {!apiKey && Generate an API key in your profile first.} Name} {...form.getInputProps("name")} required /> Category} {...form.getInputProps("categoryId")} clearable /> Position} {...form.getInputProps("position")} required min={0} /> Filtering expression} description={ Build a filter expression to indicate what you want to read. Entries that don't match will be marked as read automatically. } > {feed.filterLegacy && ( }> This feed has a legacy filter that cannot be edited and is not applied. Please recreate the filter using the new expression editor. The legacy filter expression was: {feed.filterLegacy} )} form.setFieldValue("filter", value)} />
) }