import { ArrowLeftIcon, EditInterestIcon, LoaderIcon } from "@lume/icons"; import { useStorage } from "@lume/storage"; import { TOPICS, cn } from "@lume/utils"; import * as Dialog from "@radix-ui/react-dialog"; import { useQueryClient } from "@tanstack/react-query"; import { ReactNode, useState } from "react"; import { useTranslation } from "react-i18next"; import { toast } from "sonner"; export function InterestModal({ queryKey, className, children, }: { queryKey: string[]; className?: string; children?: ReactNode }) { const storage = useStorage(); const queryClient = useQueryClient(); const [t] = useTranslation(); const [open, setOpen] = useState(false); const [loading, setLoading] = useState(false); const [hashtags, setHashtags] = useState(storage.interests?.hashtags || []); const toggleHashtag = (item: string) => { const arr = hashtags.includes(item) ? hashtags.filter((i) => i !== item) : [...hashtags, item]; setHashtags(arr); }; const toggleAll = (item: string[]) => { const sets = new Set([...hashtags, ...item]); setHashtags([...sets]); }; const submit = async () => { try { setLoading(true); const save = await storage.createSetting( "interests", JSON.stringify({ hashtags }), ); if (save) { storage.interests = { hashtags, users: [], words: [] }; await queryClient.refetchQueries({ queryKey }); } setLoading(false); setOpen(false); } catch (e) { setLoading(false); toast.error(String(e)); } }; return ( {children ? ( children ) : ( <> {t("interests.edit")} )}

{t("interests.edit")}

{TOPICS.map((topic) => (
{topic.title}

{topic.title}

{topic.content.map((hashtag) => ( ))}
))}
{t("global.cancel")}
); }