diff --git a/src/app/auth/onboarding/hashtag.tsx b/src/app/auth/onboarding/hashtag.tsx index 5a4b8de3..8965c983 100644 --- a/src/app/auth/onboarding/hashtag.tsx +++ b/src/app/auth/onboarding/hashtag.tsx @@ -6,37 +6,9 @@ import { useStorage } from '@libs/storage/provider'; import { ArrowLeftIcon, CheckCircleIcon, LoaderIcon } from '@shared/icons'; -import { WidgetKinds } from '@stores/constants'; +import { HASHTAGS, WidgetKinds } from '@stores/constants'; import { useOnboarding } from '@stores/onboarding'; -const data = [ - { hashtag: '#bitcoin' }, - { hashtag: '#nostr' }, - { hashtag: '#nostrdesign' }, - { hashtag: '#security' }, - { hashtag: '#zap' }, - { hashtag: '#LFG' }, - { hashtag: '#zapchain' }, - { hashtag: '#shitcoin' }, - { hashtag: '#plebchain' }, - { hashtag: '#nodes' }, - { hashtag: '#hodl' }, - { hashtag: '#stacksats' }, - { hashtag: '#nokyc' }, - { hashtag: '#meme' }, - { hashtag: '#memes' }, - { hashtag: '#memestr' }, - { hashtag: '#nostriches' }, - { hashtag: '#dev' }, - { hashtag: '#anime' }, - { hashtag: '#waifu' }, - { hashtag: '#manga' }, - { hashtag: '#lume' }, - { hashtag: '#snort' }, - { hashtag: '#damus' }, - { hashtag: '#primal' }, -]; - export function OnboardHashtagScreen() { const { db } = useStorage(); @@ -93,7 +65,7 @@ export function OnboardHashtagScreen() {
- {data.map((item: { hashtag: string }) => ( + {HASHTAGS.map((item: { hashtag: string }) => ( +
+
+
+ setTitle(e.target.value)} + placeholder="Group name" + className="relative h-11 w-full rounded-lg bg-neutral-100 px-3 py-1 text-neutral-900 !outline-none placeholder:text-neutral-500 dark:bg-neutral-900 dark:text-neutral-100 dark:placeholder:text-neutral-300" + /> +
+
+ Add users {title ? 'to ' + title : ''} +
{db.account.circles.map((item: string) => ( ))}
-
- - -
+
+
+
-
+ ); } diff --git a/src/shared/widgets/tmp/hashtag.tsx b/src/shared/widgets/tmp/hashtag.tsx index 278abd4a..93ad5082 100644 --- a/src/shared/widgets/tmp/hashtag.tsx +++ b/src/shared/widgets/tmp/hashtag.tsx @@ -1,8 +1,9 @@ import { Resolver, useForm } from 'react-hook-form'; -import { ArrowRightCircleIcon } from '@shared/icons'; +import { ArrowRightCircleIcon, CancelIcon } from '@shared/icons'; +import { WidgetWrapper } from '@shared/widgets'; -import { WidgetKinds } from '@stores/constants'; +import { HASHTAGS, WidgetKinds } from '@stores/constants'; import { useWidget } from '@utils/hooks/useWidget'; import { Widget } from '@utils/types'; @@ -29,15 +30,12 @@ export function XhashtagWidget({ params }: { params: Widget }) { const { addWidget, removeWidget } = useWidget(); const { register, + setValue, setError, handleSubmit, formState: { errors, isDirty, isValid }, } = useForm({ resolver }); - const cancel = () => { - removeWidget.mutate(params.id); - }; - const onSubmit = async (data: FormValues) => { try { addWidget.mutate({ @@ -56,42 +54,57 @@ export function XhashtagWidget({ params }: { params: Widget }) { }; return ( -
-
-

- Enter hashtag you want to follow + +
+
+

+ Adding hashtag feeds

+ +
+
{errors.hashtag &&

{errors.hashtag.message}

}
-
+
+ {HASHTAGS.map((item) => ( + + ))} +
+
-
-
+ ); } diff --git a/src/stores/constants.ts b/src/stores/constants.ts index 34412fc0..8b844365 100644 --- a/src/stores/constants.ts +++ b/src/stores/constants.ts @@ -10,6 +10,37 @@ export const FULL_RELAYS = [ export const FETCH_LIMIT = 20; +export const HASHTAGS = [ + { hashtag: '#food' }, + { hashtag: '#gaming' }, + { hashtag: '#nsfw' }, + { hashtag: '#bitcoin' }, + { hashtag: '#nostr' }, + { hashtag: '#nostrdesign' }, + { hashtag: '#security' }, + { hashtag: '#zap' }, + { hashtag: '#LFG' }, + { hashtag: '#zapchain' }, + { hashtag: '#shitcoin' }, + { hashtag: '#plebchain' }, + { hashtag: '#nodes' }, + { hashtag: '#hodl' }, + { hashtag: '#stacksats' }, + { hashtag: '#nokyc' }, + { hashtag: '#meme' }, + { hashtag: '#memes' }, + { hashtag: '#memestr' }, + { hashtag: '#nostriches' }, + { hashtag: '#dev' }, + { hashtag: '#anime' }, + { hashtag: '#waifu' }, + { hashtag: '#manga' }, + { hashtag: '#lume' }, + { hashtag: '#snort' }, + { hashtag: '#damus' }, + { hashtag: '#primal' }, +]; + export const WidgetKinds = { local: { network: 100, diff --git a/src/utils/hooks/useWidget.ts b/src/utils/hooks/useWidget.ts index b2203162..7cf6017c 100644 --- a/src/utils/hooks/useWidget.ts +++ b/src/utils/hooks/useWidget.ts @@ -19,9 +19,24 @@ export function useWidget() { const removeWidget = useMutation({ mutationFn: async (id: string) => { - return await db.removeWidget(id); + // Cancel any outgoing refetches + await queryClient.cancelQueries({ queryKey: ['widgets'] }); + + // Snapshot the previous value + const prevWidgets = queryClient.getQueryData(['widgets']); + + // Optimistically update to the new value + queryClient.setQueryData(['widgets'], (prev: Widget[]) => + prev.filter((t) => t.id !== id) + ); + + // Update in database + await db.removeWidget(id); + + // Return a context object with the snapshotted value + return { prevWidgets }; }, - onSuccess: () => { + onSettled: () => { queryClient.invalidateQueries({ queryKey: ['widgets'] }); }, });