Skip to content

Commit

Permalink
finish room Settings
Browse files Browse the repository at this point in the history
  • Loading branch information
Ouadia Essendoubi committed Oct 29, 2023
1 parent 07557b0 commit add052e
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 43 deletions.
14 changes: 1 addition & 13 deletions frontend/code/src/Components/Chat/Components/Conversation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ import {
getRoomMessagesCall,
sendMessageCall,
} from "../Services/MessagesServices";
import { Message as UserMessage } from "../../Layout/Assets/Message";
import { useStore } from "zustand";

import { useUserStore } from "../../../Stores/stores";

export interface ChatPaceHolderProps {
Expand Down Expand Up @@ -277,21 +276,12 @@ export const Conversation: React.FC<ConversationProps> = ({
}) => {
const chatState = useChatStore((state) => state);
const messageContainerRef = useRef<HTMLDivElement>(null);
const selectedChatType = useChatStore((state) => state.selectedChatType);
const currentChatMessages = useChatStore((state) => state.currentMessages);
const currentRoomMessages = useChatStore(
(state) => state.currentRoomMessages
);

const pushMessage = useChatStore((state) => state.addNewMessage);
const [CurrentsMessages, setMessages] = useState<Message[]>([]);
const [inputValue, setInputValue] = useState("");
const [FailToSendMessage, setFail] = useState(false);

const selectedMessages =
selectedChatType === ChatType.Chat
? currentChatMessages
: currentRoomMessages;
// Function to handle input changes
const handleInputChange = (e: {
target: { value: React.SetStateAction<string> };
Expand Down Expand Up @@ -323,8 +313,6 @@ export const Conversation: React.FC<ConversationProps> = ({
);
setMessages(messages);
}

const response = res?.data;
});

fetch();
Expand Down
64 changes: 37 additions & 27 deletions frontend/code/src/Components/Chat/Components/RoomChatHelpers.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { SetStateAction, useEffect, useState } from "react";
import { useChatStore } from "../Controllers/RoomChatControllers";
import users, {
import {
ChatGif,
ChatRoom,
GroupChat,
Expand All @@ -15,7 +15,7 @@ import users, {
check,
groupIcon,
} from "./tools/Assets";
import { SelectedUserTile } from "..";


import {
DeleteRoomCall,
Expand Down Expand Up @@ -410,6 +410,7 @@ export const AddUsersModal = () => {

fetchData();
}
// eslint-disable-next-line
}, [LayoutState.showAddUsersModal]);
return (
<div className="modal w-screen " id="my_modal_6">
Expand Down Expand Up @@ -476,7 +477,6 @@ export const RoomSettingsModal = () => {
const [RoomPassword, setPassword] = useState("");
const [LoadingUsers, setLOading] = useState(false);


const handlePasswordChange = (event: {
target: { value: SetStateAction<string> };
}) => {
Expand Down Expand Up @@ -647,43 +647,53 @@ export const RoomSettingsModal = () => {
<li
onClick={async () => {
setTakeAction(true);
LayoutState.setShowSettingsModal(
!LayoutState.showSettingsModal
);
await takeActionCall(
selectedChatID as string,
user.id,
"ban"
user.isBaned ? "unban" : "ban"
).then((res) => {
setTakeAction(false);
if (res?.status === 200 || res?.status === 201) {
toast.success("User baned Successfully");
toast.success(res.data.message);
}
LayoutState.setShowSettingsModal(
!LayoutState.showSettingsModal
);
});
}}
>
<span className="hover:bg-[#7940CF]">Ban</span>
<span className="hover:bg-[#7940CF]">
{user.isBaned ? "UnBan" : "Ban"}
</span>
</li>

<li
onClick={async () => {
setTakeAction(true);
await takeActionCall(
selectedChatID as string,
user.id,
"mute"
).then((res) => {
setTakeAction(false);
if (res?.status === 200 || res?.status === 201) {
toast.success(
"User Muted For a 5 minutes Successfully"
{user.isMuted === false && (
<li
onClick={async () => {
setTakeAction(true);
await takeActionCall(
selectedChatID as string,
user.id,
"mute"
).then((res) => {
setTakeAction(false);
if (
res?.status === 200 ||
res?.status === 201
) {
toast.success(
"User Muted For a 5 minutes Successfully"
);
}
LayoutState.setShowSettingsModal(
!LayoutState.showSettingsModal
);
}
});
}}
>
<span className="hover:bg-[#7940CF]">mute</span>
</li>
});
}}
>
<span className="hover:bg-[#7940CF]">mute</span>
</li>
)}

<li
onClick={async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,13 @@ export interface RoomMember {
id: string;
firstname: string;
lastname: string;

avatar: {
thumbnail: string;
medium: string;
large: string;
};
isBaned?: boolean;
isMuted?: boolean;
}

export interface ChatRoom {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import toast from "react-hot-toast";

import api from "../../../Api/base";


Expand Down
2 changes: 2 additions & 0 deletions frontend/code/src/Components/Chat/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,8 @@ export const UserPreviewCard: React.FC<ConversationProps> = ({
};

fetchData();

//eslint-disable-next-line
}, [SelectedChat]);
return (
<div className="flex flex-col p-4 ">
Expand Down
2 changes: 1 addition & 1 deletion frontend/code/src/Components/Layout/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { matchRoutes, useLocation } from "react-router-dom";
import { useUserStore } from "../../Stores/stores";
import { useNavigate } from "react-router-dom";
import { FirstLogin } from "../FirstLogin";
import { AxiosError, type AxiosResponse } from "axios";


const routes = [
{ path: "Profile/:id" },
Expand Down

0 comments on commit add052e

Please sign in to comment.