Added individual post page
This commit is contained in:
@@ -8,6 +8,7 @@ import ManageUserAccountPage from "./pages/ManageUserAccountPage";
|
|||||||
import CommunityPage from "./pages/CommunityPage";
|
import CommunityPage from "./pages/CommunityPage";
|
||||||
import CreatePostPage from "./pages/CreatePostPage";
|
import CreatePostPage from "./pages/CreatePostPage";
|
||||||
import EditPostPage from "./pages/EditPostPage";
|
import EditPostPage from "./pages/EditPostPage";
|
||||||
|
import PostPage from './pages/PostPage';
|
||||||
import SchedulePage from "./pages/SchedulePage";
|
import SchedulePage from "./pages/SchedulePage";
|
||||||
import EventsPage from "./pages/EventsPage";
|
import EventsPage from "./pages/EventsPage";
|
||||||
import AdministratorSpringboard from "./pages/AdministratorSpringboard";
|
import AdministratorSpringboard from "./pages/AdministratorSpringboard";
|
||||||
@@ -25,6 +26,7 @@ function App() {
|
|||||||
<Route element={<CommunityPage />} path="/community" />
|
<Route element={<CommunityPage />} path="/community" />
|
||||||
<Route element={<CreatePostPage />} path="/createPost" />
|
<Route element={<CreatePostPage />} path="/createPost" />
|
||||||
<Route element={<EditPostPage />} path="/editPost/:id" />
|
<Route element={<EditPostPage />} path="/editPost/:id" />
|
||||||
|
<Route element={<PostPage />} path="/post/:id" />
|
||||||
<Route element={<SchedulePage />} path="/schedule" />
|
<Route element={<SchedulePage />} path="/schedule" />
|
||||||
<Route element={<EventsPage />} path="/events" />
|
<Route element={<EventsPage />} path="/events" />
|
||||||
</Routes>
|
</Routes>
|
||||||
|
|||||||
@@ -10,8 +10,6 @@ import {
|
|||||||
DropdownItem,
|
DropdownItem,
|
||||||
Input,
|
Input,
|
||||||
Chip,
|
Chip,
|
||||||
} from "@nextui-org/react";
|
|
||||||
import {
|
|
||||||
Modal,
|
Modal,
|
||||||
ModalContent,
|
ModalContent,
|
||||||
ModalHeader,
|
ModalHeader,
|
||||||
@@ -30,9 +28,12 @@ import {
|
|||||||
XMarkIcon,
|
XMarkIcon,
|
||||||
} from "../icons";
|
} from "../icons";
|
||||||
import { useNavigate } from "react-router-dom";
|
import { useNavigate } from "react-router-dom";
|
||||||
|
// import { retrieveUserInformation } from "../security/users";
|
||||||
|
// import UserPostImage from "../components/UserPostImage";
|
||||||
|
|
||||||
interface Post {
|
interface Post {
|
||||||
title: string;
|
title: string;
|
||||||
|
postImage: Blob;
|
||||||
content: string;
|
content: string;
|
||||||
tags: string;
|
tags: string;
|
||||||
id: number;
|
id: number;
|
||||||
@@ -43,6 +44,8 @@ export default function CommunityPage() {
|
|||||||
const { isOpen, onOpen, onOpenChange } = useDisclosure();
|
const { isOpen, onOpen, onOpenChange } = useDisclosure();
|
||||||
const [selectedPost, setSelectedPost] = useState<Post | null>(null);
|
const [selectedPost, setSelectedPost] = useState<Post | null>(null);
|
||||||
|
|
||||||
|
// const [userInformation, setUserInformation] = useState(null);
|
||||||
|
|
||||||
// communityList is a state variable
|
// communityList is a state variable
|
||||||
// function setCommunityList is the setter function for the state variable
|
// function setCommunityList is the setter function for the state variable
|
||||||
// e initial value of the state variable is an empty array []
|
// e initial value of the state variable is an empty array []
|
||||||
@@ -114,6 +117,18 @@ export default function CommunityPage() {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// useEffect(() => {
|
||||||
|
// retrieveUserInformation()
|
||||||
|
// .then((response) => {
|
||||||
|
// setUserInformation(response);
|
||||||
|
// })
|
||||||
|
// return;
|
||||||
|
// }, []);
|
||||||
|
|
||||||
|
const handlePostClick = (id: number) => {
|
||||||
|
navigate(`/post/${id}`);
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<DefaultLayout>
|
<DefaultLayout>
|
||||||
<div className="flex flex-row gap-4 m-10">
|
<div className="flex flex-row gap-4 m-10">
|
||||||
@@ -130,8 +145,9 @@ export default function CommunityPage() {
|
|||||||
<section
|
<section
|
||||||
className="flex flex-row gap-4 bg-primary-50 dark:bg-primary-950 border border-none rounded-2xl p-4"
|
className="flex flex-row gap-4 bg-primary-50 dark:bg-primary-950 border border-none rounded-2xl p-4"
|
||||||
key={post.id}
|
key={post.id}
|
||||||
|
onClick={() => handlePostClick(post.id)}
|
||||||
>
|
>
|
||||||
<div>
|
<div onClick={(e) => e.stopPropagation()}>
|
||||||
<Avatar
|
<Avatar
|
||||||
src="https://pbs.twimg.com/media/GOva9x5a0AAK8Bn?format=jpg&name=large"
|
src="https://pbs.twimg.com/media/GOva9x5a0AAK8Bn?format=jpg&name=large"
|
||||||
size="lg"
|
size="lg"
|
||||||
@@ -147,7 +163,8 @@ export default function CommunityPage() {
|
|||||||
<div className="flex flex-row-reverse justify-center items-center">
|
<div className="flex flex-row-reverse justify-center items-center">
|
||||||
<Dropdown>
|
<Dropdown>
|
||||||
<div>
|
<div>
|
||||||
<DropdownTrigger className="justify-center items-center">
|
<DropdownTrigger className="justify-center items-center"
|
||||||
|
onClick={(e) => e.stopPropagation()}>
|
||||||
<Button isIconOnly variant="light">
|
<Button isIconOnly variant="light">
|
||||||
<EllipsisHorizontalIcon />
|
<EllipsisHorizontalIcon />
|
||||||
</Button>
|
</Button>
|
||||||
@@ -177,6 +194,15 @@ export default function CommunityPage() {
|
|||||||
<div>
|
<div>
|
||||||
<p>{post.content}</p>
|
<p>{post.content}</p>
|
||||||
</div>
|
</div>
|
||||||
|
<div>
|
||||||
|
<p>Image</p>
|
||||||
|
{/* {userInformation && (
|
||||||
|
<UserPostImage
|
||||||
|
userId={userInformation}
|
||||||
|
editable={true}
|
||||||
|
/>
|
||||||
|
)} */}
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div className="flex flex-col gap-2">
|
<div className="flex flex-col gap-2">
|
||||||
<div className="flex flex-row gap-2">
|
<div className="flex flex-row gap-2">
|
||||||
@@ -184,18 +210,19 @@ export default function CommunityPage() {
|
|||||||
<Chip>Tag 2</Chip>
|
<Chip>Tag 2</Chip>
|
||||||
</div>
|
</div>
|
||||||
<div className="flex flex-row">
|
<div className="flex flex-row">
|
||||||
<Button variant="light" isIconOnly>
|
<Button variant="light" isIconOnly onClick={(e) => e.stopPropagation()}>
|
||||||
<HandThumbsUpIcon />
|
<HandThumbsUpIcon />
|
||||||
</Button>
|
</Button>
|
||||||
<Button variant="light" isIconOnly>
|
<Button variant="light" isIconOnly onClick={(e) => e.stopPropagation()}>
|
||||||
<ChatBubbleOvalLeftEllipsisIcon />
|
<ChatBubbleOvalLeftEllipsisIcon />
|
||||||
</Button>
|
</Button>
|
||||||
<Button variant="light" isIconOnly>
|
<Button variant="light" isIconOnly onClick={(e) => e.stopPropagation()}>
|
||||||
<EllipsisHorizontalIcon />
|
<EllipsisHorizontalIcon />
|
||||||
</Button>
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
</section>
|
</section>
|
||||||
);
|
);
|
||||||
})}
|
})}
|
||||||
|
|||||||
@@ -62,7 +62,7 @@ function CreatePostPage() {
|
|||||||
setSubmitting(false);
|
setSubmitting(false);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<DefaultLayout>
|
<DefaultLayout>
|
||||||
<section className="w-8/12 mx-auto">
|
<section className="w-8/12 mx-auto">
|
||||||
@@ -93,7 +93,9 @@ function CreatePostPage() {
|
|||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
<div className="text-sm">
|
<div className="text-sm">
|
||||||
<p>Image</p>
|
<div>
|
||||||
|
<p>Image</p>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
<NextUIFormikTextarea
|
<NextUIFormikTextarea
|
||||||
@@ -111,10 +113,10 @@ function CreatePostPage() {
|
|||||||
labelPlacement="inside"
|
labelPlacement="inside"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
<div className="flex flex-row-reverse border">
|
<div className="flex flex-row-reverse">
|
||||||
<Button
|
<Button
|
||||||
type="submit"
|
type="submit"
|
||||||
className="bg-primary-color text-white text-xl w-1/6"
|
className="bg-primary-color text-white text-xl w-1/12"
|
||||||
disabled={!isValid || !dirty || isSubmitting}
|
disabled={!isValid || !dirty || isSubmitting}
|
||||||
>
|
>
|
||||||
<p>Post</p>
|
<p>Post</p>
|
||||||
|
|||||||
@@ -124,7 +124,7 @@ function editPost() {
|
|||||||
labelPlacement="inside"
|
labelPlacement="inside"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
<div className="flex flex-row-reverse border">
|
<div className="flex flex-row-reverse">
|
||||||
<Button
|
<Button
|
||||||
type="submit"
|
type="submit"
|
||||||
className="bg-primary-color text-white text-xl w-1/6"
|
className="bg-primary-color text-white text-xl w-1/6"
|
||||||
|
|||||||
196
client/src/pages/PostPage.tsx
Normal file
196
client/src/pages/PostPage.tsx
Normal file
@@ -0,0 +1,196 @@
|
|||||||
|
import { useParams, useNavigate } from 'react-router-dom';
|
||||||
|
import { useEffect, useState } from 'react';
|
||||||
|
import DefaultLayout from "../layouts/default";
|
||||||
|
import instance from "../security/http";
|
||||||
|
import config from "../config";
|
||||||
|
import {
|
||||||
|
Button,
|
||||||
|
Avatar,
|
||||||
|
Dropdown,
|
||||||
|
DropdownTrigger,
|
||||||
|
DropdownMenu,
|
||||||
|
DropdownItem,
|
||||||
|
Chip,
|
||||||
|
Modal,
|
||||||
|
ModalContent,
|
||||||
|
ModalHeader,
|
||||||
|
ModalBody,
|
||||||
|
ModalFooter,
|
||||||
|
useDisclosure,
|
||||||
|
Spinner,
|
||||||
|
} from "@nextui-org/react";
|
||||||
|
import {
|
||||||
|
ChatBubbleOvalLeftEllipsisIcon,
|
||||||
|
EllipsisHorizontalIcon,
|
||||||
|
HandThumbsUpIcon,
|
||||||
|
ArrowUTurnLeftIcon,
|
||||||
|
} from "../icons";
|
||||||
|
|
||||||
|
interface Post {
|
||||||
|
title: string;
|
||||||
|
postImage: Blob;
|
||||||
|
content: string;
|
||||||
|
tags: string;
|
||||||
|
id: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
const PostPage: React.FC = () => {
|
||||||
|
const navigate = useNavigate();
|
||||||
|
const { id } = useParams<{ id: string }>();
|
||||||
|
const [post, setPost] = useState<Post | null>(null);
|
||||||
|
const { isOpen, onOpen, onOpenChange } = useDisclosure();
|
||||||
|
const [selectedPost, setSelectedPost] = useState<Post | null>(null);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (id) {
|
||||||
|
instance.get(`${config.serverAddress}/post/${id}`).then((res) => {
|
||||||
|
setPost(res.data);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}, [id]);
|
||||||
|
|
||||||
|
if (!post) {
|
||||||
|
return <div className="flex justify-center min-h-screen"><Spinner label="Loading..." color="danger" /></div>;
|
||||||
|
}
|
||||||
|
|
||||||
|
const handleDeleteClick = (post: Post) => {
|
||||||
|
setSelectedPost(post);
|
||||||
|
onOpen();
|
||||||
|
};
|
||||||
|
const handleDeleteConfirm = async () => {
|
||||||
|
if (selectedPost) {
|
||||||
|
try {
|
||||||
|
await instance.delete(
|
||||||
|
config.serverAddress + `/post/${selectedPost.id}`
|
||||||
|
);
|
||||||
|
onOpenChange();
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Error deleting post:", error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<DefaultLayout>
|
||||||
|
<section className="flex">
|
||||||
|
<div className="w-2/12 flex justify-end">
|
||||||
|
<Button
|
||||||
|
variant="light"
|
||||||
|
onPress={() => {
|
||||||
|
navigate(-1);
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<ArrowUTurnLeftIcon />
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
<div className="flex flex-row w-full gap-4 mx-auto ">
|
||||||
|
<div className="flex flex-col gap-8 w-full">
|
||||||
|
<div className="flex flex-col gap-4">
|
||||||
|
<section
|
||||||
|
className="flex flex-row gap-4 bg-primary-50 dark:bg-primary-950 border border-none rounded-2xl p-4"
|
||||||
|
key={post.id}>
|
||||||
|
<div>
|
||||||
|
<Avatar
|
||||||
|
src="https://pbs.twimg.com/media/GOva9x5a0AAK8Bn?format=jpg&name=large"
|
||||||
|
size="lg"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<div className="flex flex-col gap-8 w-full">
|
||||||
|
<div className="h-full flex flex-col gap-4">
|
||||||
|
<div className="flex flex-row justify-between">
|
||||||
|
<div className="flex flex-col">
|
||||||
|
<p className="text-xl font-bold">{post.title}</p>
|
||||||
|
<p className="text-md text-neutral-500">Adam</p>
|
||||||
|
</div>
|
||||||
|
<div className="flex flex-row-reverse justify-center items-center">
|
||||||
|
<Dropdown>
|
||||||
|
<DropdownTrigger className="justify-center items-center">
|
||||||
|
<Button isIconOnly variant="light">
|
||||||
|
<EllipsisHorizontalIcon />
|
||||||
|
</Button>
|
||||||
|
</DropdownTrigger>
|
||||||
|
<DropdownMenu aria-label="Static Actions">
|
||||||
|
<DropdownItem
|
||||||
|
key="edit"
|
||||||
|
onClick={() => {
|
||||||
|
navigate(`/editPost/${post.id}`);
|
||||||
|
}}>
|
||||||
|
Edit
|
||||||
|
</DropdownItem>
|
||||||
|
<DropdownItem
|
||||||
|
key="delete"
|
||||||
|
className="text-danger"
|
||||||
|
color="danger"
|
||||||
|
onClick={() => handleDeleteClick(post)}
|
||||||
|
>
|
||||||
|
Delete
|
||||||
|
</DropdownItem>
|
||||||
|
</DropdownMenu>
|
||||||
|
</Dropdown>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<p>{post.content}</p>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<p>Image</p>
|
||||||
|
{/* {userInformation && (
|
||||||
|
<UserPostImage
|
||||||
|
userId={userInformation}
|
||||||
|
editable={true}
|
||||||
|
/>
|
||||||
|
)} */}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div className="flex flex-col gap-2">
|
||||||
|
<div className="flex flex-row gap-2">
|
||||||
|
<Chip>Tag 1</Chip>
|
||||||
|
<Chip>Tag 2</Chip>
|
||||||
|
</div>
|
||||||
|
<div className="flex flex-row">
|
||||||
|
<Button variant="light" isIconOnly>
|
||||||
|
<HandThumbsUpIcon />
|
||||||
|
</Button>
|
||||||
|
<Button variant="light" isIconOnly>
|
||||||
|
<ChatBubbleOvalLeftEllipsisIcon />
|
||||||
|
</Button>
|
||||||
|
<Button variant="light" isIconOnly>
|
||||||
|
<EllipsisHorizontalIcon />
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div className="w-2/12">
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
<Modal isOpen={isOpen} onOpenChange={onOpenChange}>
|
||||||
|
<ModalContent>
|
||||||
|
{(onClose) => (
|
||||||
|
<>
|
||||||
|
<ModalHeader className="flex flex-col gap-1">
|
||||||
|
Confirm Delete
|
||||||
|
</ModalHeader>
|
||||||
|
<ModalBody>
|
||||||
|
<p>Are you sure you want to delete this post?</p>
|
||||||
|
</ModalBody>
|
||||||
|
<ModalFooter>
|
||||||
|
<Button color="danger" variant="light" onPress={onClose}>
|
||||||
|
Close
|
||||||
|
</Button>
|
||||||
|
<Button color="primary" onPress={handleDeleteConfirm}>
|
||||||
|
Confirm
|
||||||
|
</Button>
|
||||||
|
</ModalFooter>
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
</ModalContent>
|
||||||
|
</Modal>
|
||||||
|
</DefaultLayout>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export default PostPage;
|
||||||
@@ -1,9 +1,19 @@
|
|||||||
module.exports = (sequelize, DataTypes) => {
|
module.exports = (sequelize, DataTypes) => {
|
||||||
const Post = sequelize.define("Post", {
|
const Post = sequelize.define("Post", {
|
||||||
|
id: {
|
||||||
|
type: DataTypes.UUID,
|
||||||
|
defaultValue: DataTypes.UUIDV4,
|
||||||
|
allowNull: false,
|
||||||
|
primaryKey: true,
|
||||||
|
},
|
||||||
title: {
|
title: {
|
||||||
type: DataTypes.STRING(100),
|
type: DataTypes.STRING(100),
|
||||||
allowNull: false
|
allowNull: false
|
||||||
},
|
},
|
||||||
|
postImage: {
|
||||||
|
type: DataTypes.BLOB("long"),
|
||||||
|
allowNull: true,
|
||||||
|
},
|
||||||
content: {
|
content: {
|
||||||
type: DataTypes.TEXT,
|
type: DataTypes.TEXT,
|
||||||
allowNull: false
|
allowNull: false
|
||||||
|
|||||||
@@ -3,6 +3,8 @@ const router = express.Router();
|
|||||||
const { Post } = require('../models');
|
const { Post } = require('../models');
|
||||||
const { Op, where } = require("sequelize");
|
const { Op, where } = require("sequelize");
|
||||||
const yup = require("yup");
|
const yup = require("yup");
|
||||||
|
const multer = require("multer");
|
||||||
|
const sharp = require("sharp");
|
||||||
|
|
||||||
// Profanity function
|
// Profanity function
|
||||||
const Filter = require('bad-words'); // Import the bad-words library
|
const Filter = require('bad-words'); // Import the bad-words library
|
||||||
@@ -19,7 +21,8 @@ router.post("/", async (req, res) => {
|
|||||||
// Validate request body
|
// Validate request body
|
||||||
let validationSchema = yup.object({
|
let validationSchema = yup.object({
|
||||||
title: yup.string().trim().min(3).max(200).required(), // yup object to define validation schema
|
title: yup.string().trim().min(3).max(200).required(), // yup object to define validation schema
|
||||||
content: yup.string().trim().min(3).max(500).required()
|
content: yup.string().trim().min(3).max(500).required(),
|
||||||
|
postImage: yup.string().trim().max(255),
|
||||||
});
|
});
|
||||||
try {
|
try {
|
||||||
data = await validationSchema.validate(data, // validate() method is used to validate data against the schema and returns the valid data and any applied transformations
|
data = await validationSchema.validate(data, // validate() method is used to validate data against the schema and returns the valid data and any applied transformations
|
||||||
|
|||||||
Reference in New Issue
Block a user