Skip to content

Commit ce5126c

Browse files
Enhance logging, improve component styling, and refactor imports across multiple files
1 parent 6c8b7c7 commit ce5126c

File tree

9 files changed

+25
-23
lines changed

9 files changed

+25
-23
lines changed

src/appwrite/config.service.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ export class Service{
1616

1717
async createPost({title, slug, content, featuredImage, status, userId}){
1818
try {
19+
console.log("createPost parameters:", {title, slug, content, featuredImage, status, userId});
1920
return await this.databases.createDocument(
2021
conf.appwriteDatabaseId,
2122
conf.appwriteCollectionId,

src/components/Login.jsx

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React ,{useState} from 'react'
2-
import {Link, useNavigate} from 'react-router-dom'
3-
import {login as authLoginStore} from '../store/authSlice.js'
2+
import {Link, useNavigate} from 'react-router-dom';
3+
import {login as authLogin} from '../store/authSlice.js'
44
import {Button, Input, Logo} from './index.js'
55
import { useDispatch } from 'react-redux'
66
import authService from '../appwrite/auth.service'
@@ -18,10 +18,11 @@ function Login() {
1818
const session = await authService.login(data)
1919
if(session){
2020
const userData = await authService.getCurrentUser()
21+
console.log("Can go to home but not going")
2122
if(userData){
22-
dispatch(authLoginStore(userData))
23-
navigate("/")
23+
dispatch(authLogin(userData));
2424
}
25+
navigate("/");
2526
}
2627
} catch (error) {
2728
setError(error.message)
@@ -59,7 +60,7 @@ function Login() {
5960
{...register("email", {
6061
required: true,
6162
validate: {
62-
matchPattern :(value) => /^\w+([.-]?\w+)*@\w+([.-]?\w+)*(\.\w{2,3})+$/.test(value) ||
63+
matchPattern :(value) => /^\w+([.-]?\w+)*@\w+([.-]?\w+)*(\.\w{2,3})+$/.test(value) ||
6364
"Email address must be a valid address",
6465
}
6566
})}

src/components/PostCard.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ function PostCard({$id, title, featuredImage}) { //$id - special syntax of aappw
1111
alt={title} className='rounded-xl'/>
1212
</div>
1313
</div>
14-
<h2 className='text-xl'>
14+
<h2 className='text-xl font-bold'>
1515
{title}</h2>
1616
</Link>
1717
)

src/components/Select.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import React , {useId} from 'react'
33
function Select({
44
options,
55
label,
6-
className = "",
6+
className,
77
...props
88
}, ref) {
99
const id = useId();

src/components/SignUp.jsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,11 @@ function SignUp() {
2727
}
2828

2929
return (
30-
<div className="flex items-center justify-center">
30+
<div className="flex items-center justify-center pt-5 pb-5">
3131
<div className={`mx-auto w-full max-w-lg bg-gray-100 rounded-xl p-10 border border-black/10`}>
3232
<div className="mb-2 flex justify-center">
3333
<span className="inline-block w-full max-w-[100px]">
34-
<Logo width='100%'/>
34+
<Logo width='50px'/>
3535
</span>
3636
</div>
3737
<h2 className="text-center text-2xl font-bold leading-tight">Sign Up to create account</h2>

src/components/post-form/PostForm.jsx

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,11 @@ import { useSelector } from 'react-redux'
88
export default function PostForm({post}) {
99
const {register, handleSubmit, watch, setValue, control, getValues} = useForm({
1010
defaultValues:{
11-
title: post?.title || '',
12-
slug : post?.slug || '',
13-
content : post?.content || '',
11+
title: post?.title || "",
12+
slug : post?.$id || "",
13+
content : post?.content || "",
1414
status : post?.status || "active",
15+
userId: post?.$id || ""
1516
},
1617
})
1718

@@ -71,7 +72,7 @@ export default function PostForm({post}) {
7172
//to optimise useEffect
7273
subscription.unsubscribe()
7374
}
74-
}, [watch, slugTransform, setValue])
75+
}, [watch, slugTransform, setValue])
7576
return (
7677
<form onSubmit={handleSubmit(submit)} className="flex flex-wrap">
7778
<div className="w-2/3 px-2">

src/main.jsx

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@ import App from './App.jsx'
77
import { Provider } from 'react-redux'
88
import store from './store/store.js'
99
import { createBrowserRouter, RouterProvider } from 'react-router-dom'
10-
import AuthLayout from './components/AuthLayout.jsx'
11-
import Login from './components/Login.jsx'
10+
import { AuthLayout, Login } from './components/index.js'
1211
import Home from './pages/Home.jsx'
1312
import Allposts from './pages/Allposts.jsx'
1413
import Addpost from './pages/Addpost.jsx'
@@ -72,8 +71,8 @@ const router = createBrowserRouter([
7271
path: "/post/:slug",
7372
element: <Post />,
7473
},
75-
]
76-
}
74+
],
75+
},
7776
])
7877

7978
ReactDOM.createRoot(document.getElementById('root')).render(

src/pages/Editpost.jsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
import React ,{useEffect, useState}from 'react'
22
import { Container, PostForm } from '../components'
3-
import service from '../appwrite/config.service'
3+
import appwriteService from '../appwrite/config.service'
44
import { useNavigate, useParams } from 'react-router-dom'
55

66
function Editpost() {
77
const [post, setPost] = useState(null)
88
const {slug} = useParams()
9-
const navigate = useNavigate
9+
const navigate = useNavigate()
1010

11-
useEffect((slug) => {
11+
useEffect(() => {
1212
if(slug){
13-
service.getPosts(slug).then((post) => {
13+
appwriteService.getPost(slug).then((post) => {
1414
if(post){
1515
setPost(post)
1616
}
@@ -22,7 +22,7 @@ function Editpost() {
2222
return post ? (
2323
<div>
2424
<Container>
25-
<PostForm post = {post}/>
25+
<PostForm post={post}/>
2626
</Container>
2727
</div>
2828
) : null

src/pages/Home.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ function Home() {
1515
<div className="w-full py-8 mt-4 text-center">
1616
<Container>
1717
<div className="flex flex-wrap">
18-
<div className="p-2 w-full">
18+
<div className="p-2 w-full h-full">
1919
<h1 className="text-2xl font-bold hover:text-gray-500">
2020
Login to read posts
2121
</h1>

0 commit comments

Comments
 (0)