Skip to content

Commit

Permalink
[fix] Feed not refreshing after changing sort (#1070)
Browse files Browse the repository at this point in the history
* Remove broken refresh

* add react-hooks lint

* fix feed not refreshing when changing sort

* lint

---------

Co-authored-by: GitHub Actions Bot <>
  • Loading branch information
gkasdorf authored Nov 6, 2023
1 parent 36839e1 commit 20709e6
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 39 deletions.
4 changes: 3 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module.exports = {
env: {
es2021: true,
},
extends: ["plugin:react/recommended", "standard-with-typescript", "prettier"],
extends: ["plugin:react/recommended", "standard-with-typescript", "prettier", "plugin:react-hooks/recommended"],
overrides: [],
parserOptions: {
ecmaVersion: "latest",
Expand Down Expand Up @@ -57,5 +57,7 @@ module.exports = {
printWidth: 80,
}],
"no-console": [2],
"react-hooks/rules-of-hooks": [2],
"react-hooks/exhaustive-deps": [1],
},
};
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@
"eslint-plugin-prettier": "^5.0.0",
"eslint-plugin-promise": "^6.0.0",
"eslint-plugin-react": "^7.33.2",
"eslint-plugin-react-hooks": "^4.6.0",
"license-report": "^6.5.0",
"patch-package": "^8.0.0",
"postinstall-postinstall": "^2.1.0",
Expand Down
16 changes: 2 additions & 14 deletions src/components/Feed/hooks/useMainFeed.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import {
useDefaultSort,
useFeedNextPage,
useFeedPostPairs,
useLastHomePress,
} from '@src/state';
import React, {
useCallback,
Expand Down Expand Up @@ -57,8 +56,6 @@ export const useMainFeed = (): UseMainFeed => {
const defaultCommunitySort = useDefaultCommunitySort();
const defaultListingType = useDefaultListingType();

const lastHomePress = useLastHomePress();

const [sortType, setSortType] = useState<SortType>(
params?.communityName != null
? defaultCommunitySort ?? 'Hot'
Expand Down Expand Up @@ -144,15 +141,6 @@ export const useMainFeed = (): UseMainFeed => {
}
}, [listingType, sortType]);

useEffect(() => {
if (lastHomePress === 0) return;

if (!isLoading) {
onRefresh();
flashListRef.current?.scrollToOffset({ offset: 0, animated: true });
}
}, [lastHomePress]);

// Callback for loading more data when we hit the end
const onEndReached = useCallback(() => {
append(async () => {
Expand All @@ -161,7 +149,7 @@ export const useMainFeed = (): UseMainFeed => {
page: nextPage,
});
});
}, [defaultOptions, nextPage]);
}, [defaultOptions, key, nextPage]);

// Callback for refreshing the data
const onRefresh = useCallback(() => {
Expand All @@ -172,7 +160,7 @@ export const useMainFeed = (): UseMainFeed => {
refresh: true,
});
});
}, [defaultOptions]);
}, [defaultOptions, key]);

return {
postPairs,
Expand Down
16 changes: 0 additions & 16 deletions src/components/Navigation/Tabs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import ProfileStackScreen from '@components/Navigation/ProfileStackScreen';
import { Cog, Home, Inbox, Search, User } from '@tamagui/lucide-icons';
import {
setDrawerOpen,
setHomePress,
useCurrentAccount,
usePersonAvatar,
useShowAvatarInTabBar,
Expand All @@ -22,20 +21,6 @@ import AccountsContextMenu from '@components/Common/ContextMenu/components/Accou

const Tab = createBottomTabNavigator();

let lastPress = 0;

const onHomeTabPress = (): void => {
const now = Date.now();

if (now < lastPress + 200) {
setHomePress();
}

lastPress = now;

void playHaptic();
};

const onHomeTabLongPress = (): void => {
setDrawerOpen(true);
};
Expand Down Expand Up @@ -88,7 +73,6 @@ export default function Tabs(): React.JSX.Element {
tabBarIcon: ({ color }) => <Home color={color} size={24} />,
}}
listeners={{
tabPress: onHomeTabPress,
tabLongPress: onHomeTabLongPress,
}}
/>
Expand Down
16 changes: 8 additions & 8 deletions src/hooks/useLoadData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,19 +82,19 @@ export const useLoadData = <ReturnType>(

setPage?.((prev) => prev + 1);
} else {
setStatus((prev) => ({
...prev,
isLoading: false,
isError: false,
isRefreshing: false,
error: undefined,
}));

setReturnData(data);

setPage?.(2);
}

setStatus((prev) => ({
...prev,
isLoading: false,
isError: false,
isRefreshing: false,
error: undefined,
}));

inProgress.current = false;
})
.catch((e) => {
Expand Down
5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5627,6 +5627,11 @@ eslint-plugin-promise@^6.0.0:
resolved "https://registry.yarnpkg.com/eslint-plugin-promise/-/eslint-plugin-promise-6.1.1.tgz#269a3e2772f62875661220631bd4dafcb4083816"
integrity sha512-tjqWDwVZQo7UIPMeDReOpUgHCmCiH+ePnVT+5zVapL0uuHnegBUs2smM13CzOs2Xb5+MHMRFTs9v24yjba4Oig==

eslint-plugin-react-hooks@^4.6.0:
version "4.6.0"
resolved "https://registry.yarnpkg.com/eslint-plugin-react-hooks/-/eslint-plugin-react-hooks-4.6.0.tgz#4c3e697ad95b77e93f8646aaa1630c1ba607edd3"
integrity sha512-oFc7Itz9Qxh2x4gNHStv3BqJq54ExXmfC+a1NjAta66IAN87Wu0R/QArgIS9qKzX3dXKPI9H5crl9QchNMY9+g==

eslint-plugin-react@^7.33.2:
version "7.33.2"
resolved "https://registry.yarnpkg.com/eslint-plugin-react/-/eslint-plugin-react-7.33.2.tgz#69ee09443ffc583927eafe86ffebb470ee737608"
Expand Down

0 comments on commit 20709e6

Please sign in to comment.