-
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.
Merge pull request #87 from JimTheCat/CU-869760jjk_Support-CRUD-for-P…
…osts_Patryk-Kosiski feature: Create post menu
- Loading branch information
Showing
16 changed files
with
215 additions
and
61 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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 |
---|---|---|
@@ -1,57 +1,55 @@ | ||
import {RichEditor} from "../shared/components/RichEditor"; | ||
import {Button, Divider, Group, Modal} from "@mantine/core"; | ||
import {useDisclosure} from "@mantine/hooks"; | ||
import {IconPencil} from "@tabler/icons-react"; | ||
import {useState} from "react"; | ||
import {useRef, useState} from "react"; | ||
import api from "../shared/services/api.ts"; | ||
import {useAlert} from "../../Providers/AlertProvider.tsx"; | ||
import {ModificationModal} from "../shared/components/ModificationModal"; | ||
import {Button} from "@mantine/core"; | ||
import {ModalRichContent} from "../shared/consts"; | ||
|
||
export const CreatePost = () => { | ||
const [opened, {open, close}] = useDisclosure(false); | ||
const [content, setContent] = useState(''); | ||
const contentRef = useRef(content); | ||
const alert = useAlert(); | ||
|
||
const handleContentChange = (html: string) => { | ||
setContent(html); | ||
contentRef.current = html; | ||
} | ||
|
||
const handleCreatePost = () => { | ||
console.log('Create post: ', content) | ||
if (!content) { | ||
const contentToSave = contentRef.current; | ||
console.log('Create post: ', contentToSave); | ||
if (!contentToSave) { | ||
alert.showError('Post is empty!'); | ||
return; | ||
} | ||
|
||
api.post('/api/posts/create', null, {params: {content}}).then((response) => { | ||
api.post('/api/posts/create', null, {params: {content: contentToSave}}).then((response) => { | ||
if (response.status === 200) { | ||
close(); | ||
} | ||
}); | ||
} | ||
|
||
return ( | ||
<> | ||
<Modal opened={opened} onClose={close} title="Create post" size={"auto"} centered closeOnClickOutside={false}> | ||
<RichEditor onContentChange={handleContentChange}/> | ||
<Divider my={"md"}/> | ||
<Group justify={"space-between"}> | ||
<Button color="red" variant="light" onClick={close}>Cancel</Button> | ||
<Button color="blue" variant="light" onClick={handleCreatePost}>Create</Button> | ||
</Group> | ||
</Modal> | ||
<Button | ||
variant={"subtle"} | ||
size={"md"} | ||
leftSection={<IconPencil/>} | ||
autoContrast | ||
fullWidth | ||
justify={"flex-start"} | ||
color={"gray"} | ||
onClick={() => ModificationModal({ | ||
handleAction: handleCreatePost, | ||
title: 'Create post', | ||
buttonConfirmText: 'Create', | ||
buttonConfirmColor: 'blue', | ||
childrenContent: <ModalRichContent handleContentChange={handleContentChange}/> | ||
})} | ||
> | ||
Create post | ||
</Button> | ||
|
||
<Button | ||
variant={"subtle"} | ||
size={"md"} | ||
leftSection={<IconPencil/>} | ||
autoContrast | ||
fullWidth | ||
justify={"flex-start"} | ||
color={"gray"} | ||
onClick={open} | ||
> | ||
Napisz post | ||
</Button> | ||
</> | ||
); | ||
} |
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
42 changes: 42 additions & 0 deletions
42
frontend/src/Features/shared/components/Cards/Post/components/EditPost/EditPost.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,42 @@ | ||
import {ModificationModal} from "../../../../ModificationModal"; | ||
import {IconPencil} from "@tabler/icons-react"; | ||
import {Menu, rem} from "@mantine/core"; | ||
import {useRef, useState} from "react"; | ||
import {ModalRichContent} from "../../../../../consts"; | ||
|
||
type EditPostProps = { | ||
content?: string; | ||
postId?: string; | ||
} | ||
|
||
export const EditPost = (props: EditPostProps) => { | ||
const [content, setContent] = useState(props.content ?? ''); | ||
const contentRef = useRef(content); | ||
|
||
const handleContentChange = (html: string) => { | ||
console.log('Content changed: ', html); | ||
setContent(html); | ||
contentRef.current = html; | ||
} | ||
|
||
const handleEditPost = () => { | ||
// TODO: Replace with actual edit logic | ||
console.log('Edit post: ', contentRef.current); | ||
}; | ||
|
||
return ( | ||
<Menu.Item | ||
leftSection={<IconPencil style={{width: rem(14), height: rem(14)}}/>} | ||
onClick={() => ModificationModal({ | ||
handleAction: handleEditPost, | ||
title: 'Edit post', | ||
buttonConfirmText: 'Save', | ||
buttonConfirmColor: 'blue', | ||
content: content, | ||
childrenContent: <ModalRichContent content={content} handleContentChange={handleContentChange}/> | ||
})} | ||
> | ||
Edit post | ||
</Menu.Item> | ||
); | ||
} |
1 change: 1 addition & 0 deletions
1
frontend/src/Features/shared/components/Cards/Post/components/EditPost/index.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 @@ | ||
export {EditPost} from './EditPost'; |
25 changes: 25 additions & 0 deletions
25
frontend/src/Features/shared/components/Cards/Post/components/MenuPost/MenuPost.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,25 @@ | ||
import {ActionIcon, Menu} from "@mantine/core"; | ||
import {IconDots} from "@tabler/icons-react"; | ||
import {EditPost} from "../EditPost"; | ||
import {RemovePost} from "../RemovePost"; | ||
|
||
type MenuPostProps = { | ||
content?: string; | ||
} | ||
|
||
export const MenuPost = (props: MenuPostProps) => { | ||
return ( | ||
<Menu radius={'sm'} shadow="xl" width={"auto"} closeOnItemClick> | ||
<Menu.Target> | ||
<ActionIcon size="lg" color="gray" radius={"xl"} variant={"subtle"}> | ||
<IconDots stroke={1.5}/> | ||
</ActionIcon> | ||
</Menu.Target> | ||
<Menu.Dropdown> | ||
<Menu.Label>Manage</Menu.Label> | ||
<EditPost content={props.content}/> | ||
<RemovePost/> | ||
</Menu.Dropdown> | ||
</Menu> | ||
); | ||
} |
1 change: 1 addition & 0 deletions
1
frontend/src/Features/shared/components/Cards/Post/components/MenuPost/index.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 @@ | ||
export {MenuPost} from './MenuPost'; |
30 changes: 30 additions & 0 deletions
30
frontend/src/Features/shared/components/Cards/Post/components/RemovePost/RemovePost.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,30 @@ | ||
import {Menu, rem, Text} from "@mantine/core"; | ||
import {IconTrash} from "@tabler/icons-react"; | ||
import {ModificationModal} from "../../../../ModificationModal"; | ||
|
||
type RemovePostProps = { | ||
postId?: string; | ||
} | ||
|
||
export const RemovePost = (props: RemovePostProps) => { | ||
const handleRemoval = () => { | ||
// TODO: Replace with actual removal logic | ||
console.log('Remove post: ', props.postId); | ||
}; | ||
|
||
return ( | ||
<Menu.Item | ||
color="red" | ||
leftSection={<IconTrash style={{width: rem(14), height: rem(14)}}/>} | ||
onClick={() => ModificationModal({ | ||
handleAction: handleRemoval, | ||
title: 'Remove post', | ||
buttonConfirmText: 'Remove', | ||
buttonConfirmColor: 'red', | ||
childrenContent: <Text>Are you sure that you want to remove your post?</Text> | ||
})} | ||
> | ||
Remove post | ||
</Menu.Item> | ||
); | ||
} |
1 change: 1 addition & 0 deletions
1
frontend/src/Features/shared/components/Cards/Post/components/RemovePost/index.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 @@ | ||
export {RemovePost} from './RemovePost'; |
25 changes: 25 additions & 0 deletions
25
frontend/src/Features/shared/components/ModificationModal/ModificationModal.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,25 @@ | ||
import {MantineColor} from "@mantine/core"; | ||
import {modals} from "@mantine/modals"; | ||
import React from "react"; | ||
|
||
type ModificationModalProps = { | ||
handleAction: () => void; | ||
buttonConfirmText: string; | ||
buttonConfirmColor: MantineColor; | ||
title: string; | ||
content?: string; | ||
childrenContent: React.ReactNode; | ||
} | ||
|
||
export const ModificationModal = (props: ModificationModalProps) => modals.openConfirmModal({ | ||
title: props.title, | ||
children: ( | ||
props.childrenContent | ||
), | ||
labels: {confirm: props.buttonConfirmText, cancel: "Cancel"}, | ||
confirmProps: {color: props.buttonConfirmColor}, | ||
size: "auto", | ||
centered: true, | ||
closeOnClickOutside: false, | ||
onConfirm: props.handleAction | ||
}); |
1 change: 1 addition & 0 deletions
1
frontend/src/Features/shared/components/ModificationModal/index.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 @@ | ||
export {ModificationModal} from './ModificationModal.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
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,19 @@ | ||
import {RichEditor} from "../components/RichEditor"; | ||
import {Divider} from "@mantine/core"; | ||
|
||
type ModalContentProps = { | ||
content?: string; | ||
handleContentChange: (html: string) => void; | ||
} | ||
|
||
export const ModalRichContent = (props: ModalContentProps) => { | ||
return ( | ||
<> | ||
<RichEditor | ||
content={props.content} | ||
onContentChange={props.handleContentChange} | ||
/> | ||
<Divider my={"md"}/> | ||
</> | ||
); | ||
}; |
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 +1,2 @@ | ||
export {Languages} from './Languages'; | ||
export {Languages} from './Languages'; | ||
export {ModalRichContent} from './ModalRichContent'; |
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