Skip to content

Commit

Permalink
Merge pull request Memmy-App#7 from gkasdorf/development
Browse files Browse the repository at this point in the history
fix refreshing
  • Loading branch information
gkasdorf authored Jun 13, 2023
2 parents 7077199 + 2a0d34d commit 217695e
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 14 deletions.
2 changes: 1 addition & 1 deletion app.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"ios": {
"bundleIdentifier": "com.gkasdorf.memmyapp",
"supportsTablet": false,
"buildNumber": "1"
"buildNumber": "3"
},
"plugins": [
[
Expand Down
14 changes: 10 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,26 +33,32 @@ const FeedsCommunityScreen = () => {
}
}, [updateVote]);

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

try {
const res = await lemmyInstance.getPosts({
auth: lemmyAuthToken,
community_id: Number(communityId),
limit: 50,
page: !posts ? 1 : (posts.length / 50) + 1,
sort: sort
});

setPosts(res.posts);
if(!posts || refresh) {
setPosts(res.posts);
} else {
setPosts([...posts, ...res.posts]);
}

setLoading(false);
} catch(e) {
setLoading(false);
return;
}
};

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;
14 changes: 10 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 @@ -50,10 +50,16 @@ const FeedsIndexScreen = () => {
const res = await lemmyInstance.getPosts({
auth: lemmyAuthToken,
limit: 50,
page: !posts ? 1 : (posts.length / 50) + 1,
sort: sort
});

setPosts(res.posts);
if(!posts || refresh) {
setPosts(res.posts);
} else {
setPosts([...posts, ...res.posts]);
}

setLoading(false);
} catch(e) {
setPosts(null);
Expand All @@ -64,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;
11 changes: 6 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,8 +82,11 @@ 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}
ListFooterComponent={loading ? <LoadingView /> : null}
/>
</View>
);
Expand Down

0 comments on commit 217695e

Please sign in to comment.