Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
H
hw92
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
5
Issues
5
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Болатов Ален
hw92
Commits
59860c5e
Commit
59860c5e
authored
Apr 04, 2023
by
Zhanara
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
мелкие изменения
parent
ada9e5fc
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
43 additions
and
34 deletions
+43
-34
Layout.tsx
frontend/src/components/Layout.tsx
+36
-30
HomePage.tsx
frontend/src/containers/HomePage.tsx
+7
-4
No files found.
frontend/src/components/Layout.tsx
View file @
59860c5e
...
...
@@ -7,37 +7,43 @@ const Layout: FunctionComponent = (): ReactElement => {
const
{
user
}
=
useAppSelector
((
state
)
=>
state
.
user
);
const
dispatch
=
useAppDispatch
();
return
(
<
div
className=
"bg-gray-100"
>
<
div
className=
"container mx-auto flex justify-between items-center py-4"
>
<
p
className=
"text-lg font-medium"
>
Forum
</
p
>
{
!
user
.
username
?
(
<
div
>
<
NavLink
className=
"text-gray-700 hover:text-gray-900"
to=
{
'register'
}
>
Register
</
NavLink
>
</
div
>
)
:
(
<
div
className=
"flex items-center"
>
<
p
className=
"text-gray-700 mr-4"
>
<
span
className=
"text-indigo-600"
>
{
user
.
username
}
</
span
>
</
p
>
<
NavLink
className=
{
'mx-4'
}
to=
{
'/'
}
>
Add new Post
</
NavLink
>
<
NavLink
onClick=
{
()
=>
{
window
.
sessionStorage
.
setItem
(
'token'
,
''
);
dispatch
(
setInitialUser
());
}
}
to=
{
'/'
}
className=
"text-gray-700 hover:text-gray-900"
>
Log out
</
NavLink
>
</
div
>
)
}
<
div
className=
"bg-gray-100 flex"
>
<
div
className=
"w-1/6"
>
<
div
className=
"container mx-auto py-4"
>
<
p
className=
"text-lg font-medium mb-8"
>
Forum
</
p
>
{
!
user
.
username
?
(
<
div
>
<
NavLink
className=
"text-gray-700 hover:text-gray-900"
to=
{
'register'
}
>
Register
</
NavLink
>
</
div
>
)
:
(
<
div
className=
"flex flex-col"
>
<
p
className=
"text-gray-700 mb-4"
>
Hello
<
span
className=
"text-indigo-600"
>
{
user
.
username
}
!
</
span
>
</
p
>
<
NavLink
to=
{
'/'
}
className=
" mb-4"
>
Add new Post
</
NavLink
>
<
NavLink
onClick=
{
()
=>
{
window
.
sessionStorage
.
setItem
(
'token'
,
''
);
dispatch
(
setInitialUser
());
}
}
to=
{
'/'
}
className=
"text-gray-700 hover:text-gray-900"
>
Log out
</
NavLink
>
</
div
>
)
}
</
div
>
</
div
>
<
div
className=
"container mx-auto py-8"
>
<
Outlet
/>
<
div
className=
"w-3/4"
>
<
div
className=
"container mx-auto py-8"
>
<
Outlet
/>
</
div
>
</
div
>
</
div
>
);
...
...
frontend/src/containers/HomePage.tsx
View file @
59860c5e
...
...
@@ -11,17 +11,20 @@ const HomePage: FunctionComponent = (): ReactElement => {
const
dispatch
=
useAppDispatch
();
const
{
posts
}
=
useSelector
((
state
:
AppState
)
=>
state
.
posts
,
shallowEqual
)
const
{
user
}
=
useSelector
((
state
:
AppState
)
=>
state
.
user
,
shallowEqual
);
useEffect
(()
=>
{
const
token
=
window
.
sessionStorage
.
getItem
(
'token'
);
if
(
token
)
{
dispatch
(
getUser
(
token
));
dispatch
(
getPosts
())
}
});
},[]);
if
(
!
user
)
{
return
<
div
>
Loading...
</
div
>;
}
useEffect
(()
=>
{
dispatch
(
getPosts
())
},
[])
return
(
<
div
className=
"bg-gray-50 dark:bg-gray-900 h-screen w-full container mx-auto"
>
<
PostsList
posts=
{
posts
}
/>
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment