migrated channel messages to jotai state (same as chat)

This commit is contained in:
Ren Amamiya
2023-04-16 17:31:31 +07:00
parent 00e28529dd
commit a573f9e4eb
3 changed files with 33 additions and 8 deletions

View File

@@ -1,4 +1,11 @@
import { atom } from 'jotai';
import { atomWithReset } from 'jotai/utils';
// channel reply id
export const channelReplyAtom = atomWithReset({ id: null, pubkey: null, content: null });
// channel messages
export const channelMessagesAtom = atomWithReset([]);
export const sortedChannelMessagesAtom = atom((get) => {
const messages = get(channelMessagesAtom);
return messages.sort((x: { created_at: number }, y: { created_at: number }) => x.created_at - y.created_at);
});