-
Notifications
You must be signed in to change notification settings - Fork 0
Dannguyen/same room dialog #587
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
8868677
797047b
092c2bd
8589981
be4e724
d258aeb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| import { Button } from "@cb/lib/components/ui/button"; | ||
| import { DialogClose } from "@cb/lib/components/ui/dialog"; | ||
| import { cn } from "@cb/utils/cn"; | ||
| import { DialogOverlay } from "@radix-ui/react-dialog"; | ||
| import { RoomDialog, baseButtonClassName } from "./RoomDialog"; | ||
|
|
||
| interface AlreadyInRoomDialogProps { | ||
| open: boolean; | ||
| onOpenChange: (open: boolean) => void; | ||
| onConfirm: (event: React.MouseEvent<HTMLButtonElement>) => void; | ||
| onCancel: (event: React.MouseEvent<HTMLButtonElement>) => void; | ||
| } | ||
|
|
||
| export const AlreadyInRoomDialog = ({ | ||
| open, | ||
| onOpenChange, | ||
| onConfirm, | ||
| onCancel, | ||
| }: AlreadyInRoomDialogProps) => { | ||
| return ( | ||
| <RoomDialog | ||
| dialog={{ props: { open, onOpenChange } }} | ||
| title={{ node: "This account is already in the room" }} | ||
| content={{ | ||
| props: { | ||
| className: | ||
| "w-[400px] gap-y-4 rounded-xl bg-white p-6 text-lg text-[#1E1E1E] dark:bg-[#262626] shadow-lg dark:text-[#FFFFFF]", | ||
| onClick: (e) => e.stopPropagation(), | ||
| }, | ||
| }} | ||
| overlay={ | ||
| <DialogOverlay className="fixed inset-0 z-[9999] dark:bg-black/30 bg-white/30 backdrop-blur-sm" /> | ||
| } | ||
| > | ||
| <div className="flex w-full items-center justify-end gap-2"> | ||
| <DialogClose asChild> | ||
| <Button | ||
| className={cn(baseButtonClassName, "flex-1")} | ||
| onClick={onCancel} | ||
| > | ||
| Cancel | ||
| </Button> | ||
| </DialogClose> | ||
| <Button | ||
| className={cn(baseButtonClassName, "flex-1 bg-orange-500")} | ||
| onClick={onConfirm} | ||
| > | ||
| Join anyway | ||
| </Button> | ||
| </div> | ||
| </RoomDialog> | ||
| ); | ||
| }; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,7 +11,7 @@ const Header = ({ className, ...props }: HeaderProps) => { | |
| <ThemeAwaredLogo /> | ||
| </div> | ||
| <h2 className="font-medium"> | ||
| Code<span className="text-codebuddy-pink">Buddy</span> | ||
| Code<span className="text-codebuddy-pink">Buddy2</span> | ||
|
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. note to revert |
||
| </h2> | ||
| </div> | ||
| ); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -110,6 +110,7 @@ interface RoomAction { | |
| selectSidebarTab: (identifier: SidebarTabIdentifier) => void; | ||
| closeSidebarTab: () => void; | ||
| getVariables: (url: string) => Question["variables"] | undefined; | ||
| checkAlreadyInRoom: (id: Id) => Promise<boolean>; | ||
| }; | ||
| peers: { | ||
| update: (id: Id, peer: Partial<UpdatePeerArgs>) => Promise<void>; | ||
|
|
@@ -411,6 +412,26 @@ const createRoomStore = (background: BackgroundProxy, appStore: AppStore) => { | |
| }); | ||
| } | ||
| }, | ||
| checkAlreadyInRoom: async (id: string) => { | ||
|
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. RoomController already does a fetch https://github.com/nickbar01234/codebuddy/blob/main/extension/src/services/controllers/RoomController.ts#L284-L305. Probably can just extend from it? |
||
| try { | ||
| const username = appStore | ||
| .getState() | ||
| .actions.getAuthUser().username; | ||
| const room = await db.room.get(id); | ||
|
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You mentioned dialog never popped up. Did you print username / room object here? |
||
| if (room && Object.keys(room.users).includes(username)) { | ||
| console.log(`User ${username} is already in room ${id}`); | ||
| set((state) => { | ||
| state.status = RoomStatus.IN_ROOM; | ||
|
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we want to set state here? |
||
| }); | ||
|
|
||
| return true; | ||
| } | ||
| return false; | ||
| } catch (error) { | ||
| console.error("Failed to check already in room", error); | ||
| return false; | ||
| } | ||
| }, | ||
| leave: async () => { | ||
| try { | ||
| get().actions.room.loading(); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Update
onJoinRoomto take a parameter on whether to validate if user is already in room or not