mirror of
https://github.com/hydralauncher/hydra.git
synced 2025-02-03 00:33:49 +03:00
Merge branch 'feat/new-catalogue' into feat/achievements-points
This commit is contained in:
commit
53b0c0b08f
@ -67,10 +67,10 @@ export function Header() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!location.pathname.startsWith("/catalogue")) {
|
if (!location.pathname.startsWith("/catalogue") && searchValue) {
|
||||||
dispatch(setFilters({ title: "" }));
|
dispatch(setFilters({ title: "" }));
|
||||||
}
|
}
|
||||||
}, [location.pathname, dispatch]);
|
}, [location.pathname, searchValue, dispatch]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
|
@ -5,6 +5,7 @@ import type { CatalogueSearchPayload } from "@types";
|
|||||||
|
|
||||||
export interface CatalogueSearchState {
|
export interface CatalogueSearchState {
|
||||||
filters: CatalogueSearchPayload;
|
filters: CatalogueSearchPayload;
|
||||||
|
page: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
const initialState: CatalogueSearchState = {
|
const initialState: CatalogueSearchState = {
|
||||||
@ -16,6 +17,7 @@ const initialState: CatalogueSearchState = {
|
|||||||
genres: [],
|
genres: [],
|
||||||
developers: [],
|
developers: [],
|
||||||
},
|
},
|
||||||
|
page: 1,
|
||||||
};
|
};
|
||||||
|
|
||||||
export const catalogueSearchSlice = createSlice({
|
export const catalogueSearchSlice = createSlice({
|
||||||
@ -27,11 +29,20 @@ export const catalogueSearchSlice = createSlice({
|
|||||||
action: PayloadAction<Partial<CatalogueSearchPayload>>
|
action: PayloadAction<Partial<CatalogueSearchPayload>>
|
||||||
) => {
|
) => {
|
||||||
state.filters = { ...state.filters, ...action.payload };
|
state.filters = { ...state.filters, ...action.payload };
|
||||||
|
state.page = initialState.page;
|
||||||
},
|
},
|
||||||
clearFilters: (state) => {
|
clearFilters: (state) => {
|
||||||
state.filters = initialState.filters;
|
state.filters = initialState.filters;
|
||||||
|
state.page = initialState.page;
|
||||||
|
},
|
||||||
|
setPage: (state, action: PayloadAction<number>) => {
|
||||||
|
state.page = action.payload;
|
||||||
|
},
|
||||||
|
clearPage: (state) => {
|
||||||
|
state.page = initialState.page;
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
export const { setFilters, clearFilters } = catalogueSearchSlice.actions;
|
export const { setFilters, clearFilters, setPage, clearPage } =
|
||||||
|
catalogueSearchSlice.actions;
|
||||||
|
@ -13,7 +13,7 @@ import "./catalogue.scss";
|
|||||||
import { SPACING_UNIT, vars } from "@renderer/theme.css";
|
import { SPACING_UNIT, vars } from "@renderer/theme.css";
|
||||||
import { downloadSourcesTable } from "@renderer/dexie";
|
import { downloadSourcesTable } from "@renderer/dexie";
|
||||||
import { FilterSection } from "./filter-section";
|
import { FilterSection } from "./filter-section";
|
||||||
import { setFilters } from "@renderer/features";
|
import { setFilters, setPage } from "@renderer/features";
|
||||||
import { useTranslation } from "react-i18next";
|
import { useTranslation } from "react-i18next";
|
||||||
import Skeleton, { SkeletonTheme } from "react-loading-skeleton";
|
import Skeleton, { SkeletonTheme } from "react-loading-skeleton";
|
||||||
import { Pagination } from "./pagination";
|
import { Pagination } from "./pagination";
|
||||||
@ -42,12 +42,11 @@ export default function Catalogue() {
|
|||||||
|
|
||||||
const [results, setResults] = useState<any[]>([]);
|
const [results, setResults] = useState<any[]>([]);
|
||||||
|
|
||||||
const [page, setPage] = useState(1);
|
|
||||||
const [itemsCount, setItemsCount] = useState(0);
|
const [itemsCount, setItemsCount] = useState(0);
|
||||||
|
|
||||||
const { formatNumber } = useFormat();
|
const { formatNumber } = useFormat();
|
||||||
|
|
||||||
const { filters } = useAppSelector((state) => state.catalogueSearch);
|
const { filters, page } = useAppSelector((state) => state.catalogueSearch);
|
||||||
|
|
||||||
const dispatch = useAppDispatch();
|
const dispatch = useAppDispatch();
|
||||||
|
|
||||||
@ -103,10 +102,6 @@ export default function Catalogue() {
|
|||||||
}));
|
}));
|
||||||
}, [steamGenresMapping, filters.genres]);
|
}, [steamGenresMapping, filters.genres]);
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
setPage(1);
|
|
||||||
}, [filters]);
|
|
||||||
|
|
||||||
const steamUserTagsFilterItems = useMemo(() => {
|
const steamUserTagsFilterItems = useMemo(() => {
|
||||||
if (!steamUserTags[language]) return [];
|
if (!steamUserTags[language]) return [];
|
||||||
|
|
||||||
@ -240,7 +235,7 @@ export default function Catalogue() {
|
|||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{groupedFilters.map((filter) => (
|
{groupedFilters.map((filter) => (
|
||||||
<li key={filter.label}>
|
<li key={`${filter.key}-${filter.value}`}>
|
||||||
<FilterItem
|
<FilterItem
|
||||||
filter={filter.label}
|
filter={filter.label}
|
||||||
orbColor={filter.orbColor}
|
orbColor={filter.orbColor}
|
||||||
@ -308,7 +303,7 @@ export default function Catalogue() {
|
|||||||
<Pagination
|
<Pagination
|
||||||
page={page}
|
page={page}
|
||||||
totalPages={Math.ceil(itemsCount / PAGE_SIZE)}
|
totalPages={Math.ceil(itemsCount / PAGE_SIZE)}
|
||||||
onPageChange={setPage}
|
onPageChange={(page) => dispatch(setPage(page))}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
import { Button } from "@renderer/components/button/button";
|
import { Button } from "@renderer/components/button/button";
|
||||||
import { ChevronLeftIcon, ChevronRightIcon } from "@primer/octicons-react";
|
import { ChevronLeftIcon, ChevronRightIcon } from "@primer/octicons-react";
|
||||||
|
import { useFormat } from "@renderer/hooks/use-format";
|
||||||
|
|
||||||
interface PaginationProps {
|
interface PaginationProps {
|
||||||
page: number;
|
page: number;
|
||||||
@ -12,6 +13,8 @@ export function Pagination({
|
|||||||
totalPages,
|
totalPages,
|
||||||
onPageChange,
|
onPageChange,
|
||||||
}: PaginationProps) {
|
}: PaginationProps) {
|
||||||
|
const { formatNumber } = useFormat();
|
||||||
|
|
||||||
if (totalPages <= 1) return null;
|
if (totalPages <= 1) return null;
|
||||||
|
|
||||||
// Number of visible pages
|
// Number of visible pages
|
||||||
@ -45,6 +48,18 @@ export function Pagination({
|
|||||||
</Button>
|
</Button>
|
||||||
|
|
||||||
{page > 2 && (
|
{page > 2 && (
|
||||||
|
<>
|
||||||
|
{/* initial page */}
|
||||||
|
<Button
|
||||||
|
theme="outline"
|
||||||
|
onClick={() => onPageChange(1)}
|
||||||
|
style={{ width: 40, maxWidth: 40, maxHeight: 40 }}
|
||||||
|
disabled={page === 1}
|
||||||
|
>
|
||||||
|
{1}
|
||||||
|
</Button>
|
||||||
|
|
||||||
|
{/* ellipsis */}
|
||||||
<div
|
<div
|
||||||
style={{
|
style={{
|
||||||
width: 40,
|
width: 40,
|
||||||
@ -55,6 +70,7 @@ export function Pagination({
|
|||||||
>
|
>
|
||||||
<span style={{ fontSize: 16 }}>...</span>
|
<span style={{ fontSize: 16 }}>...</span>
|
||||||
</div>
|
</div>
|
||||||
|
</>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
{/* Page Buttons */}
|
{/* Page Buttons */}
|
||||||
@ -68,11 +84,13 @@ export function Pagination({
|
|||||||
style={{ width: 40, maxWidth: 40, maxHeight: 40 }}
|
style={{ width: 40, maxWidth: 40, maxHeight: 40 }}
|
||||||
onClick={() => onPageChange(pageNumber)}
|
onClick={() => onPageChange(pageNumber)}
|
||||||
>
|
>
|
||||||
{pageNumber}
|
{formatNumber(pageNumber)}
|
||||||
</Button>
|
</Button>
|
||||||
))}
|
))}
|
||||||
|
|
||||||
{page < totalPages - 1 && (
|
{page < totalPages - 1 && (
|
||||||
|
<>
|
||||||
|
{/* ellipsis */}
|
||||||
<div
|
<div
|
||||||
style={{
|
style={{
|
||||||
width: 40,
|
width: 40,
|
||||||
@ -83,6 +101,17 @@ export function Pagination({
|
|||||||
>
|
>
|
||||||
<span style={{ fontSize: 16 }}>...</span>
|
<span style={{ fontSize: 16 }}>...</span>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
{/* last page */}
|
||||||
|
<Button
|
||||||
|
theme="outline"
|
||||||
|
onClick={() => onPageChange(totalPages)}
|
||||||
|
style={{ width: 40, maxWidth: 40, maxHeight: 40 }}
|
||||||
|
disabled={page === totalPages}
|
||||||
|
>
|
||||||
|
{formatNumber(totalPages)}
|
||||||
|
</Button>
|
||||||
|
</>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
{/* Next Button */}
|
{/* Next Button */}
|
||||||
|
Loading…
Reference in New Issue
Block a user