diff --git a/app/pages/CreateCollection.tsx b/app/pages/CreateCollection.tsx
index 8300788..7363e6d 100644
--- a/app/pages/CreateCollection.tsx
+++ b/app/pages/CreateCollection.tsx
@@ -18,19 +18,8 @@ import { ReleaseLink } from "#/components/ReleaseLink/ReleaseLink";
import { CropModal } from "#/components/CropModal/CropModal";
import { b64toBlob } from "#/api/utils";
-const fetcher = async (url: string) => {
- const res = await fetch(url);
-
- if (!res.ok) {
- const error = new Error(
- `An error occurred while fetching the data. status: ${res.status}`
- );
- error.message = await res.json();
- throw error;
- }
-
- return res.json();
-};
+import { useSWRfetcher } from "#/api/utils";
+import { Spinner } from "#/components/Spinner/Spinner";
export const CreateCollectionPage = () => {
const userStore = useUserStore();
@@ -150,9 +139,9 @@ export const CreateCollectionPage = () => {
async function _createCollection() {
const url =
- mode === "edit"
- ? `${ENDPOINTS.collection.edit}/${collection_id}?token=${userStore.token}`
- : `${ENDPOINTS.collection.create}?token=${userStore.token}`;
+ mode === "edit" ?
+ `${ENDPOINTS.collection.edit}/${collection_id}?token=${userStore.token}`
+ : `${ENDPOINTS.collection.create}?token=${userStore.token}`;
const res = await fetch(url, {
method: "POST",
@@ -239,39 +228,42 @@ export const CreateCollectionPage = () => {
className="flex flex-col items-center w-full sm:max-w-[600px] h-[337px] border-2 border-gray-300 border-dashed rounded-lg cursor-pointer bg-gray-50 hover:bg-gray-100 dark:border-gray-600 dark:bg-gray-700 dark:hover:border-gray-500 dark:hover:bg-gray-600"
>
- {!imageUrl ? (
- <>
-
-
- Нажмите для загрузки{" "}
- или перетащите файл
-
-
- PNG или JPG (Макс. 600x337 пикселей)
-
- >
- ) : (
- // eslint-disable-next-line @next/next/no-img-element
-

- )}
+ {
+ !imageUrl ?
+ <>
+
+
+
+ Нажмите для загрузки
+ {" "}
+ или перетащите файл
+
+
+ PNG или JPG (Макс. 600x337 пикселей)
+
+ >
+ // eslint-disable-next-line @next/next/no-img-element
+ :

+
+ }
}
+ {isLoading && }
+ {error && Произошла ошибка
}
);
};
diff --git a/app/pages/Search.tsx b/app/pages/Search.tsx
index ba68963..f1ee103 100644
--- a/app/pages/Search.tsx
+++ b/app/pages/Search.tsx
@@ -11,20 +11,7 @@ import { useUserStore } from "../store/auth";
import { Button, Dropdown, Modal } from "flowbite-react";
import { CollectionsSection } from "#/components/CollectionsSection/CollectionsSection";
import { UserSection } from "#/components/UserSection/UserSection";
-
-const fetcher = async (url: string) => {
- const res = await fetch(url);
-
- if (!res.ok) {
- const error = new Error(
- `An error occurred while fetching the data. status: ${res.status}`
- );
- error.message = await res.json();
- throw error;
- }
-
- return res.json();
-};
+import { useSWRfetcher } from "#/api/utils";
const ListsMapping = {
watching: {
@@ -128,7 +115,7 @@ export function SearchPage() {
const { data, error, isLoading, size, setSize } = useSWRInfinite(
getKey,
- fetcher,
+ useSWRfetcher,
{ initialSize: 2, revalidateFirstPage: false }
);
@@ -174,7 +161,18 @@ export function SearchPage() {
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [searchVal]);
- if (error) return failed to load: {error.message}
;
+ if (error)
+ return (
+
+
+
Ошибка
+
+ Произошла ошибка поиска. Попробуйте обновить страницу или зайдите
+ позже.
+
+
+
+ );
return (
<>
@@ -237,39 +235,35 @@ export function SearchPage() {
{data && data[0].related &&
}
- {content ? (
- content.length > 0 ? (
+ {content ?
+ content.length > 0 ?
<>
- {where == "collections" ? (
+ {where == "collections" ?
- ) : where == "profiles" ? (
+ : where == "profiles" ?
- ) : (
-
- )}
+ }
>
- ) : (
-
+ :
Странно, аниме не найдено, попробуйте другой запрос...
- )
- ) : (
- isLoading && (
+ : isLoading && (
)
- )}
+ }
{!content && !isLoading && !query && (
@@ -277,11 +271,13 @@ export function SearchPage() {
)}
- {data &&
- data.length > 1 &&
- (where == "releases"
- ? data[data.length - 1].releases.length == 25
- : data[data.length - 1].content.length == 25) ? (
+ {(
+ data &&
+ data.length > 1 &&
+ (where == "releases" ?
+ data[data.length - 1].releases.length == 25
+ : data[data.length - 1].content.length == 25)
+ ) ?
- ) : (
- ""
- )}
+ : ""}
- {props.isAuth &&
- where == "list" &&
- ListsMapping.hasOwnProperty(list) ? (
+ {props.isAuth && where == "list" && ListsMapping.hasOwnProperty(list) ?
Список
@@ -414,10 +406,8 @@ const FiltersModal = (props: {
- ) : (
- ""
- )}
- {!["profiles", "collections"].includes(where) ? (
+ : ""}
+ {!["profiles", "collections"].includes(where) ?
Искать по
@@ -435,9 +425,7 @@ const FiltersModal = (props: {
- ) : (
- ""
- )}
+ : ""}