Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate filters to rtk query #371

Merged
merged 1 commit into from
Aug 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 11 additions & 7 deletions src/components/Dialogs/FiltersModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,24 @@ import ModalPanel from '../Panels/ModalPanel';
import { useDispatch, useSelector } from 'react-redux';
import { RootState } from '../../core/store';
import { setStatus } from '../../core/slices/modals/filters';
import Events from '../../core/events';
import { useLazyGetTopFiltersQuery } from '../../core/rtkQuery/collectionApi';

import type { CollectionFilterType } from '../../core/types/api/collection';

function FiltersModal() {
const dispatch = useDispatch();
const status = useSelector((state: RootState) => state.modals.filters.status);
const filters = useSelector((state: RootState) => state.modals.filters.filters);

const handleClose = () => dispatch(setStatus(false));
const [trigger, filtersResult] = useLazyGetTopFiltersQuery({});
const filters: Array<CollectionFilterType> = filtersResult?.data?.List ?? [] as Array<CollectionFilterType>;

useEffect(() => {
dispatch({ type: Events.FILTERS_GET });
}, []);
if (!status) { return; }
trigger({}).catch(() => {});
}, [status]);

const handleClose = () => dispatch(setStatus(false));

const renderItem = item => (
const renderItem = (item: CollectionFilterType) => (
<div className="flex justify-between font-semibold">
<span>{item.Name}</span>
<span className="text-highlight-2">{item.Size}</span>
Expand Down
2 changes: 0 additions & 2 deletions src/core/events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ export default {
FIRSTRUN_TEST_DATABASE: 'EVENT_FIRSTRUN_TEST_DATABASE',
// DASHBOARD
DASHBOARD_UPCOMING_ANIME: 'EVENT_DASHBOARD_UPCOMING_ANIME',
// FILTERS
FILTERS_GET: 'EVENT_FILTERS_GET',
// FOLDER
FOLDER_BROWSE: 'EVENT_FOLDER_BROWSE',
// QUICK ACTIONS
Expand Down
2 changes: 1 addition & 1 deletion src/core/middlewares/rtkQueryError.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const rtkQueryErrorLogger: Middleware =
if (action.payload.status === 401) {
toast.error('Unauthorized!');
} else {
toast.error(action.payload?.data?.title ?? action.payload.error);
toast.error(action.payload?.data?.title ?? action.payload.error ?? `${action.payload.status} - ${action.error.message}`);
}
}

Expand Down
6 changes: 5 additions & 1 deletion src/core/rtkQuery/collectionApi.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { createApi, fetchBaseQuery } from '@reduxjs/toolkit/query/react';
import { RootState } from '../store';

import { CollectionGroupType } from '../types/api/collection';
import { CollectionFilterType, CollectionGroupType } from '../types/api/collection';
import { ListResultType, PaginationType } from '../types/api';
import { SeriesType } from '../types/api/series';

Expand All @@ -22,10 +22,14 @@ export const collectionApi = createApi({
getGroupSeries: build.query<Array<SeriesType>, { groupId?: string }>({
query: ({ groupId }) => ({ url: `Group/${groupId}/Series` }),
}),
getTopFilters: build.query<ListResultType<Array<CollectionFilterType>>, PaginationType>({
query: params => ({ url: 'Filter', params: { page: params.page ?? 1, pageSize: params.pageSize ?? 0 } }),
}),
}),
});

export const {
useLazyGetGroupsQuery,
useGetGroupSeriesQuery,
useLazyGetTopFiltersQuery,
} = collectionApi;
20 changes: 0 additions & 20 deletions src/core/sagas/collection.ts

This file was deleted.

3 changes: 0 additions & 3 deletions src/core/sagas/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import ApiCommon from '../api/common';
import Events from '../events';

import SagaAuth from './auth';
import SagaCollection from './collection';
import SagaFile from './file';
import SagaFolder from './folder';
import SagaImportFolder from './import-folder';
Expand Down Expand Up @@ -58,8 +57,6 @@ export default function* rootSaga() {
takeEvery(Events.FIRSTRUN_START_SERVER, SagaInit.startServer),
takeEvery(Events.FIRSTRUN_TEST_ANIDB, SagaInit.testAniDB),
takeEvery(Events.FIRSTRUN_TEST_DATABASE, SagaInit.testDatabase),
// FILTERS
takeEvery(Events.FILTERS_GET, SagaCollection.getFilters),
// FOLDER
takeEvery(Events.FOLDER_BROWSE, SagaFolder.folderBrowse),
// QUICK ACTIONS
Expand Down
2 changes: 1 addition & 1 deletion src/core/types/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export type QueueStatusType = {
};

export type PaginationType = {
pageSize: number;
pageSize?: number;
page?: number;
};

Expand Down
13 changes: 13 additions & 0 deletions src/core/types/api/collection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,17 @@ export type GroupSizesSeriesTypesType = {
Web: number;
Movie: number;
OVA: number;
};

export type CollectionFilterType = {
IDs: {
ParentFilter: number | null;
ID: number;
},
Locked: boolean;
ApplyAtSeriesLevel: boolean;
Directory: boolean;
Hidden: boolean;
Name: string;
Size: number;
};