Updated icons, new identification
This commit is contained in:
parent
00a1bee73e
commit
7adb2dee05
34 changed files with 331 additions and 402 deletions
|
|
@ -1,102 +0,0 @@
|
|||
import { useTTP } from "@tensamin/ttp/context";
|
||||
import {
|
||||
createContext,
|
||||
useContext,
|
||||
useEffect,
|
||||
useState,
|
||||
type ReactNode,
|
||||
} from "react";
|
||||
|
||||
import { toast } from "@tensamin/shared/log";
|
||||
import type {
|
||||
Community,
|
||||
Conversation,
|
||||
} from "@tensamin/shared/features/conversation/schema";
|
||||
|
||||
interface contextValue {
|
||||
conversations: Conversation[] | null;
|
||||
communities: Community[] | null;
|
||||
}
|
||||
|
||||
const ConversationContext = createContext<contextValue | undefined>(undefined);
|
||||
|
||||
/**
|
||||
* Executes ConversationProvider.
|
||||
* @param props Parameter props.
|
||||
* @returns unknown.
|
||||
*/
|
||||
export default function ConversationProvider(props: { children: ReactNode }) {
|
||||
const [conversations, setConversations] = useState<Conversation[] | null>(
|
||||
null,
|
||||
);
|
||||
const [communities, setCommunities] = useState<Community[] | null>(null);
|
||||
|
||||
const { send } = useTTP();
|
||||
|
||||
useEffect(() => {
|
||||
let active = true;
|
||||
|
||||
send("get_conversations", {})
|
||||
.then((data) => {
|
||||
if (active) {
|
||||
setConversations(data.data.user_ids);
|
||||
}
|
||||
})
|
||||
.catch(() => {
|
||||
setConversations([
|
||||
{
|
||||
last_message_at: 0,
|
||||
user_id: 0,
|
||||
},
|
||||
]);
|
||||
toast("error", "Failed to load conversations");
|
||||
});
|
||||
|
||||
send("get_communities", {})
|
||||
.then((data) => {
|
||||
if (active) {
|
||||
setCommunities(data.data.communities);
|
||||
}
|
||||
})
|
||||
.catch(() => {
|
||||
setCommunities([
|
||||
{
|
||||
community_address: "none",
|
||||
community_title: "Failed",
|
||||
position: "",
|
||||
},
|
||||
]);
|
||||
toast("error", "Failed to load communities");
|
||||
});
|
||||
|
||||
return () => {
|
||||
active = false;
|
||||
};
|
||||
}, [send]);
|
||||
|
||||
return (
|
||||
<ConversationContext.Provider
|
||||
value={{
|
||||
conversations,
|
||||
communities,
|
||||
}}
|
||||
>
|
||||
{props.children}
|
||||
</ConversationContext.Provider>
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Executes useConversation.
|
||||
* @param none This function has no parameters.
|
||||
* @returns contextValue.
|
||||
*/
|
||||
export function useConversation(): contextValue {
|
||||
const context = useContext(ConversationContext);
|
||||
if (!context) {
|
||||
throw new Error(
|
||||
"useConversation must be used within a ConversationProvider",
|
||||
);
|
||||
}
|
||||
return context;
|
||||
}
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
import * as React from "react";
|
||||
import { useVirtualizer } from "@tanstack/react-virtual";
|
||||
import { useConversation } from "../context";
|
||||
import { useTTP } from "@tensamin/ttp/context";
|
||||
|
||||
import Switch from "./switch";
|
||||
import ConversationModal from "../modal/conversation";
|
||||
|
|
@ -17,8 +17,8 @@ export default function List() {
|
|||
"conversations" | "communities"
|
||||
>("conversations");
|
||||
|
||||
const { conversations, communities } = useConversation();
|
||||
const items = category === "conversations" ? conversations : communities;
|
||||
const { contacts, communities } = useTTP();
|
||||
const items = category === "conversations" ? contacts : communities;
|
||||
|
||||
const scrollRef = React.useRef<HTMLDivElement | null>(null);
|
||||
|
||||
|
|
@ -66,14 +66,14 @@ export default function List() {
|
|||
}}
|
||||
>
|
||||
{category === "conversations" ? (
|
||||
conversations?.[virtualItem.index] ? (
|
||||
contacts?.[virtualItem.index] ? (
|
||||
<ConversationModal
|
||||
userId={conversations[virtualItem.index].user_id}
|
||||
userId={contacts[virtualItem.index].user_id}
|
||||
/>
|
||||
) : null
|
||||
) : communities?.[virtualItem.index] ? (
|
||||
<CommunityModal
|
||||
community={communities[virtualItem.index]}
|
||||
//community={communities[virtualItem.index]}
|
||||
/>
|
||||
) : null}
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -1,10 +1,3 @@
|
|||
import type { Community } from "@tensamin/shared/features/conversation/schema";
|
||||
|
||||
/**
|
||||
* Executes CommunityModal.
|
||||
* @param props Parameter props.
|
||||
* @returns unknown.
|
||||
*/
|
||||
export default function CommunityModal(props: { community: Community }) {
|
||||
return <div>{props.community.community_title}</div>;
|
||||
export default function CommunityModal() {
|
||||
return <div>Not implemented</div>;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue