-
Notifications
You must be signed in to change notification settings - Fork 98
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* fixed alignment issue * created blog functionality * fixes
- Loading branch information
1 parent
41df7c9
commit 66aaa88
Showing
9 changed files
with
378 additions
and
74 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import React, { createContext, useContext, useEffect, useState } from "react"; | ||
|
||
// Create the context with undefined as initial value | ||
const BlogContext = createContext(undefined); | ||
|
||
// BlogProvider to wrap components where Blog state is required | ||
export const BlogProvider = ({ children }) => { | ||
const [blogItems, setBlogItems] = useState([]); | ||
|
||
// Function to handle uploading a new blog | ||
useEffect(() => { | ||
if (!localStorage.getItem("blogs") === undefined) { | ||
const storedBlogs = localStorage.getItem("blogs"); | ||
if (storedBlogs) { | ||
setBlogItems(JSON.parse(storedBlogs)); | ||
} | ||
} | ||
}, []); | ||
|
||
const handleUpload = (title, author, content, image) => { | ||
// Create a new blog item object | ||
const newBlogItem = { | ||
// id: Date.now(), // You can replace this with a better ID system | ||
title, | ||
author, | ||
content, | ||
image, | ||
date: new Date().toLocaleDateString("en-US", { | ||
weekday: "long", | ||
year: "numeric", | ||
month: "long", | ||
day: "numeric", | ||
}), | ||
}; | ||
|
||
// Update the state with the new blog item | ||
setBlogItems((prevItems) => [ | ||
...prevItems, | ||
newBlogItem, | ||
]); | ||
|
||
console.log(blogItems) | ||
localStorage.setItem("blogs", JSON.stringify(blogItems)); | ||
}; | ||
|
||
// Function to remove an item from the Blog by its ID | ||
const handleRemove = (id) => { | ||
setBlogItems((prevItems) => prevItems.filter((item) => item.id !== id)); | ||
localStorage.setItem("blogs", JSON.stringify(updatedBlogs)); | ||
}; | ||
|
||
return ( | ||
<BlogContext.Provider value={{ blogItems, handleUpload, handleRemove }}> | ||
{children} | ||
</BlogContext.Provider> | ||
); | ||
}; | ||
|
||
// Custom hook to use the BlogContext in any component | ||
export const useBlog = () => { | ||
const context = useContext(BlogContext); | ||
if (!context) { | ||
throw new Error("useBlog must be used within a BlogProvider"); | ||
} | ||
return context; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
export default { | ||
plugins: { | ||
tailwindcss: {}, | ||
autoprefixer: {}, | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,20 @@ | ||
@tailwind base; | ||
@tailwind components; | ||
@tailwind utilities; | ||
|
||
|
||
*{ | ||
margin: 0; | ||
padding: 0; | ||
} | ||
|
||
body { | ||
overflow-x: hidden; | ||
} | ||
} | ||
|
||
@font-face { | ||
font-family: 'Future2'; | ||
src: url('/fonts/Future2.ttf') format('truetype'); /* Adjust path if needed */ | ||
font-weight: normal; | ||
font-style: normal; | ||
} |
Oops, something went wrong.