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
ppl-fasilkom-ui
PPL KI Ganjil 2021 2022
Clicks - Ecosystem Business
clicks-frontend
Commits
658cd4c2
Commit
658cd4c2
authored
Dec 03, 2021
by
Ahmad Izzudin Alifyandra
Browse files
feat: add thread like related functions
parent
57822efe
Changes
5
Hide whitespace changes
Inline
Side-by-side
src/helpers/images.tsx
View file @
658cd4c2
...
...
@@ -26,7 +26,6 @@ export const uploadImgToFirebase = async (
):
Promise
<
string
>
=>
{
try
{
setLoading
&&
setLoading
(
true
);
console
.
log
(
"
ayam
"
);
const
blob
:
Blob
=
await
new
Promise
((
resolve
,
reject
)
=>
{
const
xhr
=
new
XMLHttpRequest
();
...
...
src/service/firestore/thread/checkIsLiked.ts
0 → 100644
View file @
658cd4c2
import
firebase
from
"
firebase
"
;
import
{
getEnv
}
from
"
../../../helpers/getEnv
"
;
export
const
checkIsLiked
=
async
(
threadId
:
string
,
userId
:
string
):
Promise
<
boolean
>
=>
{
const
db
=
firebase
.
firestore
();
const
doc
=
await
db
.
collection
(
`threads_
${
getEnv
()}
/
${
threadId
}
/thread_likes`
)
.
doc
(
`
${
userId
}
`
)
.
get
();
return
doc
.
exists
;
};
src/service/firestore/thread/like.ts
0 → 100644
View file @
658cd4c2
import
firebase
from
"
firebase
"
;
import
{
getEnv
}
from
"
../../../helpers/getEnv
"
;
export
const
likeThread
=
async
(
threadId
:
string
,
userId
:
string
):
Promise
<
boolean
>
=>
{
try
{
const
db
=
firebase
.
firestore
();
await
db
.
collection
(
`threads_
${
getEnv
()}
/
${
threadId
}
/thread_likes`
)
.
doc
(
`
${
userId
}
`
)
.
set
({
threadId
,
userId
,
});
return
true
;
}
catch
(
e
)
{
return
false
;
}
};
export
const
unlikeThread
=
async
(
threadId
:
string
,
userId
:
string
):
Promise
<
boolean
>
=>
{
try
{
const
db
=
firebase
.
firestore
();
await
db
.
collection
(
`threads_
${
getEnv
()}
/
${
threadId
}
/thread_likes`
)
.
doc
(
`
${
userId
}
`
)
.
delete
();
return
true
;
}
catch
(
e
)
{
return
false
;
}
};
src/types/firestore/thread.ts
View file @
658cd4c2
...
...
@@ -14,7 +14,7 @@ export type IThread = {
// Subcollection of thread
export
type
IThreadLike
=
{
// ID Format: <
threadId_
userId>
// ID Format: <userId>
id
?:
string
;
threadId
:
string
;
userId
:
string
;
...
...
src/types/firestore/threadComment.ts
View file @
658cd4c2
...
...
@@ -5,6 +5,5 @@ export type IThreadComment = {
timestamp
:
firebase
.
firestore
.
Timestamp
;
threadId
:
string
;
userId
:
string
;
userName
:
string
;
content
:
string
;
};
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