Skip to content

Commit ace2322

Browse files
authored
Merge pull request #85 from JimTheCat/CU-86973uu60_Configure-Create-post_Patryk-Kosiski
feature: Configure creating posts
2 parents 0a92e0c + d55424e commit ace2322

File tree

12 files changed

+125
-40
lines changed

12 files changed

+125
-40
lines changed

frontend/src/Components/Buttons/Menu/MenuButton.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export const MenuButton = (props: MenuButtonProps) => {
1515
const navigate = useNavigate();
1616

1717
// check if the current location is a part of the href
18-
const isActive = location.pathname.includes(props.href || "") && props.href !== undefined;
18+
const isActive = location.pathname.includes(props.href ?? "") && props.href !== undefined;
1919

2020
return (
2121
<Button

frontend/src/Components/Cards/Post/Post.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import {useNavigate} from "react-router-dom";
2020
import {ImageWithSkeleton} from "../../ImageWithSkeleton/ImageWithSkeleton.tsx";
2121

2222
type PostProps = {
23-
userId: string;
23+
ownerLogin: string;
2424
contentHtml: string;
2525
photosUrls?: string[];
2626
createdAt: string;
@@ -29,7 +29,7 @@ type PostProps = {
2929
export const Post = (props: PostProps) => {
3030

3131
const auth = useAuthStore();
32-
const isOwner = auth.user?.login === props.userId;
32+
const isOwner = auth.user?.login === props.ownerLogin;
3333
const navigate = useNavigate();
3434

3535
/*Render this element each time when number of photos will change*/

frontend/src/Components/Navbar/Navbar.tsx

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import {MenuButton} from "../Buttons/Menu";
44
import {
55
IconHome,
66
IconMail,
7-
IconPencil,
87
IconSettings,
98
IconUserHeart,
109
IconUserPlus,
@@ -15,17 +14,29 @@ import {
1514
import {LogOut} from "../Buttons/LogOut/LogOut.tsx";
1615
import {useAuthStore} from "../../Services/authStore.ts";
1716
import {useNavigate} from "react-router-dom";
17+
import {CreatePost} from "../../Pages/CreatePost";
18+
import {BasicUserInfo} from "../../Services/DTOs/User.tsx";
19+
import {useEffect, useState} from "react";
20+
import api from "../../Services/api.ts";
1821

1922
export const Navbar = () => {
2023

2124
const auth = useAuthStore();
22-
const nickname = auth.user?.login;
2325
const navigate = useNavigate();
26+
const [basicUserInfo, setBasicUserInfo] = useState<BasicUserInfo | null>(null);
2427

2528
const handleProfileClick = () => {
2629
navigate(`/profile/${auth.user?.tag}`);
2730
}
2831

32+
useEffect(() => {
33+
if (auth.user) {
34+
api.get<BasicUserInfo>('/api/users/get-basic-user-info', {params: {login: auth.user.login}}).then((response) => {
35+
setBasicUserInfo(response.data);
36+
});
37+
}
38+
}, [auth.user]);
39+
2940
return (
3041
<>
3142

@@ -49,7 +60,7 @@ export const Navbar = () => {
4960
<Avatar radius={180} size={"xl"}/>
5061
<Stack justify={"center"} gap={0}>
5162
<Text>Witaj</Text>
52-
<Text>{nickname}!</Text>
63+
<Text>{basicUserInfo?.name} {basicUserInfo?.surname}</Text>
5364
</Stack>
5465
</Group>
5566
</Card>
@@ -61,7 +72,7 @@ export const Navbar = () => {
6172
<AppShell.Section grow component={ScrollArea}>
6273
<MenuButton icon={<IconHome/>} text={"Strona główna"} href={"/mainpage"}/>
6374
<MenuButton icon={<IconZoom/>} text={"Wyszukaj"} href={"/search"}/>
64-
<MenuButton icon={<IconPencil/>} text={"Napisz post"} href={"/createpost"}/>
75+
<CreatePost/>
6576
<MenuButton icon={<IconUsers/>} text={"Znajomi"} href={"/friends"}/>
6677
<MenuButton icon={<IconUsersGroup/>} text={"Grupy"} href={"/groups"}/>
6778
<MenuButton icon={<IconUserPlus/>} text={"Obserwowani"} href={"/following"}/>

frontend/src/Components/RichEditor/RichEditor.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import Superscript from '@tiptap/extension-superscript';
88
import SubScript from '@tiptap/extension-subscript';
99
import Placeholder from "@tiptap/extension-placeholder";
1010

11-
export const RichEditor = () => {
11+
export const RichEditor = ({onContentChange}: { onContentChange?: (html: string) => void }) => {
1212
const editor = useEditor({
1313
extensions: [
1414
StarterKit,
@@ -20,10 +20,13 @@ export const RichEditor = () => {
2020
TextAlign.configure({types: ['heading', 'paragraph']}),
2121
Placeholder.configure({placeholder: 'What\'s on your mind?'}),
2222
],
23+
onUpdate({editor}) {
24+
onContentChange && onContentChange(editor.getHTML());
25+
},
2326
});
2427

2528
return (
26-
<RichTextEditor editor={editor}>
29+
<RichTextEditor editor={editor} variant={"subtle"}>
2730
<RichTextEditor.Toolbar>
2831
<RichTextEditor.ControlsGroup>
2932
<RichTextEditor.Bold/>
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
import {RichEditor} from "../../Components/RichEditor";
2+
import {Button, Divider, Group, Modal} from "@mantine/core";
3+
import {useDisclosure} from "@mantine/hooks";
4+
import {IconPencil} from "@tabler/icons-react";
5+
import {useState} from "react";
6+
import api from "../../Services/api.ts";
7+
import {useAlert} from "../../Providers/AlertProvider.tsx";
8+
9+
export const CreatePost = () => {
10+
const [opened, {open, close}] = useDisclosure(false);
11+
const [content, setContent] = useState('');
12+
const alert = useAlert();
13+
14+
const handleContentChange = (html: string) => {
15+
setContent(html);
16+
}
17+
18+
const handleCreatePost = () => {
19+
console.log('Create post: ', content)
20+
if (!content) {
21+
alert.showError('Post is empty!');
22+
return;
23+
}
24+
25+
api.post('/api/posts/create', null, {params: {content}}).then((response) => {
26+
if (response.status === 200) {
27+
close();
28+
}
29+
});
30+
}
31+
32+
return (
33+
<>
34+
<Modal opened={opened} onClose={close} title="Create post" size={"auto"} centered closeOnClickOutside={false}>
35+
<RichEditor onContentChange={handleContentChange}/>
36+
<Divider my={"md"}/>
37+
<Group justify={"space-between"}>
38+
<Button color="red" variant="light" onClick={close}>Cancel</Button>
39+
<Button color="blue" variant="light" onClick={handleCreatePost}>Create</Button>
40+
</Group>
41+
</Modal>
42+
43+
<Button
44+
variant={"subtle"}
45+
size={"md"}
46+
leftSection={<IconPencil/>}
47+
autoContrast
48+
fullWidth
49+
justify={"flex-start"}
50+
color={"gray"}
51+
onClick={open}
52+
>
53+
Napisz post
54+
</Button>
55+
</>
56+
);
57+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from './CreatePost.tsx';

frontend/src/Pages/MainPage/MainPage.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export const MainPage = () => {
2020

2121
{/*Posts*/}
2222
{posts.map((post) => (
23-
<Post key={post.ownerLogin} userId={post.ownerLogin} contentHtml={post.content} createdAt={post.createdAt}
23+
<Post key={post.ownerLogin} ownerLogin={post.ownerLogin} contentHtml={post.content} createdAt={post.createdAt}
2424
photosUrls={
2525
// generate 100 random photos
2626
Array.from({length: 100}, () => {

frontend/src/Pages/Post/Post.tsx

Lines changed: 0 additions & 21 deletions
This file was deleted.

frontend/src/Pages/Post/index.tsx

Lines changed: 0 additions & 1 deletion
This file was deleted.

frontend/src/Pages/Root/Root.tsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import {NotFound} from "../NotFound";
77
import {Recovery} from "../Recovery";
88
import {Profile} from "../Profile";
99
import {Search} from "../Search";
10-
import {Post} from "../Post";
1110
import {Following} from "../Following";
1211
import {Groups} from "../Groups";
1312
import {Friends} from "../Friends";
@@ -37,7 +36,6 @@ export const Root = () => {
3736
<Route path="/mainpage" element={<MainPage/>}/>
3837
<Route path="/search" element={<Search/>}/>
3938
<Route path="/profile/:userTag" element={<Profile/>}/>
40-
<Route path="/createpost" element={<Post/>}/>
4139
<Route path="/following" element={<Following/>}/>
4240
<Route path="/groups" element={<Groups/>}/>
4341
<Route path="/friends" element={<Friends/>}/>

0 commit comments

Comments
 (0)