This commit is contained in:
Ren Amamiya
2023-03-25 17:21:41 +07:00
parent f1647fd857
commit 17bcaa1a48
9 changed files with 163 additions and 143 deletions

View File

@@ -1,9 +1,9 @@
import { isSSR } from '@utils/ssr';
import { getActiveAccount } from '@utils/storage';
import { atom } from 'jotai';
import { atomWithCache } from 'jotai-cache';
export const activeAccountAtom = atom(async () => {
export const activeAccountAtom = atomWithCache(async () => {
const response = isSSR ? {} : await getActiveAccount();
return response;
});

View File

@@ -4,13 +4,18 @@ import { getAllNotes } from '@utils/storage';
import { atom } from 'jotai';
import { atomsWithQuery } from 'jotai-tanstack-query';
// usecase: notify user that connector has receive newer note
// notify user that connector has receive newer note
export const hasNewerNoteAtom = atom(false);
// usecase: query notes from database
// query notes from database
export const [notesAtom] = atomsWithQuery(() => ({
queryKey: ['notes'],
queryFn: async ({ queryKey: [] }) => {
const res = isSSR ? [] : await getAllNotes();
return res;
},
refetchInterval: 1000000,
refetchOnReconnect: true,
refetchOnWindowFocus: true,
refetchOnMount: true,
keepPreviousData: false,
}));

View File

@@ -1,9 +1,9 @@
import { isSSR } from '@utils/ssr';
import { getAllRelays } from '@utils/storage';
import { atom } from 'jotai';
import { atomWithCache } from 'jotai-cache';
export const relaysAtom = atom(async () => {
export const relaysAtom = atomWithCache(async () => {
const response = isSSR ? [] : await getAllRelays();
return response;
});