diff --git a/app/tabs/feeds/[communityId].tsx b/app/tabs/feeds/[communityId].tsx index da60935df..436626875 100644 --- a/app/tabs/feeds/[communityId].tsx +++ b/app/tabs/feeds/[communityId].tsx @@ -3,6 +3,8 @@ import {useLocalSearchParams} from "expo-router"; import {PostView, SortType} from "lemmy-js-client"; import {lemmyAuthToken, lemmyInstance} from "../../../lemmy/LemmyInstance"; import FeedView from "../../../ui/Feed/FeedView"; +import {clearUpdateVote, selectFeed} from "../../../slices/feed/feedSlice"; +import {useAppDispatch, useAppSelector} from "../../../store"; const FeedsCommunityScreen = () => { const {communityId} = useLocalSearchParams(); @@ -10,10 +12,27 @@ const FeedsCommunityScreen = () => { const [sort, setSort] = useState(null); const [loading, setLoading] = useState(false); + const {updateVote} = useAppSelector(selectFeed); + + const dispatch = useAppDispatch(); + useEffect(() => { load().then(); }, [sort]); + useEffect(() => { + if(updateVote) { + setPosts(posts?.map(post => { + if(post.post.id === updateVote.postId) { + post.my_vote = updateVote.vote; + } + + return post; + })); + dispatch(clearUpdateVote()); + } + }, [updateVote]); + const load = async () => { setLoading(true); @@ -26,6 +45,7 @@ const FeedsCommunityScreen = () => { }); setPosts(res.posts); + setLoading(false); } catch(e) { setLoading(false); return;