-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FIX] fix sns toggle likes and follow
- Loading branch information
1 parent
11025a3
commit 8d66fdd
Showing
8 changed files
with
100 additions
and
90 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,32 @@ | ||
import { defineStore } from 'pinia' | ||
import { ref } from 'vue' | ||
import { type Ref, ref } from 'vue' | ||
|
||
export const useFollowStore | ||
= defineStore('follow', () => { | ||
const follows = ref<Set<number>>(new Set<number>()) | ||
return { follows } | ||
const follows: Ref<number[]> = ref<number[]>([]) | ||
|
||
const toggleFollows = async (followingId: number) => { | ||
const findIndex = follows.value.indexOf(followingId) | ||
if (findIndex === -1) { | ||
follows.value.push(followingId) | ||
} else { | ||
follows.value.splice(findIndex, 1) | ||
} | ||
} | ||
|
||
const hasFollowingId = (followingId: number) => { | ||
return follows.value.includes(followingId) | ||
} | ||
|
||
const clearFollows = async () => { | ||
follows.value = [] | ||
} | ||
|
||
return { follows, clearFollows, hasFollowingId, toggleFollows } | ||
}, { | ||
persist: { | ||
key: 'follows', | ||
storage: localStorage, | ||
paths: ['follows'] | ||
} | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,34 @@ | ||
import { defineStore } from 'pinia' | ||
import { ref } from 'vue' | ||
import { type Ref, ref } from 'vue' | ||
|
||
export const usePostLikeStore | ||
= defineStore('postLike', () => { | ||
const postLikes = ref<Set<number>>(new Set<number>()) | ||
return { postLikes } | ||
}) | ||
|
||
const postLikes: Ref<number[]> = ref<number[]>([]) | ||
|
||
const togglePostLikes = async (postId: number) => { | ||
const findIndex = postLikes.value.indexOf(postId) | ||
if (findIndex === -1) { | ||
postLikes.value.push(postId) | ||
} else { | ||
postLikes.value.splice(findIndex, 1) | ||
} | ||
} | ||
|
||
const hasPostLike = (postId: number) => { | ||
return postLikes.value.includes(postId) | ||
} | ||
|
||
const clearPostLikes = async () => { | ||
postLikes.value = [] | ||
} | ||
|
||
return { postLikes, clearPostLikes, hasPostLike, togglePostLikes } | ||
}, { | ||
persist: { | ||
key: 'postLikes', | ||
storage: localStorage, | ||
paths: ['postLikes'] | ||
} | ||
} | ||
) |
Oops, something went wrong.