Fakultas Ilmu Komputer UI

Commit 658cd4c2 authored by Ahmad Izzudin Alifyandra's avatar Ahmad Izzudin Alifyandra
Browse files

feat: add thread like related functions

parent 57822efe
......@@ -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();
......
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;
};
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;
}
};
......@@ -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;
......
......@@ -5,6 +5,5 @@ export type IThreadComment = {
timestamp: firebase.firestore.Timestamp;
threadId: string;
userId: string;
userName: string;
content: string;
};
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment