-
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.
feat: Added web implementation of code comments
- Loading branch information
1 parent
0a66673
commit 0cf1f92
Showing
5 changed files
with
137 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import useApiServiceClient from "@/hooks/useApiServiceClient"; | ||
import useClientQuery from "@/hooks/useClientQuery"; | ||
import { Solution } from "@/service/types/tasky"; | ||
import {Badge, Button, Card, Group, Stack, Title} from "@mantine/core"; | ||
import AssignmentDateDisplay from "@/components/assignments/AssignmentDateDisplay"; | ||
import RichTextDisplay from "@/components/display/RichTextDisplay"; | ||
import useCurrentUser from "@/hooks/useCurrentUser"; | ||
import {IconPlus} from "@tabler/icons-react"; | ||
import {useState} from "react"; | ||
import CreateCommentModal from "@/components/solution/CreateCommentModal"; | ||
|
||
interface CommentTabProps { | ||
solution: Solution; | ||
} | ||
|
||
const CommentTab = ({solution}: CommentTabProps) => { | ||
|
||
const api = useApiServiceClient(); | ||
const {user} = useCurrentUser(); | ||
const [createModalOpen, setCreateModalOpen] = useState(false); | ||
const [comments, refetch] = useClientQuery(() => api.getCodeComments(solution.id)); | ||
|
||
return ( | ||
<> | ||
<Stack gap={10}> | ||
<Group justify="flex-end"> | ||
<Button onClick={() => setCreateModalOpen(true)}><IconPlus /> | ||
Create Comment</Button> | ||
</Group> | ||
{(comments ?? []).map((comment) => ( | ||
<Card shadow="sm" padding="lg" radius="md" withBorder key={comment.id}> | ||
<Group> | ||
<Title order={4}>{comment.title}</Title> | ||
{comment.commentor === user?.id && ( | ||
<Badge color="green">Your comment</Badge> | ||
)} | ||
</Group> | ||
<RichTextDisplay content={comment.content} fullSize={false} /> | ||
</Card> | ||
))} | ||
</Stack> | ||
{createModalOpen && ( | ||
<CreateCommentModal | ||
solution={solution} | ||
refetch={refetch} | ||
onClose={() => setCreateModalOpen(false)} | ||
/> | ||
)} | ||
</> | ||
); | ||
} | ||
|
||
export default CommentTab; |
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,63 @@ | ||
import { Solution } from "@/service/types/tasky"; | ||
import {Button, Divider, Group, Modal, Stack, TextInput} from "@mantine/core"; | ||
import {useForm} from "@mantine/form"; | ||
import RichTextInput from "@/components/form/RichTextInput"; | ||
import useApiServiceClient from "@/hooks/useApiServiceClient"; | ||
import {notifications} from "@mantine/notifications"; | ||
|
||
|
||
interface CreateCommentModalProps { | ||
solution: Solution; | ||
refetch: () => void; | ||
onClose: () => void; | ||
} | ||
|
||
const CreateCommentModal = ({solution, refetch, onClose}: CreateCommentModalProps) => { | ||
|
||
const form = useForm({ | ||
initialValues: { | ||
title: '', | ||
content: '' | ||
} | ||
}); | ||
const api = useApiServiceClient(); | ||
|
||
const onSubmit = form.onSubmit(async (values) => { | ||
try { | ||
await api.createCodeComment(solution.id, values.title, values.content); | ||
refetch(); | ||
onClose(); | ||
} catch (e: any) { | ||
notifications.show({ | ||
title: 'Error', | ||
message: e?.message ?? "Failed to create comment", | ||
}) | ||
} | ||
}); | ||
|
||
return ( | ||
<Modal opened onClose={onClose} title="Create code comment" size="xl"> | ||
<form onSubmit={onSubmit}> | ||
<Stack gap={10}> | ||
<TextInput label="Title" key={form.key('title')} {...form.getInputProps('title')} /> | ||
<RichTextInput | ||
key={form.key('content')} | ||
content={form.getInputProps('content').value} | ||
setContent={form.getInputProps('content').onChange} | ||
/> | ||
</Stack> | ||
<Divider mt={10} /> | ||
<Group mt={10}> | ||
<Button type="submit"> | ||
Create questions | ||
</Button> | ||
<Button onClick={onClose} color="gray"> | ||
Cancel | ||
</Button> | ||
</Group> | ||
</form> | ||
</Modal> | ||
); | ||
} | ||
|
||
export default CreateCommentModal; |
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