move channel list logic to atom

This commit is contained in:
Ren Amamiya
2023-04-23 15:52:19 +07:00
parent 340e453b3e
commit df65790dd3
6 changed files with 39 additions and 17 deletions

View File

@@ -1,8 +1,19 @@
import { DEFAULT_CHANNELS } from '@stores/constants';
import { atom } from 'jotai';
import { atomWithReset } from 'jotai/utils';
// channel list
export const defaultChannelsAtom = atom(DEFAULT_CHANNELS);
export const channelsAtom = atom(async (get) => {
const { getChannels } = await import('@utils/storage');
const result: any = await getChannels(100, 0);
return get(defaultChannelsAtom).concat(result);
});
// channel reply id
export const channelReplyAtom = atomWithReset({ id: null, pubkey: null, content: null });
// channel messages
export const channelMessagesAtom = atomWithReset([]);
export const sortedChannelMessagesAtom = atom((get) => {