Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/posts #19

Open
wants to merge 42 commits into
base: temp/main1
Choose a base branch
from
Open
Changes from 1 commit
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
6438955
added frontend
ovindumandith Apr 29, 2024
1d74fe4
added ReplyModel for frontend
ovindumandith Apr 29, 2024
911570d
made changes to replymodel
ovindumandith Apr 29, 2024
8921b63
changes to frontend
ovindumandith Apr 29, 2024
20c6f4f
made changes to frontend
ovindumandith Apr 30, 2024
3338728
changes made to frontend of posts
ovindumandith Apr 30, 2024
72d0883
made xhanges to frontend
ovindumandith May 1, 2024
047e32e
frontend changes to user profile
ovindumandith May 1, 2024
dad8ca8
added DTO for comments and posts
ovindumandith May 1, 2024
4dd2d53
frontend changes made
ovindumandith May 1, 2024
0282712
added post shre class
ovindumandith May 2, 2024
86134b9
added post shre DTO class
ovindumandith May 2, 2024
7ed3e28
few refinements
ovindumandith May 2, 2024
fe246e2
frontend changes for posts
ovindumandith May 3, 2024
ae70466
Frontend link changes
ovindumandith May 3, 2024
f01a84f
Update README.md
IT21063596 May 7, 2024
5ff8efc
updated backend for posts,like and comments
ovindumandith May 7, 2024
a9545ec
updated backend for posts,like and comments with redux
ovindumandith May 7, 2024
f79e840
updated backend for posts,like and comments with redux and axios
ovindumandith May 8, 2024
b26615b
updated backend for posts,like and comments with redux and clodinary
ovindumandith May 8, 2024
f047549
Merge branch 'feature/posts' of https://github.com/PAF-IT3030/paf-ass…
ovindumandith May 8, 2024
c3f52aa
updated backend for edit posts
ovindumandith May 8, 2024
bffaed4
updated backend for edit posts and adding comments
ovindumandith May 9, 2024
a66c4e1
updated backend for post to pass the image URL to the DB
ovindumandith May 10, 2024
275baa7
updated frontend to send the image to S3 bucket
ovindumandith May 10, 2024
7aea21c
updated frontend to send the image to S3 bucket through .env
ovindumandith May 10, 2024
1ae3c9b
updated backend to modify the post entity
ovindumandith May 10, 2024
be59344
updated backend to modify the post entity
ovindumandith May 10, 2024
11e183d
updated fronted o handle edit of posts
ovindumandith May 10, 2024
4fceba0
updated fronted o handle edit of posts
ovindumandith May 10, 2024
9a0b21b
updated fronted to address the non sterlized values
ovindumandith May 10, 2024
009e5a8
updated fronted to address the non sterlized values
ovindumandith May 10, 2024
d16a42d
updated frontend for error correction in rendering of posts
ovindumandith May 10, 2024
3d7fbce
made api corrections for delete function
ovindumandith May 11, 2024
018cab3
added toaastify for alert functios
ovindumandith May 11, 2024
6156692
mapped backend and frontened to handle update posts
ovindumandith May 11, 2024
822d645
updated gitignore to avoid pushing secret keys
ovindumandith May 11, 2024
895aaac
updated gitignore to avoid pushing secret keys
ovindumandith May 11, 2024
dfb7b3a
updated gitignore to avoid pushing secret keys
ovindumandith May 11, 2024
a9dcc7f
updated gitignore to avoid pushing secret keys
ovindumandith May 11, 2024
52944f5
mapped backend and frontened to handle update posts
ovindumandith May 11, 2024
dfe561c
made cahanges for user profile to display the posts
ovindumandith May 11, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
updated backend for posts,like and comments with redux and clodinary
ovindumandith committed May 8, 2024
commit b26615bfc9252b028764331ccd29b9f0571f24a0
75 changes: 75 additions & 0 deletions frontend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions frontend/package.json
Original file line number Diff line number Diff line change
@@ -8,10 +8,13 @@
"@mui/icons-material": "^5.15.15",
"@mui/lab": "^5.0.0-alpha.170",
"@mui/material": "^5.15.15",
"@reduxjs/toolkit": "^2.2.3",
"@testing-library/jest-dom": "^5.17.0",
"@testing-library/react": "^13.4.0",
"@testing-library/user-event": "^13.5.0",
"axios": "^1.6.8",
"cloudinary": "^2.2.0",
"cloudinary-react": "^1.8.1",
"formik": "^2.4.5",
"react": "^18.2.0",
"react-dom": "^18.2.0",
7 changes: 5 additions & 2 deletions frontend/src/Components/HomeSection/HomeSection.jsx
Original file line number Diff line number Diff line change
@@ -2,6 +2,7 @@ import React from "react";
import { connect } from "react-redux";
import MealPost from "./MealPost";
import { addPost } from "../Store/Action";
import NewPost from "./NewPost";

const HomeSection = ({ meals, dispatch }) => {
const handlePost = (newMeal) => {
@@ -17,10 +18,12 @@ const HomeSection = ({ meals, dispatch }) => {
<section className="pb-10">
{/* Render existing posts */}
{meals.map((meal, index) => (
<MealPost key={index} meal={meal} />
<MealPost key={index} meal={meal} imageUrl={meal.imageUrl} />
))}
{/* Assuming meal object contains the imageUrl property */}

{/* Render new post */}
<MealPost handlePost={handlePost} />
<NewPost handlePost={handlePost} />
</section>
</div>
);
83 changes: 18 additions & 65 deletions frontend/src/Components/HomeSection/MealPost.jsx
Original file line number Diff line number Diff line change
@@ -1,94 +1,47 @@
import React, { useState } from "react";
import { IconButton, Button } from "@mui/material";
import PhotoCameraIcon from "@mui/icons-material/PhotoCamera";
import ThumbUpIcon from "@mui/icons-material/ThumbUp";
import ChatIcon from "@mui/icons-material/Chat";
import React from "react";
import { IconButton } from "@mui/material";
import EditIcon from "@mui/icons-material/Edit";
import DeleteIcon from "@mui/icons-material/Delete";
import ReplyModel from "./ReplyModel";
import { useDispatch } from "react-redux";
import { addPost } from "../Store/Actions"; // Assuming your action is in this file

const MealPost = () => {
const MealPost = ({ meal }) => {
const dispatch = useDispatch();
const [caption, setCaption] = useState("");
const [image, setImage] = useState(null);
const [openReplyModel, setOpenReplyModel] = useState(false);
const { caption, imageUrl } = meal;

const handleImageChange = (e) => {
setImage(e.target.files[0]);
const handleEditPost = () => {
// Placeholder logic for editing post
console.log("Edit Post");
};

const handlePostClick = () => {
if (image && caption) {
const formData = new FormData();
formData.append("caption", caption);
formData.append("image", image);
dispatch(addPost(formData));
setCaption("");
setImage(null);
}
const handleDeletePost = () => {
// Placeholder logic for deleting post
console.log("Delete Post");
};

return (
<div className="p-4 border rounded-md shadow-md bg-white">
<textarea
rows={4}
placeholder="Write a caption..."
className="w-full border border-gray-300 rounded-md p-2 mb-2"
value={caption}
onChange={(e) => setCaption(e.target.value)}
></textarea>
<div className="flex items-center mb-2">
<input
type="file"
accept="image/*"
id="image-upload"
className="hidden"
onChange={handleImageChange}
/>
<label htmlFor="image-upload">
<IconButton component="span">
<PhotoCameraIcon />
</IconButton>
</label>
{image && (
<div className="p-4 border rounded-md shadow-md bg-white margin">
<div className="flex items-center mb-2">{caption}</div>
{imageUrl && (
<div className="flex items-center mb-2">
<img
src={URL.createObjectURL(image)}
src={imageUrl}
alt="Uploaded"
className="w-20 h-20 object-cover rounded-md ml-2"
/>
)}
</div>
<div className="flex items-center justify-between">
<div>
<IconButton onClick={handlePostClick} disabled={!image || !caption}>
<ThumbUpIcon />
</IconButton>
<IconButton onClick={() => setOpenReplyModel(true)}>
<ChatIcon />
</IconButton>
</div>
)}
<div className="flex items-center justify-between">
<div>
<IconButton onClick={() => handleEditPost()}>
<EditIcon />
</IconButton>
<IconButton onClick={() => handleDeletePost()}>
<DeleteIcon />
</IconButton>
<Button
variant="contained"
onClick={handlePostClick}
disabled={!image || !caption}
>
Post
</Button>
</div>
</div>
<ReplyModel
open={openReplyModel}
handleClose={() => setOpenReplyModel(false)}
/>
<ReplyModel />
</div>
);
};
127 changes: 127 additions & 0 deletions frontend/src/Components/HomeSection/NewPost.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
import React, { useState } from "react";
import { IconButton, Button } from "@mui/material";
import PhotoCameraIcon from "@mui/icons-material/PhotoCamera";
import ThumbUpIcon from "@mui/icons-material/ThumbUp";
import ChatIcon from "@mui/icons-material/Chat";
import EditIcon from "@mui/icons-material/Edit";
import DeleteIcon from "@mui/icons-material/Delete";
import ReplyModel from "./ReplyModel";
import { useDispatch } from "react-redux";
import { addPost } from "../Store/Action";

const NewPost = () => {
const dispatch = useDispatch();
const [caption, setCaption] = useState("");
const [image, setImage] = useState(null);
const [openReplyModel, setOpenReplyModel] = useState(false);

const handleImageChange = (e) => {
setImage(e.target.files[0]);
};

const handlePostClick = async () => {
if (image && caption) {
try {
// Upload image to Cloudinary
const formData = new FormData();
formData.append("file", image);
formData.append("upload_preset", "paf123");
const response = await fetch(
"https://api.cloudinary.com/v1_1/ddvmuwi3e/image/upload",
{
method: "POST",
body: formData,
}
);
if (!response.ok) {
throw new Error("Failed to upload image to Cloudinary");
}
const data = await response.json();
const imageUrl = data.secure_url;

// Dispatch action to add post
dispatch(addPost({ caption, imageUrl }));

// Reset form
setCaption("");
setImage(null);
} catch (error) {
console.error("Error uploading image:", error);
}
}
};

const handleEditPost = () => {
// Placeholder logic for editing post
console.log("Edit Post");
};

const handleDeletePost = () => {
// Placeholder logic for deleting post
console.log("Delete Post");
};

return (
<div className="p-4 border rounded-md shadow-md bg-white">
<textarea
rows={4}
placeholder="Write a caption..."
className="w-full border border-gray-300 rounded-md p-2 mb-2"
value={caption}
onChange={(e) => setCaption(e.target.value)}
></textarea>
<div className="flex items-center mb-2">
<input
type="file"
accept="image/*"
id="image-upload"
className="hidden"
onChange={handleImageChange}
/>
<label htmlFor="image-upload">
<IconButton component="span">
<PhotoCameraIcon />
</IconButton>
</label>
{image && (
<img
src={URL.createObjectURL(image)}
alt="Uploaded"
className="w-20 h-20 object-cover rounded-md ml-2"
/>
)}
</div>
<div className="flex items-center justify-between">
<div>
<IconButton onClick={handlePostClick} disabled={!image || !caption}>
<ThumbUpIcon />
</IconButton>
<IconButton onClick={() => setOpenReplyModel(true)}>
<ChatIcon />
</IconButton>
</div>
<div>
<IconButton onClick={() => handleEditPost()}>
<EditIcon />
</IconButton>
<IconButton onClick={() => handleDeletePost()}>
<DeleteIcon />
</IconButton>
<Button
variant="contained"
onClick={handlePostClick}
disabled={!image || !caption}
>
Post
</Button>
</div>
</div>
<ReplyModel
open={openReplyModel}
handleClose={() => setOpenReplyModel(false)}
/>
</div>
);
};

export default NewPost;
Loading