Fakultas Ilmu Komputer UI
Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Functional Programming
Diskuy-Frontend
Commits
712eace7
Commit
712eace7
authored
Feb 22, 2021
by
FadhilP
Browse files
refactor topic
parent
18b838c7
Changes
3
Hide whitespace changes
Inline
Side-by-side
src/components/topic/CreateTopicForm.jsx
View file @
712eace7
...
...
@@ -4,17 +4,10 @@ import React, { useState } from 'react';
import
{
useInput
}
from
'
../../helpers/hooks/input-hook
'
;
import
'
../../styles/topic/CreateTopicForm.css
'
;
import
{
API_URL
}
from
'
../../config/keys
'
;
import
AuthService
,
{
loggedIn
,
authHeader
,
}
from
'
../../helpers/services/auth.service
'
;
import
{
authHeader
,
isAdmin
}
from
'
../../helpers/services/auth.service
'
;
export
default
function
CreateTopicForm
(
props
)
{
const
isAdmin
=
loggedIn
?
AuthService
.
getCurrentUser
().
data
.
role
:
'
unregistered
'
;
if
(
isAdmin
!=
'
admin
'
)
{
if
(
!
isAdmin
)
{
props
.
history
.
push
(
'
/page/1
'
);
}
...
...
src/components/topic/Topic.jsx
View file @
712eace7
/* eslint-disable eqeqeq */
import
React
,
{
useEffect
,
useState
}
from
'
react
'
;
import
React
,
{
useEffect
,
useState
,
Fragment
}
from
'
react
'
;
import
axios
from
'
axios
'
;
import
ThreadList
from
'
../thread/ThreadList
'
;
import
{
API_URL
}
from
'
../../config/keys
'
;
import
'
../../styles/topic/Topic.css
'
;
import
Button
from
'
../utility/Button
'
;
import
Pagination
from
'
../thread/Pagination
'
;
import
AuthService
,
{
import
{
loggedIn
,
authHeader
,
isAdmin
,
}
from
'
../../helpers/services/auth.service
'
;
export
default
function
Topic
(
props
)
{
const
{
params
}
=
props
.
match
;
const
currentPage
=
params
.
pageNumber
;
const
topicParam
=
params
.
topic
;
const
isAdmin
=
loggedIn
?
AuthService
.
getCurrentUser
().
data
.
role
:
'
unregistered
'
;
const
[
threads
,
setThreads
]
=
useState
([]);
const
[
totalItems
,
setTotalItems
]
=
useState
(
0
);
...
...
@@ -62,7 +60,7 @@ export default function Topic(props) {
{
loggedIn
&&
(
<
Button
text
=
"Create Thread"
color
=
"orange"
url
=
"create/thread"
/>
)
}
{
loggedIn
&&
isAdmin
==
'
admin
'
&&
(
{
loggedIn
&&
isAdmin
&&
(
<
button
type
=
"button"
className
=
"deleteTopicButton"
...
...
@@ -73,16 +71,19 @@ export default function Topic(props) {
)
}
</
div
>
<
div
className
=
"list_threads_section"
>
{
totalItems
==
0
&&
<
p
>
There are no threads with this topic yet.
</
p
>
}
{
totalItems
!=
0
&&
<
ThreadList
thread
=
{
threads
}
/>
}
{
totalItems
!=
0
&&
(
<
div
className
=
"paginationContainer"
>
<
Pagination
activePage
=
{
currentPage
}
totalItems
=
{
totalItems
}
switchPage
=
{
switchPage
}
/>
</
div
>
{
totalItems
==
0
?
(
<
p
>
There are no threads with this topic yet.
</
p
>
)
:
(
<
Fragment
>
<
ThreadList
thread
=
{
threads
}
/>
<
div
className
=
"paginationContainer"
>
<
Pagination
activePage
=
{
currentPage
}
totalItems
=
{
totalItems
}
switchPage
=
{
switchPage
}
/>
</
div
>
</
Fragment
>
)
}
</
div
>
</
div
>
...
...
src/components/topic/TopicList.jsx
View file @
712eace7
...
...
@@ -5,13 +5,10 @@ import { Link } from 'react-router-dom';
import
{
API_URL
}
from
'
../../config/keys
'
;
import
'
../../styles/topic/TopicList.css
'
;
import
Button
from
'
../utility/Button
'
;
import
AuthService
,
{
loggedIn
}
from
'
../../helpers/services/auth.service
'
;
import
{
loggedI
n
,
isAdmi
n
}
from
'
../../helpers/services/auth.service
'
;
export
default
function
TopicList
(
props
)
{
const
[
topics
,
setTopics
]
=
useState
([]);
const
isAdmin
=
loggedIn
?
AuthService
.
getCurrentUser
()?.
data
?.
role
:
'
unregistered
'
;
useEffect
(()
=>
{
const
fetch
=
async
()
=>
{
...
...
@@ -25,7 +22,7 @@ export default function TopicList(props) {
<
div
className
=
"topicContainer"
>
<
div
className
=
"headerTopic"
>
<
h1
>
Topic List
</
h1
>
{
loggedIn
&&
isAdmin
==
'
admin
'
&&
(
{
loggedIn
&&
isAdmin
&&
(
<
Button
text
=
"Create Topic"
color
=
"orange"
url
=
"create/topic"
/>
)
}
</
div
>
...
...
Write
Preview
Supports
Markdown
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