Skip to content

Commit

Permalink
ADD:zustand
Browse files Browse the repository at this point in the history
  • Loading branch information
ismail-kharrobi committed Sep 18, 2023
1 parent 3a80356 commit 3a68513
Show file tree
Hide file tree
Showing 9 changed files with 144 additions and 107 deletions.
2 changes: 1 addition & 1 deletion frontend/code/src/Components/Layout/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export const Layout : FC<PropsWithChildren> = () : JSX.Element =>
{
const user = useUserStore();

useEffect(() => {user.auth.login();},[])
useEffect(() => {user.auth.login();},[user.auth])
const path : string = useCurrentPath()
const obj = {x:"30",y:"20"}
return (
Expand Down
5 changes: 5 additions & 0 deletions frontend/code/src/Components/Profile/assets/svg/threedots.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
33 changes: 21 additions & 12 deletions frontend/code/src/Components/Profile/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import Master from '../Badges/Master.svg'
import Ultimate from '../Badges/Ultimate.svg'
import { Edit } from './assets/Edit'
import { useUserStore } from '../../Stores/stores'

import dots from './assets/svg/threedots.svg'
export const Profile = () =>{
const user = useUserStore();
const params = useParams()
Expand Down Expand Up @@ -53,29 +53,38 @@ export const Profile = () =>{
</div>
</div>
</div>
<div className='relative flex flex-col gap-y-2 sm:gap-y-0 pl-4 sm:pt-12 pt-6 text-neutral font-montserrat bg-base-200 justify-start items-start h-[15%] xl:h-[30%] xl:min-h-[30%] min-h-[25%] rounded-b-3xl w-[85vw] overflow-scroll no-scrollbar'>
<div className='relative flex flex-col gap-y-4 sm:gap-y-0 pl-4 text-neutral font-montserrat bg-base-200 justify-start items-start h-[15%] xl:h-[30%] xl:min-h-[27%] min-h-[25%] rounded-b-3xl w-[85vw] overflow-scroll no-scrollbar'>
{
users?.name?.first ? <h6>{users?.name?.first} </h6>: <Load/>
users?.name?.first ? <h6 className='sm:pt-12 pt-6 font-poppins font-bold text-xl'>{users?.name?.first} {users.name.last} </h6>: <Load/>
} <div className="flex justify-center items-center gap-x-2">
<File/>
<span className='text-xs font-mono '>bio bla bla bla</span>
<span className='text-sm pt-4 font-mono '>{user.bio}</span>
</div>
<div className=" w-full flex flex-col sm:flex-row sm:flex-wrap sm:justify-between items-center gap-x-4 h-2/6">
<div className="flex flex-col gap-y-2 flex-0 sm:flex-row sm:gap-x-4 justify-center items-center sm:justify-start sm:items-start sm:w-[25vw]">
{params.id !== "me" ?
<div className=" w-full h-full flex flex-col sm:flex-row sm:flex-wrap sm:justify-between gap-x-4">
<div className="flex flex-col gap-y-0 items-center h-full sm:flex-row sm:gap-x-4 justify-center sm:justify-start sm:items-end pb-4 sm:w-[25vw]">
{
params.id !== "me" ?
(<><Message/>
<Share/></>)
:
(
<Link to={"/Settings"}><Edit/></Link>
)

}
</div>
<div className="flex flex-row gap-x-4 justify-center items-center w-72 sm:w-auto sm:pr-4 sm:pt-0 pt-4">
<img className={`h-[9vh] sm:h-[11vh] md:h-[12vh] lg:h-[13vh] xl:h-[14vh] 2xl:h-[15vh] `} src={Newbie} alt="newbie badge" />
<img className={`h-[9vh] sm:h-[11vh] md:h-[12vh] lg:h-[13vh] xl:h-[14vh] 2xl:h-[15vh] opacity-30`} src={Master} alt="Master badge" />
<img className={`h-[9vh] sm:h-[11vh] md:h-[12vh] lg:h-[13vh] xl:h-[14vh] 2xl:h-[15vh] `} src={Ultimate} alt="Ultimate badge" />
<div className="flex h-full w-full flex-row gap-x-4 justify-center sm:justify-start items-center sm:w-auto sm:pr-4 sm:pt-0 pt-4 ">
<img className={`h-[9vh] sm:h-[11vh] md:h-[12vh] lg:h-[13vh] xl:h-[15vh] 2xl:h-[16vh] `} src={Newbie} alt="newbie badge" />
<img className={`h-[9vh] sm:h-[11vh] md:h-[12vh] lg:h-[13vh] xl:h-[15vh] 2xl:h-[16vh] opacity-30`} src={Master} alt="Master badge" />
<img className={`h-[9vh] sm:h-[11vh] md:h-[12vh] lg:h-[13vh] xl:h-[15vh] 2xl:h-[16vh] `} src={Ultimate} alt="Ultimate badge" />
<div className="flex h-full items-start cursor-pointer dropdown dropdown-end">
<label tabIndex={0} className="btn m-1">
<img src={dots} alt="three dots" />
</label>
<ul tabIndex={0} className="relative top-14 dropdown-content z-[1] menu p-2 shadow bg-base-200 rounded-box w-52">
<li className='hover:bg-primary hover:rounded-xl transform duration-500'><div>Block</div></li>
<li className='hover:bg-primary hover:rounded-xl transform duration-500'><div>Send friend request</div></li>
</ul>
</div>
</div>
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion frontend/code/src/Components/Settings/assets/Avatar.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
export const Avatar = (props:any) => {
return (
<div className="avatar">
<div className="w-16 sm:w-24 rounded-full">
<div className="w-16 sm:w-24 xl:w-32 rounded-full">
<img src={props.picture} alt="avatar" />
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion frontend/code/src/Components/Settings/assets/Inputs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ interface MyComponentProps {

export const Inputs = (props:MyComponentProps) => {
const user = useUserStore();
const { register, handleSubmit, reset , formState: { errors } } = useForm();
const { register, handleSubmit, reset } = useForm();
const onSubmit = (data : any)=> {
toast.promise(

Expand Down
202 changes: 112 additions & 90 deletions frontend/code/src/Components/Settings/index.tsx
Original file line number Diff line number Diff line change
@@ -1,93 +1,115 @@
import { Avatar } from './assets/Avatar'
import { Edit } from './assets/Edit'
import Newbie from '../Badges/Newbie.svg'
import Master from '../Badges/Master.svg'
import Ultimate from '../Badges/Ultimate.svg'
import { api as axsios }from '../../Api/base'
import toast from 'react-hot-toast'
import { useState , useEffect} from 'react'
import { Inputs } from './assets/Inputs'
import { useUserStore } from '../../Stores/stores'
export const Setting = () => {
const getdata :any = async() => {
const data:any = await axsios.get("/test")
return data
}

const user = useUserStore();
const [myuser, setMyuser] = useState(user);
const data_names = ["First name","Last name","Email","Phone","Bio"]
const data_content = [user.name.first,user.name.last, user.email,user.phone,user.bio]
import { Avatar } from "./assets/Avatar";
import { Edit } from "./assets/Edit";
import Newbie from "../Badges/Newbie.svg";
import Master from "../Badges/Master.svg";
import Ultimate from "../Badges/Ultimate.svg";
import { api as axsios } from "../../Api/base";
import toast from "react-hot-toast";
import { useState, useEffect } from "react";
import { Inputs } from "./assets/Inputs";
import { useUserStore } from "../../Stores/stores";
export const Setting = () => {
const getdata: any = async () => {
const data: any = await axsios.get("/test");
return data;
};

useEffect(()=>{
setMyuser(user)
},[myuser, user])
const user = useUserStore();
const [myuser, setMyuser] = useState(user);
const data_names = ["First name", "Last name", "Email", "Phone", "Bio"];
const data_content = [
user.name.first,
user.name.last,
user.email,
user.phone,
user.bio,
];


return (
<>
<div className="flex h-[90vh] w-full font-poppins font-medium">
<h1 className='pt-6 pl-6 font-poppins font-medium text-xl text-neutral'>Profile Settings</h1>
<div className=" h-[82%] w-[90%] flex flex-col absolute bottom-0 right-0 bg-base-200 rounded-tl-2xl">
<h2 className='pt-4 pl-4 text-neutral '>change preview</h2>
<div className="flex justify-center h-full w-full pt-8">
<div className="flex flex-col sm:flex-row items-center gap-4 sm:justify-between justify-center overflow-scroll no-scrollbar w-[90%] max-h-[25vh] bg-base-100 border-solid border-gray-400 border-2 rounded-3xl">
<div className='flex justify-between items-center gap-x-10 px-2 sm:px-0'>
<div className='relative sm:pl-10 pt-6 sm:pt-0'><Avatar picture={myuser.picture.medium}/>
<div className="absolute bottom-0 right-0">
<Edit/>
</div>
</div>
<div className='flex flex-col items-stretch justify-evenly gap-y-4'>
<div className='text-neutral break-words break-all font-poppins font-medium text-sm sm:text-xl'> {myuser.name.first} {myuser.name.last} </div>
<div className='font-poppins font-medium text-sm sm:text-lg'> {user.bio}</div>
</div>
</div>
<div className="flex pr-6 items-center justify-center gap-x-2">

<div onClick={()=> {toast.promise(

getdata(),
{

loading: 'Saving...',
success: <b>fetched</b>,
error: <b>could not fetch</b>,
}
);}}>
</div>
<img className={`h-[9vh] md:h-[12vh] `} src={Newbie} alt="newbie badge" />
<img className={`h-[9vh] md:h-[12vh] opacity-30`} src={Master} alt="Master badge" />
<img className={`h-[9vh] md:h-[12vh] `} src={Ultimate} alt="Ultimate badge" />
</div>
</div>
</div>

<h2 className='pt-4 pl-4 text-neutral'>change preview</h2>
<div className="flex justify-center h-full w-full pt-8">
<div className="flex flex-col sm:flex-row justify-between w-[90%] h-[50vh] sm:max-h-[50vh] max-h-[40vh] bg-base-100 border-solid border-gray-400 border-2 rounded-3xl">
<div className='gap-4 p-6 flex-wrap shrink grid grid-cols-2 justify-between w-full h-56'>
{
data_names.map((x, index) => {
return (
<Inputs key={index} name={x} data={data_content[index]} />
)
})

}
<div className="flex flex-col gap-y-4">
<h4 className='font-mono font-bold text-neutral '>How to Enable two factor Auth</h4>
<div className="flex gap-x-6">
<div className='flex justify-center h-28 w-28 rounded-2xl border-2 border-violet-600'></div>
<div className='flex justify-center h-28 w-28 rounded-2xl border-2 border-violet-600'></div>
<div className='flex justify-center h-28 w-28 rounded-2xl border-2 border-violet-600'></div>
</div>
</div>
</div>
</div>
</div>
useEffect(() => {
setMyuser(user);
}, [myuser, user]);

return (
<>
<div className="flex h-[90vh] w-full font-poppins font-medium">
<h1 className="pt-6 pl-6 font-poppins font-medium text-xl text-neutral">
Profile Settings
</h1>
<div className=" h-[82%] w-[90%] flex flex-col absolute bottom-0 right-0 bg-base-200 rounded-tl-2xl">
<h2 className="pt-4 pl-4 text-neutral ">change preview</h2>
<div className="flex justify-center h-full w-full pt-8">
<div className="flex flex-col sm:flex-row items-center gap-4 sm:justify-between justify-center overflow-scroll no-scrollbar w-[90%] max-h-[30vh] h-[20vh] bg-base-100 border-solid border-gray-400 border-2 rounded-3xl">
<div className="flex justify-between items-center gap-x-10 px-2 sm:px-0">
<div className="relative sm:pl-10 pt-6 sm:pt-0">
<Avatar picture={myuser.picture.medium} />
<div className="absolute bottom-0 right-0">
<Edit />
</div>
</div>
<div className="flex flex-col items-stretch justify-evenly gap-y-4">
<div className="text-neutral break-words break-all font-poppins font-medium text-sm sm:text-xl">
{" "}
{myuser.name.first} {myuser.name.last}{" "}
</div>
<div className="font-poppins font-medium text-sm sm:text-lg">
{" "}
{user.bio}
</div>
</div>
</div>
<div className="flex pr-6 items-center justify-center gap-x-2 xl:gap-x-8">
<div
onClick={() => {
toast.promise(getdata(), {
loading: "Saving...",
success: <b>fetched</b>,
error: <b>could not fetch</b>,
});
}}
></div>
<img
className={`h-[9vh] md:h-[12vh] xl:h-[14vh] `}
src={Newbie}
alt="newbie badge"
/>
<img
className={`h-[9vh] md:h-[12vh] xl:h-[14vh] opacity-30`}
src={Master}
alt="Master badge"
/>
<img
className={`h-[9vh] md:h-[12vh] xl:h-[14vh] `}
src={Ultimate}
alt="Ultimate badge"
/>
</div>
</div>
</div>

<h2 className="pt-4 pl-4 text-neutral">change preview</h2>
<div className="flex justify-center h-full w-full pt-8">
<div className="flex flex-col sm:flex-row justify-between w-[90%] h-[50vh] sm:max-h-[50vh] max-h-[40vh] bg-base-100 border-solid border-gray-400 border-2 rounded-3xl">
<div className="overflow-scroll no-scrollbar h-full gap-4 p-6 flex-wrap shrink grid md:grid-cols-2 grid-cols-1 justify-between w-full">
{data_names.map((x, index) => {
return (
<Inputs key={index} name={x} data={data_content[index]} />
);
})}
<div className="flex flex-col gap-y-4">
<h4 className="font-mono font-bold text-neutral ">
How to Enable two factor Auth
</h4>
<div className="flex gap-x-6">
<div className="flex justify-center h-28 w-28 rounded-2xl border-2 border-violet-600"></div>
<div className="flex justify-center h-28 w-28 rounded-2xl border-2 border-violet-600"></div>
<div className="flex justify-center h-28 w-28 rounded-2xl border-2 border-violet-600"></div>
</div>
</div>
</div>
</>
)
}
</div>
</div>
</div>
</div>
</div>
</>
);
};
2 changes: 1 addition & 1 deletion frontend/code/src/Stores/stores.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ type Action = {
// }
// sendMessage : (id : State['dmsIds']) => void
// updateHistory: (history : State['history']) => void,
// roomRule : (chatromm : State['chatRoomsJoinedIds']) => void
// roomRole : (chatromm : State['chatRoomsJoinedIds']) => void
}

export const useUserStore = create<State & Action>((set) => ({
Expand Down
3 changes: 2 additions & 1 deletion frontend/code/src/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
@import url('https://fonts.googleapis.com/css2?family=Lexend+Peta:wght@400;700&family=Montserrat:ital,wght@0,700;1,500&family=Poppins:ital,wght@0,400;0,500;0,600;0,700;1,400;1,500;1,600;1,700&display=swap');
@layer base {
html {
@apply no-scrollbar
@apply no-scrollbar;
@apply font-montserrat;
}
}
Empty file removed migrate
Empty file.

0 comments on commit 3a68513

Please sign in to comment.