Skip to content

Commit 9add911

Browse files
everything is functional
1 parent 803bdf4 commit 9add911

File tree

5 files changed

+13
-5
lines changed

5 files changed

+13
-5
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,6 @@ Currently, two official plugins are available:
66

77
- [@vitejs/plugin-react](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react/README.md) uses [Babel](https://babeljs.io/) for Fast Refresh
88
- [@vitejs/plugin-react-swc](https://github.com/vitejs/vite-plugin-react-swc) uses [SWC](https://swc.rs/) for Fast Refresh
9+
10+
# Note
11+
- It takes some time for redux to hydrate the state so please wait for some time before creating a new post

src/components/PostCard.jsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ function PostCard({$id, title, featuredImage}) { //$id - special syntax of aappw
77
<Link to={`/post/${$id}`}>
88
<div className='w-full bg-gray-100 rounded-xl p-4'>
99
<div className='w-full justify-center mb-4'>
10-
<img src={appwriteService.getFilePreview(featuredImage)}
11-
alt={title} className='rounded-xl'/>
10+
<img className="rounded-xl" src={appwriteService.getFilePreview(featuredImage)}
11+
alt={title}/>
1212
</div>
1313
</div>
1414
<h2 className='text-xl font-bold'>

src/components/post-form/PostForm.jsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,14 @@ import { useSelector } from 'react-redux'
77

88
export default function PostForm({post}) {
99
const userData = useSelector((state) => state.auth.userData)
10+
console.log(userData)
1011
const {register, handleSubmit, watch, setValue, control, getValues} = useForm({
1112
defaultValues:{
1213
title: post?.title || "",
1314
slug : post?.$id || "",
1415
content : post?.content || "",
1516
status : post?.status || "active",
16-
userId: userData?.$id || ""
17+
// userId: userData?.$id || ""
1718
},
1819
})
1920

@@ -24,14 +25,17 @@ export default function PostForm({post}) {
2425
const file = data.image[0] ? await appwriteService.uploadFile(data.image[0]) : null
2526
if(file){
2627
appwriteService.deleteFile(post.featuredImage)
28+
console.log("file created")
2729
}
2830
const dbPost = await appwriteService.updatePost(
2931
post.$id, {
3032
...data,
3133
featuredImage: file ? file.$id : undefined,
3234
}
3335
)
36+
console.log("post updated")
3437
if(dbPost) {
38+
console.log("navigating to post")
3539
navigate(`/post/${dbPost.$id}`)
3640
}
3741
}else {
@@ -42,7 +46,7 @@ export default function PostForm({post}) {
4246
data.featuredImage = fileId
4347
const dbPost = await appwriteService.createPost({
4448
...data,
45-
usedId : userData.$id,
49+
userId :userData.$id,
4650
})
4751
if(dbPost){
4852
navigate(`/post/${dbPost.$id}`)

src/pages/Post.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ export default function Post() {
3838
<div className="w-full flex justify-center mb-4 relative border rounded-xl p-2">
3939
<img
4040
src={appwriteService.getFilePreview(post.featuredImage)}
41-
alt={post.title}
4241
className="rounded-xl"
42+
alt={post.title}
4343
/>
4444

4545
{isAuthor && (

src/store/authSlice.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ const authSlice = createSlice({
1313
login: (state, action) => {
1414
state.status = true;
1515
state.userData = action.payload.userData;
16+
// state.userData = action.payload;
1617
},
1718
logout:(state) => {
1819
state.status = false;

0 commit comments

Comments
 (0)