feat!(front): migrate to Hey API
This commit is contained in:
parent
128a33824a
commit
6e802d2402
47 changed files with 2865 additions and 1209 deletions
|
|
@ -2,10 +2,10 @@ import { useEffect, useState } from "react";
|
|||
import { ListView } from "../../components/ListView/ListView";
|
||||
import { SearchBar } from "../../components/SearchBar/SearchBar";
|
||||
import { TitlesSortBox } from "../../components/TitlesSortBox/TitlesSortBox";
|
||||
import { DefaultService } from "../../api/services/DefaultService";
|
||||
// import { DefaultService } from "../../api/services/DefaultService";
|
||||
import { TitleCardSquare } from "../../components/cards/TitleCardSquare";
|
||||
import { TitleCardHorizontal } from "../../components/cards/TitleCardHorizontal";
|
||||
import type { CursorObj, Title, TitleSort } from "../../api";
|
||||
import { getTitles, type CursorObj, type Title, type TitleSort } from "../../api";
|
||||
import { LayoutSwitch } from "../../components/LayoutSwitch/LayoutSwitch";
|
||||
import { Link } from "react-router-dom";
|
||||
import { type TitlesFilter, TitlesFilterPanel } from "../../components/TitlesFilterPanel/TitlesFilterPanel";
|
||||
|
|
@ -32,37 +32,31 @@ export default function TitlesPage() {
|
|||
});
|
||||
|
||||
const fetchPage = async (cursorObj: CursorObj | null) => {
|
||||
const cursorStr = cursorObj ? btoa(JSON.stringify(cursorObj)).replace(/\+/g, '-').replace(/\//g, '_').replace(/=+$/, '') : "";
|
||||
const cursorStr = cursorObj
|
||||
? btoa(JSON.stringify(cursorObj)).replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "")
|
||||
: undefined;
|
||||
|
||||
try {
|
||||
const result = await DefaultService.getTitles(
|
||||
cursorStr,
|
||||
sort,
|
||||
sortForward,
|
||||
filters.extSearch,
|
||||
search.trim() || undefined,
|
||||
filters.status ? [filters.status] : undefined,
|
||||
filters.rating || undefined,
|
||||
filters.releaseYear || undefined,
|
||||
filters.releaseSeason || undefined,
|
||||
PAGE_SIZE,
|
||||
PAGE_SIZE,
|
||||
"all"
|
||||
);
|
||||
const response = await getTitles({
|
||||
query: {
|
||||
cursor: cursorStr,
|
||||
sort: sort,
|
||||
sort_forward: sortForward,
|
||||
ext_search: filters.extSearch,
|
||||
word: search.trim() || undefined,
|
||||
status: filters.status ? [filters.status] : undefined,
|
||||
rating: filters.rating || undefined,
|
||||
release_year: filters.releaseYear || undefined,
|
||||
release_season: filters.releaseSeason || undefined,
|
||||
limit: PAGE_SIZE,
|
||||
offset: PAGE_SIZE,
|
||||
fields: "all",
|
||||
},
|
||||
});
|
||||
|
||||
if ((result === undefined) || !result.data?.length) {
|
||||
return { items: [], nextCursor: null };
|
||||
}
|
||||
return {
|
||||
items: result.data ?? [],
|
||||
nextCursor: result.cursor ?? null
|
||||
};
|
||||
} catch (err: any) {
|
||||
if (err.status === 204) {
|
||||
return { items: [], nextCursor: null };
|
||||
}
|
||||
throw err;
|
||||
}
|
||||
return {
|
||||
items: response.data?.data ?? [],
|
||||
nextCursor: response.data?.cursor ?? null,
|
||||
};
|
||||
};
|
||||
|
||||
// Инициализация: загружаем сразу две страницы
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue