Skip to content

Commit

Permalink
fix not refreshing
Browse files Browse the repository at this point in the history
  • Loading branch information
gkasdorf committed Jun 13, 2023
1 parent fec3380 commit 2a0d34d
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 13 deletions.
8 changes: 4 additions & 4 deletions app/tabs/feeds/[communityId].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const FeedsCommunityScreen = () => {
const dispatch = useAppDispatch();

useEffect(() => {
load().then();
load(true).then();
}, [sort]);

useEffect(() => {
Expand All @@ -33,7 +33,7 @@ const FeedsCommunityScreen = () => {
}
}, [updateVote]);

const load = async () => {
const load = async (refresh = false) => {
setLoading(true);

try {
Expand All @@ -45,7 +45,7 @@ const FeedsCommunityScreen = () => {
sort: sort
});

if(!posts) {
if(!posts || refresh) {
setPosts(res.posts);
} else {
setPosts([...posts, ...res.posts]);
Expand All @@ -58,7 +58,7 @@ const FeedsCommunityScreen = () => {
}
};

return <FeedView posts={posts} load={load} loading={loading} sort={sort} setSort={setSort} communityTitle />;
return <FeedView posts={posts} load={load} loading={loading} setSort={setSort} />;
};

export default FeedsCommunityScreen;
8 changes: 4 additions & 4 deletions app/tabs/feeds/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ const FeedsIndexScreen = () => {
}, [updateVote]);

useEffect(() => {
load().then();
load(true).then();
}, [sort]);

const load = async () => {
const load = async (refresh = false) => {
setLoading(true);

try {
Expand All @@ -54,7 +54,7 @@ const FeedsIndexScreen = () => {
sort: sort
});

if(!posts) {
if(!posts || refresh) {
setPosts(res.posts);
} else {
setPosts([...posts, ...res.posts]);
Expand All @@ -70,7 +70,7 @@ const FeedsIndexScreen = () => {
dispatch(getSubscribedCommunities());
};

return <FeedView posts={posts} loading={loading} load={load} sort={sort} setSort={setSort} titleDropsdown={true} />;
return <FeedView posts={posts} loading={loading} load={load} setSort={setSort} titleDropsdown={true} />;
};

export default FeedsIndexScreen;
8 changes: 3 additions & 5 deletions ui/Feed/FeedView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,13 @@ import FeedHeaderDropdownDrawer from "./FeedHeaderDropdownDrawer";

interface FeedViewProps {
posts: PostView[],
load: () => Promise<void>,
load: (refresh?: boolean) => Promise<void>,
loading: boolean,
sort: SortType,
titleDropsdown?: boolean,
setSort: React.Dispatch<React.SetStateAction<SortType>>,
communityTitle?: boolean
}

const FeedView = ({posts, load, loading, setSort, sort, titleDropsdown = true, communityTitle = false}: FeedViewProps) => {
const FeedView = ({posts, load, loading, setSort, titleDropsdown = true}: FeedViewProps) => {
const [sortIcon, setSortIcon] = useState(SortIconType[2]);

const {showActionSheetWithOptions} = useActionSheet();
Expand Down Expand Up @@ -84,7 +82,7 @@ const FeedView = ({posts, load, loading, setSort, sort, titleDropsdown = true, c
data={posts}
renderItem={feedItem}
keyExtractor={keyExtractor}
refreshControl={<RefreshControl refreshing={loading} onRefresh={load}/>}
refreshControl={<RefreshControl refreshing={loading} onRefresh={() => load(true)}/>}
estimatedItemSize={200}
onEndReached={load}
onEndReachedThreshold={0.95}
Expand Down

0 comments on commit 2a0d34d

Please sign in to comment.