-
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.
- Loading branch information
1 parent
01e549c
commit 6832adc
Showing
34 changed files
with
545 additions
and
442 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
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
48 changes: 48 additions & 0 deletions
48
client/src/components/custom/ButtonWithTooltipWhenDisabled.tsx
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,48 @@ | ||
import { Button, ButtonProps } from "@/components/ui/button"; | ||
import { Tooltip, TooltipContent, TooltipTrigger } from "@/components/ui/tooltip"; | ||
|
||
interface ButtonWithTooltipWhenDisabledProps extends ButtonProps { | ||
onClick: () => void; | ||
tooltipText: string; | ||
ariaLabel: string; | ||
disabled: boolean; | ||
} | ||
|
||
export default function ButtonWithTooltipWhenDisabled({ | ||
children, | ||
className, | ||
variant = "ghost", | ||
size = "icon", | ||
ariaLabel, | ||
onClick, | ||
tooltipText, | ||
disabled | ||
}: ButtonWithTooltipWhenDisabledProps) { | ||
const button = ( | ||
<Button | ||
variant={variant} | ||
size={size} | ||
className={className} | ||
aria-label={ariaLabel} | ||
onClick={onClick} | ||
disabled={disabled} | ||
> | ||
{children} | ||
</Button> | ||
); | ||
|
||
if (!disabled) { | ||
return button; | ||
} | ||
|
||
return ( | ||
<Tooltip> | ||
<TooltipTrigger asChild> | ||
{button} | ||
</TooltipTrigger> | ||
<TooltipContent side="right" sideOffset={5}> | ||
{tooltipText} | ||
</TooltipContent> | ||
</Tooltip> | ||
); | ||
} |
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 was deleted.
Oops, something went wrong.
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,23 @@ | ||
mutation CreateSwarm($input: CreateSwarmRequest!) { | ||
swarmMutation { | ||
createSwarm(input: $input) { | ||
...User | ||
} | ||
} | ||
} | ||
|
||
mutation CreateInformationGraph($input: CreateInformationGraphRequest!) { | ||
informationGraphMutation { | ||
createInformationGraph(input: $input) { | ||
...User | ||
} | ||
} | ||
} | ||
|
||
mutation SendMessage($input: SendMessageRequest!) { | ||
chatMutation { | ||
sendMessage(input: $input) { | ||
...Chat | ||
} | ||
} | ||
} |
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 |
---|---|---|
|
@@ -2,4 +2,4 @@ subscription NewMessage($chatId: ID!) { | |
messageSent(chatId: $chatId) { | ||
...Message | ||
} | ||
} | ||
} |
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 |
---|---|---|
@@ -1,11 +1,20 @@ | ||
import { useFetchUserQuery } from "../graphql/generated/graphql"; | ||
import { ApolloError } from "@apollo/client"; | ||
import { FetchUserQueryResult, useFetchUserQuery, User } from "../graphql/generated/graphql"; | ||
|
||
export function useFetchUser() { | ||
const { data, loading, error } = useFetchUserQuery(); | ||
export function useFetchUser(): { | ||
user: User | null; | ||
loading: boolean; | ||
error: ApolloError | null; | ||
refetch: () => Promise<FetchUserQueryResult>; | ||
} { | ||
const { data, loading, error, refetch } = useFetchUserQuery({ | ||
fetchPolicy: 'cache-and-network', | ||
}); | ||
|
||
return { | ||
user: data?.user, | ||
user: data?.user || null, | ||
loading, | ||
error | ||
error: error || null, | ||
refetch: refetch as () => Promise<FetchUserQueryResult> | ||
}; | ||
} |
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,72 @@ | ||
import { useState } from "react"; | ||
import { Dialog, DialogContent } from "@/components/ui/dialog"; | ||
import { Input } from "@/components/ui/input"; | ||
import { CreateInformationGraphRequest, useCreateInformationGraphMutation } from "../../graphql/generated/graphql"; | ||
import { useFetchUser } from "../../hooks/fetchUser"; | ||
import ButtonWithTooltipWhenDisabled from "@/components/custom/ButtonWithTooltipWhenDisabled"; | ||
|
||
interface CreateInformationDialogProps { | ||
open: boolean; | ||
onOpenChange: (open: boolean) => void; | ||
} | ||
|
||
const initialCreateInformationGraphRequest: CreateInformationGraphRequest = { | ||
title: '', | ||
} | ||
|
||
export function CreateInformationDialog({ open, onOpenChange }: CreateInformationDialogProps) { | ||
const [createInformationGraphRequest, setCreateInformationGraphRequest] = useState<CreateInformationGraphRequest>(initialCreateInformationGraphRequest) | ||
const [createInformationGraph] = useCreateInformationGraphMutation(); | ||
const { refetch } = useFetchUser(); | ||
|
||
const handleCreateInformationGraph = async () => { | ||
try { | ||
const result = await createInformationGraph({ | ||
variables: { input: createInformationGraphRequest }, | ||
}); | ||
console.log(result); | ||
await refetch(); // Refetch user data after creating a new information graph | ||
onOpenChange(false); | ||
setCreateInformationGraphRequest(initialCreateInformationGraphRequest); | ||
} catch (error) { | ||
console.error("Error creating information graph:", error); | ||
} | ||
}; | ||
|
||
const isCreateButtonDisabled = !createInformationGraphRequest.title | ||
|
||
const handleSubmit = (e: React.FormEvent) => { | ||
e.preventDefault(); | ||
if (!isCreateButtonDisabled) { | ||
handleCreateInformationGraph(); | ||
} | ||
}; | ||
|
||
return ( | ||
<Dialog open={open} onOpenChange={onOpenChange}> | ||
<DialogContent className="bg-background border-secondary border-2 rounded-2xl"> | ||
<form onSubmit={handleSubmit}> | ||
<div className="grid gap-4 py-4 px-20 mt-2"> | ||
<Input | ||
className="bg-secondary rounded-2xl" | ||
placeholder="Title" | ||
value={createInformationGraphRequest.title} | ||
onChange={(e) => setCreateInformationGraphRequest({ ...createInformationGraphRequest, title: e.target.value })} | ||
/> | ||
</div> | ||
<div className="flex justify-end"> | ||
<ButtonWithTooltipWhenDisabled | ||
type="submit" | ||
disabled={isCreateButtonDisabled} | ||
onClick={() => {}} // This is needed because the onClick prop is required | ||
tooltipText="Please enter a title" | ||
ariaLabel="Create information graph" | ||
> | ||
Create | ||
</ButtonWithTooltipWhenDisabled> | ||
</div> | ||
</form> | ||
</DialogContent> | ||
</Dialog> | ||
); | ||
} |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.