今天把留言牆的功能做出來,完成以下功能:
發文測試
按讚測試&追蹤測試
likeCount + 1
follows/{A_B}
/u/B
顯示「已追蹤」不用登入也可以看到貼文
import { doc, setDoc } from "firebase/firestore";
async function followUser(followerId: string, targetId: string) {
const ref = doc(db, "follows", `${followerId}_${targetId}`);
await setDoc(ref, {
followerId,
targetId,
createdAt: Date.now()
});
}
import { doc, updateDoc, increment } from "firebase/firestore";
async function likePost(postId: string, userId: string) {
const ref = doc(db, "posts", postId);
await updateDoc(ref, {
likeCount: increment(1),
likedBy: userId
});
}