bunch of data updates and now getting hang of recoil but not a pro so keep working at it and start displaying stuff in different places
This commit is contained in:
@@ -6,7 +6,7 @@ import Conversation, {
|
||||
} from "@nirvana/common/models/conversation";
|
||||
import { User as NirvanaUser } from "@nirvana/common/models/user";
|
||||
|
||||
import { atom, selector } from "recoil";
|
||||
import { atom, selector, selectorFamily } from "recoil";
|
||||
|
||||
export enum RecoilActions {
|
||||
TEST = "TEST",
|
||||
@@ -20,6 +20,9 @@ export enum RecoilActions {
|
||||
SORTED_CONVERSATIONS = "SORTED_CONVERSATIONS",
|
||||
LIVE_ROOMS = "LIVE_ROOMS",
|
||||
|
||||
ALL_RELEVANT_CONTACTS = "ALL_RELEVANT_CONTACTS",
|
||||
RELEVANT_CONTACTS_SELECTOR_CACHE = "RELEVANT_CONTACTS_SELECTOR_CACHE",
|
||||
|
||||
USER_DATA = "USER_DATA",
|
||||
}
|
||||
|
||||
@@ -38,60 +41,30 @@ export const nirvanaUserDataAtom = atom<NirvanaUser | null>({
|
||||
// default: getTest, // default value (aka initial value)
|
||||
// });
|
||||
|
||||
export class CompleteConversation {
|
||||
id: string; // conversation id
|
||||
|
||||
get isLive(): boolean {
|
||||
return this.members?.length > 0;
|
||||
}
|
||||
|
||||
// method/property for knowing if this there is a new activity for me in this conversation
|
||||
|
||||
// method/property for getting the latest link if valid
|
||||
|
||||
// method/property to get the latest convo chunk/last person talking
|
||||
|
||||
conversation: Conversation;
|
||||
|
||||
constructor(convo: Conversation) {
|
||||
this.conversation = convo;
|
||||
this.id = this.conversation.id;
|
||||
}
|
||||
|
||||
userMember?: ConversationMember;
|
||||
|
||||
members: ConversationMember[] = [] as ConversationMember[];
|
||||
audioClips: AudioClip[] = [] as AudioClip[];
|
||||
links: Link[] = [] as Link[];
|
||||
}
|
||||
|
||||
// map cache of all complete conversation objects
|
||||
export const allCompleteConversations = atom({
|
||||
key: RecoilActions.ALL_COMPLETE_CONVERSATIONS,
|
||||
default: new Map<string, CompleteConversation>(),
|
||||
});
|
||||
|
||||
// map cache of all relevant users
|
||||
|
||||
// selector for the convos that have members in the live room
|
||||
|
||||
// selectors for convos: inbox/default, live, later, done, priority
|
||||
|
||||
// approach: fill in all "bottom" level atoms, and then build the tree later with selectors
|
||||
export const allUsersConversations = atom({
|
||||
// convo id -> userMember object
|
||||
export const allUsersConversationsAtom = atom({
|
||||
key: RecoilActions.ALL_USERS_CONVERSATION_RELATIONSHIPS,
|
||||
default: new Map<string, ConversationMember>(),
|
||||
});
|
||||
|
||||
export const allRelevantConversations = atom({
|
||||
export const allRelevantConversationsAtom = atom({
|
||||
key: RecoilActions.ALL_RELEVANT_CONVERSATIONS,
|
||||
default: new Map<string, Conversation>(),
|
||||
effects: [
|
||||
({ onSet }) => {
|
||||
onSet((newMap) => {
|
||||
//go through and make sure that our relevant user's cache is up to date
|
||||
// const allUsersInConvos = newMap.values()
|
||||
});
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
export const sortedRoomSelector = selector<Conversation[]>({
|
||||
key: RecoilActions.SORTED_CONVERSATIONS,
|
||||
get: ({ get }) => {
|
||||
const relConvos = get(allRelevantConversations);
|
||||
const relConvos = get(allRelevantConversationsAtom);
|
||||
const convosArr: Conversation[] = Array.from(relConvos.values());
|
||||
|
||||
convosArr.sort((a, b) => {
|
||||
@@ -113,7 +86,9 @@ export const sortedRoomSelector = selector<Conversation[]>({
|
||||
},
|
||||
});
|
||||
|
||||
// get all rooms with active members in the room, and
|
||||
// selectors for convos: inbox/default, live, later, done, priority
|
||||
|
||||
// get all rooms with active members in the room
|
||||
export const liveRoomsSelector = selector<Conversation[]>({
|
||||
key: RecoilActions.LIVE_ROOMS,
|
||||
get: ({ get }) => {
|
||||
@@ -125,3 +100,21 @@ export const liveRoomsSelector = selector<Conversation[]>({
|
||||
return liveRooms;
|
||||
},
|
||||
});
|
||||
|
||||
// map cache of all relevant users
|
||||
// get all of the users in all of the conversations, once through a simple service call
|
||||
export const allRelevantContactsAtom = atom<Map<string, NirvanaUser>>({
|
||||
key: RecoilActions.ALL_RELEVANT_CONTACTS,
|
||||
default: new Map<string, NirvanaUser>(),
|
||||
});
|
||||
|
||||
// todo: useful selector where a component can pass in a list of users
|
||||
// and return their full information
|
||||
export const cachedRelevantContactsSelector = selector<NirvanaUser[]>({
|
||||
key: RecoilActions.RELEVANT_CONTACTS_SELECTOR_CACHE,
|
||||
get: async ({ get }) => {
|
||||
const currContacts: Map<string, NirvanaUser> = get(allRelevantContactsAtom);
|
||||
return [];
|
||||
},
|
||||
// selector set (pass in a user and build cache if somethings not in the cache already)
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user