diff --git a/src/appwrite/config.js b/src/appwrite/config.js
index 4f7a52a..12c4dc7 100644
--- a/src/appwrite/config.js
+++ b/src/appwrite/config.js
@@ -1,65 +1,63 @@
import confg from "../conf/conf";
-import { Client , ID , Databases , Query , Storage } from 'appwrite'
+import { Client, ID, Databases, Query, Storage } from 'appwrite'
-export class Service{
+export class Service {
client = new Client();
databases;
Storage;
- constructor(){
+ constructor() {
this.client
- .setEndpoint(confg.appwriteUrl)
- .setProject(confg.appwriteProjectId)
+ .setEndpoint(confg.appwriteUrl)
+ .setProject(confg.appwriteProjectId)
this.Storage = new Storage(this.client)
this.databases = new Databases(this.client)
}
- async createPost({title , slug , content , featuredImage, status, userId}){
+ async createPost({ title, slug, content, featuredImage, status, userId }) {
try {
return await this.databases.createDocument(
confg.appwriteDatabaseId,
confg.appwriteCollectionId,
- ID, // documentId
+ ID.unique(), // documentId
{
- title,
- slug,
- content,
- featuredImage,
- status,
- userId
- }
- );
+ title,
+ slug,
+ content,
+ featuredImage,
+ status,
+ userId
+ }
+ );
} catch (error) {
console.log(`Error creating post : ${error}`);
}
}
-
- async updatePost(ID,{title , slug , content , featuredImage, status,userId}){
+
+ async updatePost(Id, { title, slug, content, featuredImage, status, userId }) {
try {
return await this.databases.updateDocument(
confg.appwriteDatabaseId,
confg.appwriteCollectionId,
- ID,
+ Id,
{
- title,
- slug,
- content,
- featuredImage,
- status,
- userId
- }
+ title,
+ content,
+ featuredImage,
+ status,
+ }
)
} catch (error) {
console.log(`Error updating post : ${error}`);
}
}
- async deletePost(ID){
+ async deletePost(Id) {
try {
await this.databases.deleteDocument(
confg.appwriteDatabaseId,
confg.appwriteCollectionId,
- ID,
+ Id,
)
return true;
} catch (error) {
@@ -68,12 +66,12 @@ export class Service{
}
}
- async getPost(ID){
+ async getPost(Id) {
try {
return await this.databases.getDocument(
confg.appwriteDatabaseId,
confg.appwriteCollectionId,
- ID
+ Id,
)
} catch (error) {
console.log(`Error getting post : ${error}`);
@@ -81,7 +79,7 @@ export class Service{
}
}
- async getAllPost(queries = [Query.equal("status","active")]){
+ async getAllPost(queries = [Query.equal("status", "active")]) {
try {
return await this.databases.listDocuments(
confg.appwriteDatabaseId,
@@ -97,7 +95,7 @@ export class Service{
// file upload service
- async uploadFile(file){
+ async uploadFile(file) {
try {
return await this.Storage.createFile(
confg.appwriteBucketId,
@@ -109,7 +107,7 @@ export class Service{
}
}
- async removeFile(fileId){
+ async removeFile(fileId) {
try {
await this.Storage.deleteFile(
confg.appwriteBucketId,
@@ -122,7 +120,7 @@ export class Service{
}
}
- async getFilePreview(fileId){
+ async getFilePreview(fileId) {
try {
return await this.Storage.getFilePreview(
confg.appwriteBucketId,
diff --git a/src/components/AuthLayout.jsx b/src/components/AuthLayout.jsx
index 7d68d04..8b7933a 100644
--- a/src/components/AuthLayout.jsx
+++ b/src/components/AuthLayout.jsx
@@ -21,14 +21,15 @@ const Protected = ({children,authentication = true}) => {
}else{
setLoading(false)
}
- },[authStatus,navigate,authentication])
+ setLoading(false);
+ },[authStatus, navigate, authentication]);
if(authStatus === null || loading){
return
Loading...
}
return (
- <>{children}>
+ loading ? Loading...
: {children}
)
}
diff --git a/src/components/Header/Header.jsx b/src/components/Header/Header.jsx
index 905a889..8894b98 100644
--- a/src/components/Header/Header.jsx
+++ b/src/components/Header/Header.jsx
@@ -7,7 +7,7 @@ import { useNavigate } from 'react-router-dom'
const Header = () => {
- const authStatus = useSelector((state)=> state.auth.Status)
+ const authStatus = useSelector((state)=> state.auth.status)
const navigate = useNavigate()
diff --git a/src/components/Header/LogoutBtn.jsx b/src/components/Header/LogoutBtn.jsx
index 444c6e4..df382b7 100644
--- a/src/components/Header/LogoutBtn.jsx
+++ b/src/components/Header/LogoutBtn.jsx
@@ -1,7 +1,7 @@
import React from 'react'
import { useDispatch } from 'react-redux'
-import authService from "../../appwrite/auth.js"
-import logout from "../../store/authSlice.js"
+import authService from "../../appwrite/auth"
+import {logout} from "../../store/authSlice"
import { useNavigate } from 'react-router-dom'
const LogoutBtn = () => {
@@ -9,13 +9,13 @@ const LogoutBtn = () => {
const navigate = useNavigate()
const logOutHandler = () => {
authService.logout().then(()=>{
- dispatch(logout()) // to update the state
+ dispatch(logout()); // to update the state
})
navigate('/login')
}
return (
-