"use client"; import React from "react"; import Link from "next/link"; import { ActionButton } from "@/components/ui/action-button"; import { Form, FormControl, FormField, FormItem, FormLabel, FormMessage, } from "@/components/ui/form"; import { FullPageSpinner } from "@/components/ui/full-page-spinner"; import { Input } from "@/components/ui/input"; import { toast } from "@/components/ui/use-toast"; import { api } from "@/lib/trpc"; import { cn } from "@/lib/utils"; import { zodResolver } from "@hookform/resolvers/zod"; import { ArrowDownToLine, CheckCircle, CircleDashed, Edit, FlaskConical, Plus, Save, Trash2, XCircle, } from "lucide-react"; import { useForm } from "react-hook-form"; import { z } from "zod"; import { ZFeed, zNewFeedSchema, zUpdateFeedSchema, } from "@hoarder/shared/types/feeds"; import ActionConfirmingDialog from "../ui/action-confirming-dialog"; import { Button, buttonVariants } from "../ui/button"; import { Dialog, DialogClose, DialogContent, DialogFooter, DialogHeader, DialogTitle, DialogTrigger, } from "../ui/dialog"; import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow, } from "../ui/table"; import { Tooltip, TooltipContent, TooltipTrigger } from "../ui/tooltip"; export function FeedsEditorDialog() { const [open, setOpen] = React.useState(false); const apiUtils = api.useUtils(); const form = useForm>({ resolver: zodResolver(zNewFeedSchema), defaultValues: { name: "", url: "", }, }); React.useEffect(() => { if (open) { form.reset(); } }, [open]); const { mutateAsync: createFeed, isPending: isCreating } = api.feeds.create.useMutation({ onSuccess: () => { toast({ description: "Feed has been created!", }); apiUtils.feeds.list.invalidate(); setOpen(false); }, }); return ( Subscribe to a new Feed
{ await createFeed(value); form.resetField("name"); form.resetField("url"); })} > { return ( Name ); }} /> { return ( URL ); }} /> { await createFeed(value); })} loading={isCreating} variant="default" className="items-center" > Add
); } export function EditFeedDialog({ feed }: { feed: ZFeed }) { const apiUtils = api.useUtils(); const [open, setOpen] = React.useState(false); React.useEffect(() => { if (open) { form.reset({ feedId: feed.id, name: feed.name, url: feed.url, }); } }, [open]); const { mutateAsync: updateFeed, isPending: isUpdating } = api.feeds.update.useMutation({ onSuccess: () => { toast({ description: "Feed has been updated!", }); setOpen(false); apiUtils.feeds.list.invalidate(); }, }); const form = useForm>({ resolver: zodResolver(zUpdateFeedSchema), defaultValues: { feedId: feed.id, name: feed.name, url: feed.url, }, }); return ( Edit Feed
{ await updateFeed(value); })} > { return ( ); }} /> { return ( Name ); }} /> { return ( URL ); }} /> { await updateFeed(value); })} type="submit" className="items-center" > Save
); } export function FeedRow({ feed }: { feed: ZFeed }) { const apiUtils = api.useUtils(); const { mutate: deleteFeed, isPending: isDeleting } = api.feeds.delete.useMutation({ onSuccess: () => { toast({ description: "Feed has been deleted!", }); apiUtils.feeds.list.invalidate(); }, }); const { mutate: fetchNow, isPending: isFetching } = api.feeds.fetchNow.useMutation({ onSuccess: () => { toast({ description: "Feed fetch has been enqueued!", }); apiUtils.feeds.list.invalidate(); }, }); return ( {feed.name} {feed.url} {feed.lastFetchedAt?.toLocaleString()} {feed.lastFetchedStatus === "success" ? ( ) : feed.lastFetchedStatus === "failure" ? ( ) : ( )} fetchNow({ feedId: feed.id })} > Fetch Now ( deleteFeed({ feedId: feed.id })} className="items-center" type="button" > Delete )} > ); } export default function FeedSettings() { const { data: feeds, isLoading } = api.feeds.list.useQuery(); return ( <>
RSS Subscriptions Experimental
{isLoading && } {feeds && feeds.feeds.length == 0 && (

You don't have any RSS subscriptions yet.

)} {feeds && feeds.feeds.length > 0 && ( Name URL Last Fetch Last Status Actions {feeds.feeds.map((feed) => ( ))}
)}
); }