Skip to content

Commit

Permalink
upvotes for community feed
Browse files Browse the repository at this point in the history
  • Loading branch information
gkasdorf committed Jun 13, 2023
1 parent 70c8bd4 commit 440c3c3
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions app/tabs/feeds/[communityId].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,36 @@ 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();
const [posts, setPosts] = useState<PostView[]|null>(null);
const [sort, setSort] = useState<SortType|null>(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);

Expand All @@ -26,6 +45,7 @@ const FeedsCommunityScreen = () => {
});

setPosts(res.posts);
setLoading(false);
} catch(e) {
setLoading(false);
return;
Expand Down

0 comments on commit 440c3c3

Please sign in to comment.