Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
D
Daily Thought App
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
COM3014-Coursework
Daily Thought App
Commits
c7feda8c
Commit
c7feda8c
authored
1 year ago
by
Matt Kirby
Browse files
Options
Downloads
Patches
Plain Diff
uses useUser (lol) hook
parent
52994138
No related branches found
Branches containing commit
No related tags found
1 merge request
!18
Fe search and friends (sorry in advance)
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
daily-thought-frontend/src/pages/feed.tsx
+2
-27
2 additions, 27 deletions
daily-thought-frontend/src/pages/feed.tsx
with
2 additions
and
27 deletions
daily-thought-frontend/src/pages/feed.tsx
+
2
−
27
View file @
c7feda8c
...
...
@@ -2,6 +2,7 @@ import NavBar from "@/components/navigation/NavBar";
import
AnswerCard
from
"
@/components/post/AnswerCard
"
;
import
Post
from
"
@/components/post/Post
"
;
import
Question
from
"
@/components/question/Question
"
;
import
{
useUser
}
from
"
@/hooks/useUser
"
;
import
{
User
}
from
"
@/types/user
"
;
import
Router
from
"
next/router
"
;
import
{
useEffect
,
useState
}
from
"
react
"
;
...
...
@@ -16,33 +17,7 @@ const userx = {
}
const
Feed
=
()
=>
{
const
[
user
,
setUser
]
=
useState
<
undefined
|
User
>
(
undefined
)
const
fetchUser
=
async
()
=>
{
const
endpoint
=
`
${
process
.
env
.
NEXT_PUBLIC_USER_SERVICE_URL
}
api/user/
${
sessionStorage
.
getItem
(
'
username
'
)}
`
const
response
=
await
fetch
(
endpoint
)
return
await
response
.
json
()
}
useEffect
(()
=>
{
if
(
sessionStorage
.
length
<
2
){
Router
.
push
(
"
/
"
)
}
})
useEffect
(()
=>
{
if
(
!
user
){
fetchUser
().
then
(
res
=>
{
const
{
_id
,
username
,
email
,
profile
,
firstName
,
lastName
}
=
res
setUser
({
id
:
_id
,
email
,
username
,
profile
,
firstName
,
lastName
})
})
}
})
const
user
=
useUser
()
return
(
<>
<
div
className
=
"w-full"
>
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment