forked from nihonium/nyanimedb
feat!(front): migrate to Hey API
This commit is contained in:
parent
128a33824a
commit
6e802d2402
47 changed files with 2865 additions and 1209 deletions
|
|
@ -1,7 +1,7 @@
|
|||
import { useEffect, useState } from "react";
|
||||
import { useParams, Link } from "react-router-dom";
|
||||
import { DefaultService } from "../../api/services/DefaultService";
|
||||
import type { Title } from "../../api";
|
||||
// import { DefaultService } from "../../api/services/DefaultService";
|
||||
import { getTitle, type Title } from "../../api";
|
||||
import { TitleStatusControls } from "../../components/TitleStatusControls/TitleStatusControls";
|
||||
|
||||
export default function TitlePage() {
|
||||
|
|
@ -19,8 +19,9 @@ export default function TitlePage() {
|
|||
const fetchTitle = async () => {
|
||||
setLoading(true);
|
||||
try {
|
||||
const data = await DefaultService.getTitle(titleId, "all");
|
||||
setTitle(data);
|
||||
// const data = await DefaultService.getTitle(titleId, "all");
|
||||
const data = await getTitle({path: {title_id: titleId}})
|
||||
setTitle(data?.data ?? null);
|
||||
setError(null);
|
||||
} catch (err: any) {
|
||||
console.error(err);
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
};
|
||||
};
|
||||
|
||||
// Инициализация: загружаем сразу две страницы
|
||||
|
|
|
|||
|
|
@ -1,14 +1,14 @@
|
|||
// pages/UserPage/UserPage.tsx
|
||||
import { useEffect, useState } from "react";
|
||||
import { useParams } from "react-router-dom";
|
||||
import { DefaultService } from "../../api/services/DefaultService";
|
||||
// import { DefaultService } from "../../api/services/DefaultService";
|
||||
import { SearchBar } from "../../components/SearchBar/SearchBar";
|
||||
import { TitlesSortBox } from "../../components/TitlesSortBox/TitlesSortBox";
|
||||
import { LayoutSwitch } from "../../components/LayoutSwitch/LayoutSwitch";
|
||||
import { ListView } from "../../components/ListView/ListView";
|
||||
import { UserTitleCardSquare } from "../../components/cards/UserTitleCardSquare";
|
||||
import { UserTitleCardHorizontal } from "../../components/cards/UserTitleCardHorizontal";
|
||||
import type { User, UserTitle, CursorObj, TitleSort } from "../../api";
|
||||
import { type User, type UserTitle, type CursorObj, type TitleSort, getUsersId, getUserTitles } from "../../api";
|
||||
import { Link } from "react-router-dom";
|
||||
|
||||
const PAGE_SIZE = 10;
|
||||
|
|
@ -42,8 +42,9 @@ export default function UserPage({ userId }: UserPageProps) {
|
|||
if (!id) return;
|
||||
setLoadingUser(true);
|
||||
try {
|
||||
const result = await DefaultService.getUsersId(id, "all");
|
||||
setUser(result);
|
||||
// const result = await DefaultService.getUsersId(id, "all");
|
||||
const result = await getUsersId({path: {user_id: id}})
|
||||
setUser(result?.data ?? null);
|
||||
setErrorUser(null);
|
||||
} catch (err: any) {
|
||||
console.error(err);
|
||||
|
|
@ -63,25 +64,41 @@ export default function UserPage({ userId }: UserPageProps) {
|
|||
: "";
|
||||
|
||||
try {
|
||||
const result = await DefaultService.getUserTitles(
|
||||
id,
|
||||
cursorStr,
|
||||
sort,
|
||||
sortForward,
|
||||
search.trim() || undefined,
|
||||
undefined, // status фильтр, можно добавить
|
||||
undefined, // watchStatus
|
||||
undefined, // rating
|
||||
undefined, // myRate
|
||||
undefined, // releaseYear
|
||||
undefined, // releaseSeason
|
||||
PAGE_SIZE,
|
||||
"all"
|
||||
);
|
||||
const result = await getUserTitles({
|
||||
path: {
|
||||
user_id: id,
|
||||
},
|
||||
query: {
|
||||
cursor: cursorStr,
|
||||
sort: sort,
|
||||
sort_forward: sortForward,
|
||||
word: search.trim() || undefined,
|
||||
status: undefined,
|
||||
watch_status: undefined,
|
||||
rating: undefined,
|
||||
my_rate: undefined,
|
||||
release_year: undefined,
|
||||
release_season: undefined,
|
||||
limit: PAGE_SIZE}})
|
||||
// const result = await DefaultService.getUserTitles(
|
||||
// id,
|
||||
// cursorStr,
|
||||
// sort,
|
||||
// sortForward,
|
||||
// search.trim() || undefined,
|
||||
// undefined, // status фильтр, можно добавить
|
||||
// undefined, // watchStatus
|
||||
// undefined, // rating
|
||||
// undefined, // myRate
|
||||
// undefined, // releaseYear
|
||||
// undefined, // releaseSeason
|
||||
// PAGE_SIZE,
|
||||
// "all"
|
||||
// );
|
||||
|
||||
if (!result?.data?.length) return { items: [], nextCursor: null };
|
||||
if (!result?.data?.data.length) return { items: [], nextCursor: null };
|
||||
|
||||
return { items: result.data, nextCursor: result.cursor ?? null };
|
||||
return { items: result.data?.data, nextCursor: result.data?.cursor ?? null };
|
||||
} catch (err: any) {
|
||||
if (err.status === 204) return { items: [], nextCursor: null };
|
||||
throw err;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue