refactor(catalog filters store): add sorting store

This commit is contained in:
Tom (plebeius.eth)
2024-06-14 22:00:43 +02:00
parent ce93915919
commit 2c1ea475df
5 changed files with 9 additions and 20 deletions
@@ -4,7 +4,6 @@ import { useAccountComment, useSubscribe } from '@plebbit/plebbit-react-hooks';
import { isAllView, isCatalogView, isPendingPostView, isPostPageView, isSubscriptionsView } from '../../lib/utils/view-utils';
import useCatalogFiltersStore from '../../stores/use-catalog-filters-store';
import useFeedResetStore from '../../stores/use-feed-reset-store';
import useSortingStore from '../../stores/use-sorting-store';
import useTimeFilter from '../../hooks/use-time-filter';
import styles from './board-buttons.module.css';
@@ -83,7 +82,7 @@ const RefreshButton = () => {
const SortOptions = () => {
const { t } = useTranslation();
const { sortType, setSortType } = useSortingStore();
const { sortType, setSortType } = useCatalogFiltersStore();
const handleSortChange = (event: React.ChangeEvent<HTMLSelectElement>) => {
const type = event.target.value as 'active' | 'new';
+5
View File
@@ -3,6 +3,8 @@ import { create } from 'zustand';
interface CatalogFiltersStore {
showTextOnlyThreads: boolean;
setShowTextOnlyThreads: (value: boolean) => void;
sortType: 'active' | 'new';
setSortType: (type: 'active' | 'new') => void;
}
const useCatalogFiltersStore = create<CatalogFiltersStore>((set) => ({
@@ -11,6 +13,9 @@ const useCatalogFiltersStore = create<CatalogFiltersStore>((set) => ({
set({ showTextOnlyThreads: value });
localStorage.setItem('showTextOnlyThreads', value.toString());
},
sortType: 'active',
setSortType: (type: 'active' | 'new') => set({ sortType: type }),
}));
export default useCatalogFiltersStore;
-13
View File
@@ -1,13 +0,0 @@
import { create } from 'zustand';
interface SortingStore {
sortType: 'active' | 'new';
setSortType: (type: 'active' | 'new') => void;
}
const useSortingStore = create<SortingStore>((set) => ({
sortType: 'active',
setSortType: (type) => set({ sortType: type }),
}));
export default useSortingStore;
+2 -2
View File
@@ -10,7 +10,7 @@ import useFeedStateString from '../../hooks/use-feed-state-string';
import useReplyModal from '../../hooks/use-reply-modal';
import useTimeFilter from '../../hooks/use-time-filter';
import useFeedResetStore from '../../stores/use-feed-reset-store';
import useSortingStore from '../../stores/use-sorting-store';
import useCatalogFiltersStore from '../../stores/use-catalog-filters-store';
import LoadingEllipsis from '../../components/loading-ellipsis';
import { Post } from '../post';
import ReplyModal from '../../components/reply-modal';
@@ -42,7 +42,7 @@ const Board = () => {
return [subplebbitAddress];
}, [isInAllView, isInSubscriptionsView, subplebbitAddress, defaultSubplebbitAddresses, subscriptions]);
const { sortType } = useSortingStore();
const { sortType } = useCatalogFiltersStore();
const { timeFilterSeconds } = useTimeFilter();
const feedOptions: any = {
+1 -3
View File
@@ -11,7 +11,6 @@ import useTimeFilter from '../../hooks/use-time-filter';
import useWindowWidth from '../../hooks/use-window-width';
import useCatalogFiltersStore from '../../stores/use-catalog-filters-store';
import useFeedResetStore from '../../stores/use-feed-reset-store';
import useSortingStore from '../../stores/use-sorting-store';
import CatalogRow from '../../components/catalog-row';
import LoadingEllipsis from '../../components/loading-ellipsis';
import SettingsModal from '../../components/settings-modal';
@@ -112,9 +111,8 @@ const Catalog = () => {
// eslint-disable-next-line
const postsPerPage = useMemo(() => (columnCount <= 2 ? 10 : columnCount === 3 ? 15 : columnCount === 4 ? 20 : 25), []);
const { sortType } = useSortingStore();
const { timeFilterSeconds } = useTimeFilter();
const { showTextOnlyThreads } = useCatalogFiltersStore();
const { showTextOnlyThreads, sortType } = useCatalogFiltersStore();
const feedOptions: any = {
subplebbitAddresses,