-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
32 changed files
with
2,207 additions
and
21 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,38 @@ | ||
import { useState } from 'react' | ||
import reactLogo from './assets/react.svg' | ||
import viteLogo from '/vite.svg' | ||
import React, { useState, useEffect } from 'react' | ||
import { useDispatch } from 'react-redux' | ||
import './App.css' | ||
import authService from "./appwrite/auth" | ||
import {login, logout} from "./store/authSlice" | ||
import { Footer, Header } from './components' | ||
import { Outlet } from 'react-router-dom' | ||
|
||
function App() { | ||
const [count, setCount] = useState(0) | ||
console.log(import.meta.env.VITE_APPWRITE_URL); | ||
return ( | ||
<> | ||
<h1>Blog with appwrite</h1> | ||
</> | ||
) | ||
const [loading, setLoading] = useState(true) | ||
const dispatch = useDispatch() | ||
|
||
useEffect(() => { | ||
authService.getCurrentUser() | ||
.then((userData) => { | ||
if (userData) { | ||
dispatch(login({userData})) | ||
} else { | ||
dispatch(logout()) | ||
} | ||
}) | ||
.finally(() => setLoading(false)) | ||
}, []) | ||
|
||
return !loading ? ( | ||
<div className='min-h-screen flex flex-wrap content-between bg-gray-400'> | ||
<div className='w-full block'> | ||
<Header /> | ||
<main> | ||
<Outlet/> | ||
</main> | ||
<Footer /> | ||
</div> | ||
</div> | ||
) : null | ||
} | ||
|
||
export default App | ||
export default App |
Empty file.
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,24 @@ | ||
import React ,{useEffect} from 'react' | ||
import {useSelector} from 'react-redux' | ||
import {useNavigate} from 'react-router-dom' | ||
|
||
export default function Protected({children, authentication}) | ||
{ | ||
const navigate =useNavigate() | ||
const [loader, setLoader] =useState(true) | ||
const authStatus=useSelector(state=> state.auth.status) | ||
|
||
useEffect(() =>{ | ||
if(authentication && authStatus!==authentication ) | ||
{ | ||
navigate("/login") | ||
} | ||
else if(!authentication && authStatus !== authentication) | ||
{ | ||
navigate("/") | ||
} | ||
setLoader(false) | ||
},[authStatus, navigate,authentication]) | ||
|
||
return loader ? <h1>Loading...</h1> : <>{children}</> | ||
} |
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,16 @@ | ||
import React from "react"; | ||
|
||
export default function Button({ | ||
children, | ||
type = "button", | ||
bgColor = "bg-blue-600", | ||
textColor = "text-white", | ||
className = "", | ||
...props | ||
}) { | ||
return ( | ||
<button className={`px-4 py-2 rounded-lg ${bgColor} ${textColor} ${className}`} {...props}> | ||
{children} | ||
</button> | ||
); | ||
} |
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,143 @@ | ||
import React from 'react' | ||
import { Link } from 'react-router-dom' | ||
import Logo from '../Logo' | ||
|
||
function Footer() { | ||
return ( | ||
<section className="relative overflow-hidden py-10 bg-gray-400 border border-t-2 border-t-black"> | ||
<div className="relative z-10 mx-auto max-w-7xl px-4"> | ||
<div className="-m-6 flex flex-wrap"> | ||
<div className="w-full p-6 md:w-1/2 lg:w-5/12"> | ||
<div className="flex h-full flex-col justify-between"> | ||
<div className="mb-4 inline-flex items-center"> | ||
<Logo width="100px" /> | ||
</div> | ||
<div> | ||
<p className="text-sm text-gray-600"> | ||
© Copyright 2023. All Rights Reserved by DevUI. | ||
</p> | ||
</div> | ||
</div> | ||
</div> | ||
<div className="w-full p-6 md:w-1/2 lg:w-2/12"> | ||
<div className="h-full"> | ||
<h3 className="tracking-px mb-9 text-xs font-semibold uppercase text-gray-500"> | ||
Company | ||
</h3> | ||
<ul> | ||
<li className="mb-4"> | ||
<Link | ||
className=" text-base font-medium text-gray-900 hover:text-gray-700" | ||
to="/" | ||
> | ||
Features | ||
</Link> | ||
</li> | ||
<li className="mb-4"> | ||
<Link | ||
className=" text-base font-medium text-gray-900 hover:text-gray-700" | ||
to="/" | ||
> | ||
Pricing | ||
</Link> | ||
</li> | ||
<li className="mb-4"> | ||
<Link | ||
className=" text-base font-medium text-gray-900 hover:text-gray-700" | ||
to="/" | ||
> | ||
Affiliate Program | ||
</Link> | ||
</li> | ||
<li> | ||
<Link | ||
className=" text-base font-medium text-gray-900 hover:text-gray-700" | ||
to="/" | ||
> | ||
Press Kit | ||
</Link> | ||
</li> | ||
</ul> | ||
</div> | ||
</div> | ||
<div className="w-full p-6 md:w-1/2 lg:w-2/12"> | ||
<div className="h-full"> | ||
<h3 className="tracking-px mb-9 text-xs font-semibold uppercase text-gray-500"> | ||
Support | ||
</h3> | ||
<ul> | ||
<li className="mb-4"> | ||
<Link | ||
className=" text-base font-medium text-gray-900 hover:text-gray-700" | ||
to="/" | ||
> | ||
Account | ||
</Link> | ||
</li> | ||
<li className="mb-4"> | ||
<Link | ||
className=" text-base font-medium text-gray-900 hover:text-gray-700" | ||
to="/" | ||
> | ||
Help | ||
</Link> | ||
</li> | ||
<li className="mb-4"> | ||
<Link | ||
className=" text-base font-medium text-gray-900 hover:text-gray-700" | ||
to="/" | ||
> | ||
Contact Us | ||
</Link> | ||
</li> | ||
<li> | ||
<Link | ||
className=" text-base font-medium text-gray-900 hover:text-gray-700" | ||
to="/" | ||
> | ||
Customer Support | ||
</Link> | ||
</li> | ||
</ul> | ||
</div> | ||
</div> | ||
<div className="w-full p-6 md:w-1/2 lg:w-3/12"> | ||
<div className="h-full"> | ||
<h3 className="tracking-px mb-9 text-xs font-semibold uppercase text-gray-500"> | ||
Legals | ||
</h3> | ||
<ul> | ||
<li className="mb-4"> | ||
<Link | ||
className=" text-base font-medium text-gray-900 hover:text-gray-700" | ||
to="/" | ||
> | ||
Terms & Conditions | ||
</Link> | ||
</li> | ||
<li className="mb-4"> | ||
<Link | ||
className=" text-base font-medium text-gray-900 hover:text-gray-700" | ||
to="/" | ||
> | ||
Privacy Policy | ||
</Link> | ||
</li> | ||
<li> | ||
<Link | ||
className=" text-base font-medium text-gray-900 hover:text-gray-700" | ||
to="/" | ||
> | ||
Licensing | ||
</Link> | ||
</li> | ||
</ul> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
</section> | ||
) | ||
} | ||
|
||
export default Footer |
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,73 @@ | ||
import React from 'react' | ||
import {Container, Logo, LogoutBtn} from '../index' | ||
import { Link } from 'react-router-dom' | ||
import {useSelector} from 'react-redux' | ||
import { useNavigate } from 'react-router-dom' | ||
|
||
function Header() { | ||
const authStatus = useSelector((state) => state.auth.status) | ||
const navigate = useNavigate() | ||
|
||
const navItems = [ | ||
{ | ||
name: 'Home', | ||
slug: "/", | ||
active: true | ||
}, | ||
{ | ||
name: "Login", | ||
slug: "/login", | ||
active: !authStatus, | ||
}, | ||
{ | ||
name: "Signup", | ||
slug: "/signup", | ||
active: !authStatus, | ||
}, | ||
{ | ||
name: "All Posts", | ||
slug: "/all-posts", | ||
active: authStatus, | ||
}, | ||
{ | ||
name: "Add Post", | ||
slug: "/add-post", | ||
active: authStatus, | ||
}, | ||
] | ||
|
||
|
||
return ( | ||
<header className='py-3 shadow bg-gray-500'> | ||
<Container> | ||
<nav className='flex'> | ||
<div className='mr-4'> | ||
<Link to='/'> | ||
<Logo width='70px' /> | ||
|
||
</Link> | ||
</div> | ||
<ul className='flex ml-auto'> | ||
{navItems.map((item) => | ||
item.active ? ( | ||
<li key={item.name}> | ||
<button | ||
onClick={() => navigate(item.slug)} | ||
className='inline-bock px-6 py-2 duration-200 hover:bg-blue-100 rounded-full' | ||
>{item.name}</button> | ||
</li> | ||
) : null | ||
)} | ||
{authStatus && ( | ||
<li> | ||
<LogoutBtn /> | ||
</li> | ||
)} | ||
</ul> | ||
</nav> | ||
</Container> | ||
</header> | ||
) | ||
} | ||
|
||
export default Header |
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,21 @@ | ||
import React from 'react' | ||
import {useDispatch} from 'react-redux' | ||
import authService from '../../appwrite/auth' | ||
import {logout} from '../../store/authSlice' | ||
|
||
function LogoutBtn() { | ||
const dispatch = useDispatch() | ||
const logoutHandler = () => { | ||
authService.logout().then(() => { | ||
dispatch(logout()) | ||
}) | ||
} | ||
return ( | ||
<button | ||
className='inline-bock px-6 py-2 duration-200 hover:bg-blue-100 rounded-full' | ||
onClick={logoutHandler} | ||
>Logout</button> | ||
) | ||
} | ||
|
||
export default LogoutBtn |
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,29 @@ | ||
import React, {useId} from 'react' | ||
|
||
const Input = React.forwardRef( function Input({ | ||
label, | ||
type = "text", | ||
className = "", | ||
...props | ||
}, ref){ | ||
const id = useId() | ||
return ( | ||
<div className='w-full'> | ||
{label && <label | ||
className='inline-block mb-1 pl-1' | ||
htmlFor={id}> | ||
{label} | ||
</label> | ||
} | ||
<input | ||
type={type} | ||
className={`px-3 py-2 rounded-lg bg-white text-black outline-none focus:bg-gray-50 duration-200 border border-gray-200 w-full ${className}`} | ||
ref={ref} | ||
{...props} | ||
id={id} | ||
/> | ||
</div> | ||
) | ||
}) | ||
|
||
export default Input |
Oops, something went wrong.