diff --git a/src/app/auth/finish.tsx b/src/app/auth/finish.tsx index 741df4d0..dc4faa38 100644 --- a/src/app/auth/finish.tsx +++ b/src/app/auth/finish.tsx @@ -1,6 +1,81 @@ -import { Link } from 'react-router-dom'; +import { NDKKind } from '@nostr-dev-kit/ndk'; +import { useQueryClient } from '@tanstack/react-query'; +import { useState } from 'react'; +import { Link, useNavigate } from 'react-router-dom'; + +import { useArk } from '@libs/ark'; + +import { LoaderIcon } from '@shared/icons'; + +import { FETCH_LIMIT } from '@utils/constants'; export function FinishScreen() { + const { ark } = useArk(); + const [loading, setLoading] = useState(false); + + const queryClient = useQueryClient(); + const navigate = useNavigate(); + + const prefetch = async () => { + if (!ark.account.contacts.length) return navigate('/'); + + try { + setLoading(true); + + // prefetch newsfeed + await queryClient.prefetchInfiniteQuery({ + queryKey: ['newsfeed'], + initialPageParam: 0, + queryFn: async ({ + signal, + pageParam, + }: { + signal: AbortSignal; + pageParam: number; + }) => { + return await ark.getInfiniteEvents({ + filter: { + kinds: [NDKKind.Text, NDKKind.Repost], + authors: !ark.account.contacts.length + ? [ark.account.pubkey] + : ark.account.contacts, + }, + limit: FETCH_LIMIT, + pageParam, + signal, + }); + }, + }); + + // prefetch notification + await queryClient.prefetchInfiniteQuery({ + queryKey: ['notification'], + initialPageParam: 0, + queryFn: async ({ + signal, + pageParam, + }: { + signal: AbortSignal; + pageParam: number; + }) => { + return await ark.getInfiniteEvents({ + filter: { + kinds: [NDKKind.Text, NDKKind.Repost, NDKKind.Reaction, NDKKind.Zap], + '#p': [ark.account.pubkey], + }, + limit: FETCH_LIMIT, + pageParam, + signal, + }); + }, + }); + + navigate('/'); + } catch (e) { + console.error(e); + } + }; + return (
@@ -17,12 +92,13 @@ export function FinishScreen() { > Start tutorial - - Skip - + {loading ? : 'Skip'} +

You need to restart app to make changes in previous step take effect or you can continue with Lume default settings diff --git a/src/app/auth/tutorials/finish.tsx b/src/app/auth/tutorials/finish.tsx index 8b064f8a..bf969f10 100644 --- a/src/app/auth/tutorials/finish.tsx +++ b/src/app/auth/tutorials/finish.tsx @@ -1,6 +1,81 @@ -import { Link } from 'react-router-dom'; +import { NDKKind } from '@nostr-dev-kit/ndk'; +import { useQueryClient } from '@tanstack/react-query'; +import { useState } from 'react'; +import { Link, useNavigate } from 'react-router-dom'; + +import { useArk } from '@libs/ark'; + +import { LoaderIcon } from '@shared/icons'; + +import { FETCH_LIMIT } from '@utils/constants'; export function TutorialFinishScreen() { + const { ark } = useArk(); + const [loading, setLoading] = useState(false); + + const queryClient = useQueryClient(); + const navigate = useNavigate(); + + const prefetch = async () => { + if (!ark.account.contacts.length) return navigate('/'); + + try { + setLoading(true); + + // prefetch newsfeed + await queryClient.prefetchInfiniteQuery({ + queryKey: ['newsfeed'], + initialPageParam: 0, + queryFn: async ({ + signal, + pageParam, + }: { + signal: AbortSignal; + pageParam: number; + }) => { + return await ark.getInfiniteEvents({ + filter: { + kinds: [NDKKind.Text, NDKKind.Repost], + authors: !ark.account.contacts.length + ? [ark.account.pubkey] + : ark.account.contacts, + }, + limit: FETCH_LIMIT, + pageParam, + signal, + }); + }, + }); + + // prefetch notification + await queryClient.prefetchInfiniteQuery({ + queryKey: ['notification'], + initialPageParam: 0, + queryFn: async ({ + signal, + pageParam, + }: { + signal: AbortSignal; + pageParam: number; + }) => { + return await ark.getInfiniteEvents({ + filter: { + kinds: [NDKKind.Text, NDKKind.Repost, NDKKind.Reaction, NDKKind.Zap], + '#p': [ark.account.pubkey], + }, + limit: FETCH_LIMIT, + pageParam, + signal, + }); + }, + }); + + navigate('/'); + } catch (e) { + console.error(e); + } + }; + return (

@@ -11,12 +86,17 @@ export function TutorialFinishScreen() {
- - Start using - + {loading ? ( + + ) : ( + 'Start using Lume' + )} + user.pubkey ); - this.account.contacts = contacts; + if (pubkey === this.account.pubkey) this.account.contacts = contacts; return contacts; } catch (e) { console.error(e); diff --git a/src/libs/ark/provider.tsx b/src/libs/ark/provider.tsx index 4e3ecc4a..8e3798cd 100644 --- a/src/libs/ark/provider.tsx +++ b/src/libs/ark/provider.tsx @@ -1,3 +1,5 @@ +import { NDKKind } from '@nostr-dev-kit/ndk'; +import { useQueryClient } from '@tanstack/react-query'; import { ask } from '@tauri-apps/plugin-dialog'; import { platform } from '@tauri-apps/plugin-os'; import { relaunch } from '@tauri-apps/plugin-process'; @@ -10,7 +12,7 @@ import { Ark } from '@libs/ark'; import { LoaderIcon } from '@shared/icons'; -import { QUOTES } from '@utils/constants'; +import { FETCH_LIMIT, QUOTES } from '@utils/constants'; interface ArkContext { ark: Ark; @@ -24,6 +26,8 @@ const ArkProvider = ({ children }: PropsWithChildren) => { const [ark, setArk] = useState(undefined); const [isNewVersion, setIsNewVersion] = useState(false); + const queryClient = useQueryClient(); + async function initArk() { try { const sqlite = await Database.load('sqlite:lume_v2.db'); @@ -61,6 +65,56 @@ const ArkProvider = ({ children }: PropsWithChildren) => { } } + if (_ark.account) { + // prefetch newsfeed + await queryClient.prefetchInfiniteQuery({ + queryKey: ['newsfeed'], + initialPageParam: 0, + queryFn: async ({ + signal, + pageParam, + }: { + signal: AbortSignal; + pageParam: number; + }) => { + return await ark.getInfiniteEvents({ + filter: { + kinds: [NDKKind.Text, NDKKind.Repost], + authors: !ark.account.contacts.length + ? [ark.account.pubkey] + : ark.account.contacts, + }, + limit: FETCH_LIMIT, + pageParam, + signal, + }); + }, + }); + + // prefetch notification + await queryClient.prefetchInfiniteQuery({ + queryKey: ['notification'], + initialPageParam: 0, + queryFn: async ({ + signal, + pageParam, + }: { + signal: AbortSignal; + pageParam: number; + }) => { + return await ark.getInfiniteEvents({ + filter: { + kinds: [NDKKind.Text, NDKKind.Repost, NDKKind.Reaction, NDKKind.Zap], + '#p': [ark.account.pubkey], + }, + limit: FETCH_LIMIT, + pageParam, + signal, + }); + }, + }); + } + setArk(_ark); } catch (e) { console.error(e); diff --git a/src/utils/hooks/useRichContent.tsx b/src/utils/hooks/useRichContent.tsx index f407aae6..cb392e73 100644 --- a/src/utils/hooks/useRichContent.tsx +++ b/src/utils/hooks/useRichContent.tsx @@ -23,9 +23,19 @@ const NOSTR_MENTIONS = [ 'npub1', 'nprofile1', 'naddr1', + 'Nostr:npub1', + 'Nostr:nprofile1', + 'Nostr:naddre1', ]; -const NOSTR_EVENTS = ['nostr:note1', 'note1', 'nostr:nevent1', 'nevent1']; +const NOSTR_EVENTS = [ + 'nostr:note1', + 'note1', + 'nostr:nevent1', + 'nevent1', + 'Nostr:note1', + 'Nostr:nevent1', +]; // const BITCOINS = ['lnbc', 'bc1p', 'bc1q'];