mirror of
https://github.com/bitsocialnet/5chan.git
synced 2026-08-03 07:41:04 +02:00
refactor(catalog filters store): add sorting store
This commit is contained in:
@@ -4,7 +4,6 @@ import { useAccountComment, useSubscribe } from '@plebbit/plebbit-react-hooks';
|
|||||||
import { isAllView, isCatalogView, isPendingPostView, isPostPageView, isSubscriptionsView } from '../../lib/utils/view-utils';
|
import { isAllView, isCatalogView, isPendingPostView, isPostPageView, isSubscriptionsView } from '../../lib/utils/view-utils';
|
||||||
import useCatalogFiltersStore from '../../stores/use-catalog-filters-store';
|
import useCatalogFiltersStore from '../../stores/use-catalog-filters-store';
|
||||||
import useFeedResetStore from '../../stores/use-feed-reset-store';
|
import useFeedResetStore from '../../stores/use-feed-reset-store';
|
||||||
import useSortingStore from '../../stores/use-sorting-store';
|
|
||||||
import useTimeFilter from '../../hooks/use-time-filter';
|
import useTimeFilter from '../../hooks/use-time-filter';
|
||||||
import styles from './board-buttons.module.css';
|
import styles from './board-buttons.module.css';
|
||||||
|
|
||||||
@@ -83,7 +82,7 @@ const RefreshButton = () => {
|
|||||||
|
|
||||||
const SortOptions = () => {
|
const SortOptions = () => {
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
const { sortType, setSortType } = useSortingStore();
|
const { sortType, setSortType } = useCatalogFiltersStore();
|
||||||
|
|
||||||
const handleSortChange = (event: React.ChangeEvent<HTMLSelectElement>) => {
|
const handleSortChange = (event: React.ChangeEvent<HTMLSelectElement>) => {
|
||||||
const type = event.target.value as 'active' | 'new';
|
const type = event.target.value as 'active' | 'new';
|
||||||
|
|||||||
@@ -3,6 +3,8 @@ import { create } from 'zustand';
|
|||||||
interface CatalogFiltersStore {
|
interface CatalogFiltersStore {
|
||||||
showTextOnlyThreads: boolean;
|
showTextOnlyThreads: boolean;
|
||||||
setShowTextOnlyThreads: (value: boolean) => void;
|
setShowTextOnlyThreads: (value: boolean) => void;
|
||||||
|
sortType: 'active' | 'new';
|
||||||
|
setSortType: (type: 'active' | 'new') => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
const useCatalogFiltersStore = create<CatalogFiltersStore>((set) => ({
|
const useCatalogFiltersStore = create<CatalogFiltersStore>((set) => ({
|
||||||
@@ -11,6 +13,9 @@ const useCatalogFiltersStore = create<CatalogFiltersStore>((set) => ({
|
|||||||
set({ showTextOnlyThreads: value });
|
set({ showTextOnlyThreads: value });
|
||||||
localStorage.setItem('showTextOnlyThreads', value.toString());
|
localStorage.setItem('showTextOnlyThreads', value.toString());
|
||||||
},
|
},
|
||||||
|
|
||||||
|
sortType: 'active',
|
||||||
|
setSortType: (type: 'active' | 'new') => set({ sortType: type }),
|
||||||
}));
|
}));
|
||||||
|
|
||||||
export default useCatalogFiltersStore;
|
export default useCatalogFiltersStore;
|
||||||
|
|||||||
@@ -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;
|
|
||||||
@@ -10,7 +10,7 @@ import useFeedStateString from '../../hooks/use-feed-state-string';
|
|||||||
import useReplyModal from '../../hooks/use-reply-modal';
|
import useReplyModal from '../../hooks/use-reply-modal';
|
||||||
import useTimeFilter from '../../hooks/use-time-filter';
|
import useTimeFilter from '../../hooks/use-time-filter';
|
||||||
import useFeedResetStore from '../../stores/use-feed-reset-store';
|
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 LoadingEllipsis from '../../components/loading-ellipsis';
|
||||||
import { Post } from '../post';
|
import { Post } from '../post';
|
||||||
import ReplyModal from '../../components/reply-modal';
|
import ReplyModal from '../../components/reply-modal';
|
||||||
@@ -42,7 +42,7 @@ const Board = () => {
|
|||||||
return [subplebbitAddress];
|
return [subplebbitAddress];
|
||||||
}, [isInAllView, isInSubscriptionsView, subplebbitAddress, defaultSubplebbitAddresses, subscriptions]);
|
}, [isInAllView, isInSubscriptionsView, subplebbitAddress, defaultSubplebbitAddresses, subscriptions]);
|
||||||
|
|
||||||
const { sortType } = useSortingStore();
|
const { sortType } = useCatalogFiltersStore();
|
||||||
const { timeFilterSeconds } = useTimeFilter();
|
const { timeFilterSeconds } = useTimeFilter();
|
||||||
|
|
||||||
const feedOptions: any = {
|
const feedOptions: any = {
|
||||||
|
|||||||
@@ -11,7 +11,6 @@ import useTimeFilter from '../../hooks/use-time-filter';
|
|||||||
import useWindowWidth from '../../hooks/use-window-width';
|
import useWindowWidth from '../../hooks/use-window-width';
|
||||||
import useCatalogFiltersStore from '../../stores/use-catalog-filters-store';
|
import useCatalogFiltersStore from '../../stores/use-catalog-filters-store';
|
||||||
import useFeedResetStore from '../../stores/use-feed-reset-store';
|
import useFeedResetStore from '../../stores/use-feed-reset-store';
|
||||||
import useSortingStore from '../../stores/use-sorting-store';
|
|
||||||
import CatalogRow from '../../components/catalog-row';
|
import CatalogRow from '../../components/catalog-row';
|
||||||
import LoadingEllipsis from '../../components/loading-ellipsis';
|
import LoadingEllipsis from '../../components/loading-ellipsis';
|
||||||
import SettingsModal from '../../components/settings-modal';
|
import SettingsModal from '../../components/settings-modal';
|
||||||
@@ -112,9 +111,8 @@ const Catalog = () => {
|
|||||||
// eslint-disable-next-line
|
// eslint-disable-next-line
|
||||||
const postsPerPage = useMemo(() => (columnCount <= 2 ? 10 : columnCount === 3 ? 15 : columnCount === 4 ? 20 : 25), []);
|
const postsPerPage = useMemo(() => (columnCount <= 2 ? 10 : columnCount === 3 ? 15 : columnCount === 4 ? 20 : 25), []);
|
||||||
|
|
||||||
const { sortType } = useSortingStore();
|
|
||||||
const { timeFilterSeconds } = useTimeFilter();
|
const { timeFilterSeconds } = useTimeFilter();
|
||||||
const { showTextOnlyThreads } = useCatalogFiltersStore();
|
const { showTextOnlyThreads, sortType } = useCatalogFiltersStore();
|
||||||
|
|
||||||
const feedOptions: any = {
|
const feedOptions: any = {
|
||||||
subplebbitAddresses,
|
subplebbitAddresses,
|
||||||
|
|||||||
Reference in New Issue
Block a user