Commit 59860c5e authored by Zhanara's avatar Zhanara

мелкие изменения

parent ada9e5fc
...@@ -7,37 +7,43 @@ const Layout: FunctionComponent = (): ReactElement => { ...@@ -7,37 +7,43 @@ const Layout: FunctionComponent = (): ReactElement => {
const { user } = useAppSelector((state) => state.user); const { user } = useAppSelector((state) => state.user);
const dispatch = useAppDispatch(); const dispatch = useAppDispatch();
return ( return (
<div className="bg-gray-100"> <div className="bg-gray-100 flex">
<div className="container mx-auto flex justify-between items-center py-4"> <div className="w-1/6">
<p className="text-lg font-medium">Forum</p> <div className="container mx-auto py-4">
{!user.username ? ( <p className="text-lg font-medium mb-8">Forum</p>
<div> {!user.username ? (
<NavLink className="text-gray-700 hover:text-gray-900" to={'register'}> <div>
Register <NavLink className="text-gray-700 hover:text-gray-900" to={'register'}>
</NavLink> Register
</div> </NavLink>
) : ( </div>
<div className="flex items-center"> ) : (
<p className="text-gray-700 mr-4"> <div className="flex flex-col">
<span className="text-indigo-600">{user.username}</span> <p className="text-gray-700 mb-4">
</p> Hello
<NavLink className={'mx-4'} to={'/'}> <span className="text-indigo-600"> {user.username}!</span>
Add new Post </p>
</NavLink> <NavLink to={'/'} className=" mb-4">Add new Post
<NavLink </NavLink>
onClick={() => { <NavLink
window.sessionStorage.setItem('token', ''); onClick={() => {
dispatch(setInitialUser()); window.sessionStorage.setItem('token', '');
}} dispatch(setInitialUser());
to={'/'} }}
className="text-gray-700 hover:text-gray-900"> to={'/'}
Log out className="text-gray-700 hover:text-gray-900"
</NavLink> >
</div> Log out
)} </NavLink>
</div>
)}
</div>
</div> </div>
<div className="container mx-auto py-8"> <div className="w-3/4">
<Outlet /> <div className="container mx-auto py-8">
<Outlet />
</div>
</div> </div>
</div> </div>
); );
......
...@@ -11,17 +11,20 @@ const HomePage: FunctionComponent = (): ReactElement => { ...@@ -11,17 +11,20 @@ const HomePage: FunctionComponent = (): ReactElement => {
const dispatch = useAppDispatch(); const dispatch = useAppDispatch();
const {posts} = useSelector((state: AppState) => state.posts, shallowEqual) const {posts} = useSelector((state: AppState) => state.posts, shallowEqual)
const { user } = useSelector((state: AppState) => state.user,shallowEqual);
useEffect(() => { useEffect(() => {
const token = window.sessionStorage.getItem('token'); const token = window.sessionStorage.getItem('token');
if (token) { if (token) {
dispatch(getUser(token)); dispatch(getUser(token));
dispatch(getPosts())
} }
}); },[]);
if (!user) {
return <div>Loading...</div>;
}
useEffect(() => {
dispatch(getPosts())
}, [])
return ( return (
<div className="bg-gray-50 dark:bg-gray-900 h-screen w-full container mx-auto"> <div className="bg-gray-50 dark:bg-gray-900 h-screen w-full container mx-auto">
<PostsList posts={posts}/> <PostsList posts={posts}/>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment