-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[frontend] Display pending status around chat (#233)
* Fixed animation when closing sub menu of context menu * Add pending status display to Ban and Add User * Button in context menu now disables after click until process completes
- Loading branch information
Showing
9 changed files
with
361 additions
and
162 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
"use client"; | ||
|
||
import { muteUser, unmuteUser } from "@/app/lib/actions"; | ||
import { | ||
ContextMenuItem, | ||
ContextMenuSub, | ||
ContextMenuSubContent, | ||
ContextMenuSubTrigger, | ||
} from "@/components/ui/context-menu"; | ||
import { useState } from "react"; | ||
|
||
type MuteState = { | ||
isMuted: boolean; | ||
isClicked: boolean; | ||
}; | ||
|
||
export default function MuteMenu({ | ||
muteState, | ||
roomId, | ||
userId, | ||
mute, | ||
}: { | ||
muteState: MuteState; | ||
roomId: number; | ||
userId: number; | ||
mute: (duration?: number) => void; | ||
}) { | ||
return ( | ||
<div> | ||
<ContextMenuSub> | ||
<ContextMenuSubTrigger>Mute</ContextMenuSubTrigger> | ||
<ContextMenuSubContent className="w-46"> | ||
<ContextMenuItem | ||
disabled={muteState.isClicked || muteState.isMuted} | ||
onSelect={() => { | ||
mute(5 * 60); | ||
}} | ||
> | ||
For 5 minutes | ||
</ContextMenuItem> | ||
<ContextMenuItem | ||
disabled={muteState.isClicked || muteState.isMuted} | ||
onSelect={() => { | ||
mute(15 * 60); | ||
}} | ||
> | ||
For 15 minutes | ||
</ContextMenuItem> | ||
<ContextMenuItem | ||
disabled={muteState.isClicked || muteState.isMuted} | ||
onSelect={() => { | ||
mute(60 * 60); | ||
}} | ||
> | ||
For 1 Hour | ||
</ContextMenuItem> | ||
<ContextMenuItem | ||
disabled={muteState.isClicked || muteState.isMuted} | ||
onSelect={() => { | ||
mute(180 * 60); | ||
}} | ||
> | ||
For 3 Hours | ||
</ContextMenuItem> | ||
<ContextMenuItem | ||
disabled={muteState.isClicked || muteState.isMuted} | ||
onSelect={() => { | ||
mute(480 * 60); | ||
}} | ||
> | ||
For 8 Hours | ||
</ContextMenuItem> | ||
<ContextMenuItem | ||
disabled={muteState.isClicked || muteState.isMuted} | ||
onSelect={() => { | ||
mute(1440 * 60); | ||
}} | ||
> | ||
For 24 Hours | ||
</ContextMenuItem> | ||
<ContextMenuItem | ||
disabled={muteState.isClicked || muteState.isMuted} | ||
onSelect={() => { | ||
mute(); | ||
}} | ||
> | ||
Indefinite | ||
</ContextMenuItem> | ||
</ContextMenuSubContent> | ||
</ContextMenuSub> | ||
</div> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
"use client"; | ||
|
||
import { banUser } from "@/app/lib/actions"; | ||
import { PublicUserEntity } from "@/app/lib/dtos"; | ||
import { Avatar } from "@/app/ui/user/avatar"; | ||
import Loader from "@/components/ui/loader"; | ||
import { Ban } from "lucide-react"; | ||
import { useRouter } from "next/navigation"; | ||
import { useState } from "react"; | ||
|
||
export default function BanItem({ | ||
roomId, | ||
user, | ||
}: { | ||
roomId: number; | ||
user: PublicUserEntity; | ||
}) { | ||
const router = useRouter(); | ||
const [isClicked, setIsClicked] = useState(false); | ||
|
||
const onBan = async (userId: number) => { | ||
setIsClicked(true); | ||
const result = await banUser(roomId, userId); | ||
if (result === "Success") { | ||
router.refresh(); | ||
} else { | ||
setIsClicked(false); | ||
} | ||
}; | ||
|
||
return ( | ||
<div key={user.id} className="flex items-center gap-x-2 mb-6"> | ||
<Avatar avatarURL={user.avatarURL} size="medium" /> | ||
<div className="flex flex-col gap-y-1"> | ||
<div className="text-xs font-semibold flex items-center gap-x-1"> | ||
{user.name} | ||
</div> | ||
</div> | ||
{isClicked && <Loader className="ml-auto" />} | ||
{!isClicked && ( | ||
<button | ||
onClick={() => onBan(user.id)} | ||
disabled={isClicked} | ||
className="text-rose-500 ml-auto" | ||
> | ||
<Ban className="h-4 w-4 ml-2" /> | ||
BAN | ||
</button> | ||
)} | ||
</div> | ||
); | ||
} |
Oops, something went wrong.