Fakultas Ilmu Komputer UI
Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Functional Programming
Diskuy-Backend
Commits
83197446
Commit
83197446
authored
Jan 13, 2021
by
FadhilP
Browse files
add error handling in Topic get req
parent
995249d2
Changes
2
Hide whitespace changes
Inline
Side-by-side
diskuy/package.json
View file @
83197446
...
...
@@ -15,7 +15,7 @@
"web-vitals"
:
"^0.2.4"
},
"scripts"
:
{
"start"
:
"
set PORT=3000 && react-scripts start
"
,
"start"
:
"
node server/server.js
"
,
"build"
:
"react-scripts build"
,
"test"
:
"react-scripts test"
,
"eject"
:
"react-scripts eject"
...
...
diskuy/src/Topic.js
View file @
83197446
...
...
@@ -11,19 +11,19 @@ export default function Topic(props){
useEffect
(()
=>
{
const
fetch
=
async
()
=>
{
const
responseThreads
=
await
axios
.
get
(
`
${
API_URL
}
/threads/`
)
const
responseTopics
=
await
axios
.
get
(
`
${
API_URL
}
/topics`
)
try
{
const
responseThreads
=
await
axios
.
get
(
`
${
API_URL
}
/threads/`
)
const
responseTopics
=
await
axios
.
get
(
`
${
API_URL
}
/topics`
)
const
topic
=
responseTopics
.
data
.
data
.
find
(
topic
=>
topic
.
name
===
topicParam
).
id
const
threads
=
responseThreads
.
data
.
data
.
filter
(
thread
=>
thread
.
topic_id
===
topic
)
const
sortedThreads
=
threads
.
sort
((
a
,
b
)
=>
{
const
topic
=
responseTopics
.
data
.
data
.
find
(
topic
=>
topic
.
name
===
topicParam
).
id
const
threads
=
responseThreads
.
data
.
data
.
filter
(
thread
=>
thread
.
topic_id
===
topic
)
const
sortedThreads
=
threads
.
sort
((
a
,
b
)
=>
{
if
(
a
.
id
<
b
.
id
)
return
1
if
(
a
.
id
>
b
.
id
)
return
-
1
return
0
})
setThread
(
sortedThreads
)
console
.
log
(
threads
)
})
setThread
(
sortedThreads
)
}
catch
(
error
){}
}
fetch
()
},
[
topicParam
])
...
...
Write
Preview
Supports
Markdown
0%
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!
Cancel
Please
register
or
sign in
to comment