fetching convos with current state for user and combining to master convos
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
import MasterConversation from "../../../../core/models/masterConversation.model";
|
||||
import UserStatusText from "../User/userStatusText";
|
||||
export default function BasicConversationRow({
|
||||
masterConvo,
|
||||
}: {
|
||||
masterConvo: MasterConversation;
|
||||
}) {
|
||||
const isSelected = false;
|
||||
|
||||
return (
|
||||
<div
|
||||
key={masterConvo.id.toString()}
|
||||
className={`flex flex-row items-center hover:bg-zinc-600 group py-4 px-2 cursor-pointer ${
|
||||
isSelected ? "bg-zinc-600" : ""
|
||||
} rounded`}
|
||||
>
|
||||
{/* <UserAvatarWithStatus user={contactDetail.otherUser} /> */}
|
||||
|
||||
<span className="text-white font-semibold ml-2">{masterConvo.name}</span>
|
||||
<span className="text-white font-semibold ml-2">
|
||||
{masterConvo.id.toString()}
|
||||
</span>
|
||||
|
||||
{/* <span className="ml-2">
|
||||
<UserStatusText status={contactDetail.otherUser.status} />
|
||||
</span> */}
|
||||
|
||||
{/* {speakingRooms.includes(contactDetail.relationship._id.toString()) ? (
|
||||
<span className="ml-auto">speaking...</span>
|
||||
) : null} */}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -30,6 +30,12 @@ export function useUserSearch(searchQuery: string) {
|
||||
});
|
||||
}
|
||||
|
||||
export function useUserConvos() {
|
||||
// todo: merge with sockets + audio clip data + master data + convomember data
|
||||
|
||||
return useQuery("USER_CONVERSATIONS", ApiCalls.getUserConversations);
|
||||
}
|
||||
|
||||
// =========== MUTATIONS
|
||||
export function useGetDmByUserId() {
|
||||
return useMutation(ApiCalls.getDmByUserId);
|
||||
|
||||
@@ -3,6 +3,7 @@ import axios, { AxiosRequestConfig, AxiosResponse, Method } from "axios";
|
||||
import { Conversation } from "../../../core/models/conversation.model";
|
||||
import CreateConvoRequest from "../../../core/requests/createConvo.request";
|
||||
import LoginResponse from "../../../core/responses/login.response";
|
||||
import MasterConversation from "../../../core/models/masterConversation.model";
|
||||
import { User } from "@nirvana/core/models";
|
||||
import UserDetailsResponse from "../../../core/responses/userDetails.response";
|
||||
import UserSearchResponse from "../../../core/responses/userSearch.response";
|
||||
@@ -80,6 +81,10 @@ async function userSearch(searchQuery: string): Promise<UserSearchResponse> {
|
||||
);
|
||||
}
|
||||
|
||||
async function getUserConversations(): Promise<MasterConversation[]> {
|
||||
return await NirvanaApi.fetch(`/conversations`, "GET", true);
|
||||
}
|
||||
|
||||
async function getDmByUserId(otherUserId: string): Promise<Conversation> {
|
||||
return await NirvanaApi.fetch(
|
||||
`/conversations/dm/${otherUserId}`,
|
||||
@@ -102,6 +107,7 @@ export const ApiCalls = {
|
||||
authCheck,
|
||||
getUserDetails,
|
||||
userSearch,
|
||||
getUserConversations,
|
||||
getDmByUserId,
|
||||
createConversation,
|
||||
};
|
||||
|
||||
@@ -11,6 +11,7 @@ import {
|
||||
} from "../../../../../core/models/conversation.model";
|
||||
import { useRecoilState, useSetRecoilState } from "recoil";
|
||||
|
||||
import BasicConversationRow from "../../../components/conversation/basicRow";
|
||||
import { ContactDetails } from "@nirvana/core/responses/getContacts.response";
|
||||
import { FaVolumeUp } from "react-icons/fa";
|
||||
import MasterConversation from "../../../../../core/models/masterConversation.model";
|
||||
@@ -19,6 +20,7 @@ import UserAvatarWithStatus from "../../../components/User/userAvatarWithStatus"
|
||||
import UserStatusText from "../../../components/User/userStatusText";
|
||||
import useSocketData from "../../../controller/sockets";
|
||||
import { useState } from "react";
|
||||
import { useUserConvos } from "../../../controller/index";
|
||||
|
||||
enum ConvoTab {
|
||||
LIVE = "LIVE",
|
||||
@@ -57,22 +59,21 @@ export default function Conversations() {
|
||||
setSelectedConvo(googleUserId);
|
||||
};
|
||||
|
||||
// fake data of conversations
|
||||
const allMasterConvos = [] as MasterConversation[];
|
||||
const { data: userConverstionsData } = useUserConvos();
|
||||
|
||||
// render right content based on selected tab
|
||||
const renderConversationContent = () => {
|
||||
// if no content for a tab, then show stale text
|
||||
|
||||
const invitedConvos = allMasterConvos.filter(
|
||||
const invitedConvos = userConverstionsData?.filter(
|
||||
(masterConvo) =>
|
||||
masterConvo.currentUserMember.state === ConversationMemberState.INVITED
|
||||
);
|
||||
const inboxConvos = allMasterConvos.filter(
|
||||
const inboxConvos = userConverstionsData?.filter(
|
||||
(masterConvo) =>
|
||||
masterConvo.currentUserMember.state === ConversationMemberState.INBOX
|
||||
);
|
||||
const tunedConvos = allMasterConvos.filter(
|
||||
const tunedConvos = userConverstionsData?.filter(
|
||||
(masterConvo) =>
|
||||
masterConvo.currentUserMember.state === ConversationMemberState.TUNED
|
||||
);
|
||||
@@ -94,7 +95,13 @@ export default function Conversations() {
|
||||
return <span>Pin a channel to turn it into a walkie talkie.</span>;
|
||||
case ConvoTab.INBOX:
|
||||
if (inboxConvos?.length) {
|
||||
return <span>displaying all inbox convos</span>;
|
||||
return (
|
||||
<>
|
||||
{inboxConvos.map((convo) => (
|
||||
<BasicConversationRow masterConvo={convo} />
|
||||
))}
|
||||
</>
|
||||
);
|
||||
}
|
||||
return <span>Connect with someone and start talking!</span>;
|
||||
case ConvoTab.REQUESTS:
|
||||
|
||||
Reference in New Issue
Block a user