Skip to content

Commit

Permalink
remove static dotor while joinning the call
Browse files Browse the repository at this point in the history
  • Loading branch information
Irirwanirira committed Jul 19, 2024
1 parent 5ee5d11 commit 318a4bb
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 54 deletions.
8 changes: 6 additions & 2 deletions app/(app)/Appointments/MessagingAppointment/ChannelScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,14 @@ const ChannelScreen = () => {
const [isloading, setIsLoading] = useState(false);
const ios = Platform.OS === "ios";
const modal = useModal();
const {appointmentId} = useGlobalSearchParams();
const {id,appointmentId} = useGlobalSearchParams();
const { channel } = useAppContext();

// const deleteChannel = async () => {
// try{
// await client.deleteChannels([id], {hard_delete: true});
// }catch(error){}
// }
const endAppointment = async() => {
try {
setIsLoading(true);
Expand Down Expand Up @@ -131,7 +136,6 @@ const ChannelScreen = () => {
enforceUniqueReaction={true}
giphyEnabled={true}
>

<SafeAreaView style={{ marginBottom: ios ? 10 : 40 }}>
<StatusBar style={theme === "dark" ? "dark" : "dark"} />
</SafeAreaView>
Expand Down
88 changes: 41 additions & 47 deletions app/(app)/Appointments/MessagingAppointment/Home.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,76 +3,70 @@ import { AuthContext } from "@/ctx/AuthContext";
import { useContext, useEffect, useState } from "react";
import { StreamChat } from "stream-chat";
import { fetchPatientData } from "@/utils/LoggedInUser";
import {PatientTypes} from "@/constants/Types";
import { PatientTypes } from "@/constants/Types";
import { useAppContext } from "@/ctx/ChatContext";
import ChannelLists from "./ChannelList";
import uuid from "react-native-uuid";
import {useGlobalSearchParams } from "expo-router";
import { useGlobalSearchParams } from "expo-router";

const API_KEY = process.env.EXPO_PUBLIC_STREAM_API_KEY;
const SECRETE_KEY = process.env.EXPO_PUBLIC_STREAM_API_SECRET;

export function Home() {
const [clientIsReady, setClientIsReady] = useState<boolean>(false);
const [patientData, setPatientData] = useState<PatientTypes[] | null>(null);
const [client, setClient] = useState<StreamChat | null>(null);
const { channel, setChannel } = useAppContext();
const [clientIsReady, setClientIsReady] = useState<boolean>(false);
const [patientData, setPatientData] = useState<PatientTypes[] | null>(null);
const [client, setClient] = useState<StreamChat | null>(null);
const { channel, setChannel } = useAppContext();
const { userId } = useContext(AuthContext);
const CDNURL =
"https://vbwbfflzxuhktdvpbspd.supabase.co/storage/v1/object/public/patients/";
const { doctorId, appointmentId } = useGlobalSearchParams();
const chatRoomId = "matadores-medica" + uuid.v4();

useEffect(() => {
if (userId) {
fetchPatientData(userId, setPatientData);
}
}, [userId]);

const { userId } = useContext(AuthContext);

const {id, appointmentId} = useGlobalSearchParams()
const doctorId = id;
const chatRoomId = "matadores-medica"+uuid.v4();

useEffect(() => {
if (userId) {
fetchPatientData(userId, setPatientData);
}
}, [userId]);

const chatClient = StreamChat.getInstance(`${API_KEY}`);
const chatClient = StreamChat.getInstance(`${API_KEY}`);

useEffect(() => {
const setupClient = async () => {
try {
if (patientData && patientData[0]) {
const user = {
id: patientData[0].id,
name: `${patientData[0].first_name} ${patientData[0].last_name}`,
image: "https://i.imgur.com/fR9Jz14.png",
};
try {
if (patientData && patientData[0]) {
const user = {
id: patientData[0].id,
name: `${patientData[0].first_name} ${patientData[0].last_name}`,
image: `${CDNURL + patientData[0]?.image}`,
};

await chatClient.connectUser(
user,
chatClient.devToken(user.id));
setClientIsReady(true);
setClient(chatClient);
await chatClient.connectUser(user, chatClient.devToken(user.id));

const channel = chatClient.channel("messaging", `${chatRoomId}`, {
image: "https://vbwbfflzxuhktdvpbspd.supabase.co/storage/v1/object/public/doctors/adaptive_icon.png",
name: "Medica Chat Room",
members: [user?.id , `${doctorId}`],
});
await channel.watch();
setChannel(channel);
} else {
console.log("No patient data found");
}
} catch (error) {
console.error("An error occurred while connecting the user:", error);
setClientIsReady(true);
setClient(chatClient);
const channel = chatClient.channel("messaging", `${chatRoomId}`, {
image:
"https://vbwbfflzxuhktdvpbspd.supabase.co/storage/v1/object/public/doctors/adaptive_icon.png",
name: `${user?.name} in the chat`,
members: [user?.id, `${doctorId}`],
});
await channel.watch();
setChannel(channel);
} else {
console.log("No patient data found");
}
} catch (error) {
console.error("An error occurred while connecting the user:", error);
}
};
if (!chatClient.userID) {
setupClient();
}
// if(client){return async()=> await client.disconnectUser()}
}, [patientData]);

return (
<ChannelLists appointmentId={appointmentId}/>
)
return <ChannelLists appointmentId={appointmentId} />;
}

export default Home;

7 changes: 2 additions & 5 deletions app/(app)/Appointments/MessagingAppointment/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -157,9 +157,6 @@ try {
fetchUserProfile()
}, [loggeduser])




return (
<View
style={{
Expand Down Expand Up @@ -409,7 +406,7 @@ try {
flexDirection: "row",
gap: 10,
},
]}>{appointment.paid ? "(Paid)" : "(not paid)"}</Text>
]}>(Paid)</Text>
</View>
</View>
</View>
Expand All @@ -419,7 +416,7 @@ try {
router.push(
{
pathname: "(app)/Appointments/MessagingAppointment/Home",
params: {id: "1f4c9b93-5d95-427b-93fc-4936e4046454", appointmentId: appointment?.id}
params: {doctorId: appointment?.doctor_id, appointmentId: appointment?.id}
}
)
}
Expand Down

0 comments on commit 318a4bb

Please sign in to comment.