1
0
Fork 0
mirror of https://github.com/muerwre/vault-frontend.git synced 2025-04-25 04:46:40 +07:00

fix eslint

This commit is contained in:
Fedor Katurov 2023-10-30 21:49:10 +06:00
parent e4b158dada
commit a26e4168fd
80 changed files with 199 additions and 205 deletions

View file

@ -95,7 +95,6 @@ export const useOAuth = () => {
);
const accounts = useMemo(() => data || [], [data]);
const refresh = useCallback(() => mutate(), []);
const hasTelegram = useMemo(
() => accounts.some((acc) => acc.provider === 'telegram'),
@ -104,7 +103,7 @@ export const useOAuth = () => {
const showTelegramModal = useCallback(
() => showModal(Dialog.TelegramAttach, {}),
[],
[showModal],
);
return {
@ -117,6 +116,6 @@ export const useOAuth = () => {
dropAccount,
accounts,
isLoading: !data && isLoading,
refresh,
refresh: mutate,
};
};

View file

@ -5,7 +5,6 @@ import { ApiUpdateUserRequest } from '~/api/auth/types';
import { UploadSubject, UploadTarget } from '~/constants/uploads';
import { useUser } from '~/hooks/auth/useUser';
import { useUploader } from '~/hooks/data/useUploader';
import { IFile } from '~/types';
import { showErrorToast } from '~/utils/errors/showToast';
export const usePatchUser = () => {
@ -39,7 +38,7 @@ export const usePatchUser = () => {
showErrorToast(error);
}
},
[uploadFile, save],
[uploadFile, update],
);
return { updatePhoto, save };

View file

@ -1,6 +1,6 @@
import { useMemo } from "react";
import { useMemo } from 'react';
import { useAuth } from "~/hooks/auth/useAuth";
import { useAuth } from '~/hooks/auth/useAuth';
export const useSuperPowers = () => {
const { isTester, setIsTester } = useAuth();

View file

@ -30,10 +30,13 @@ export const useTelegramAccount = () => {
setLoading(false);
}
},
[],
[refresh, refreshNotificationSettings],
);
const connect = useCallback(() => showModal(Dialog.TelegramAttach, {}), []);
const connect = useCallback(
() => showModal(Dialog.TelegramAttach, {}),
[showModal],
);
const connected = useMemo(
() => accounts.some((it) => it.provider === 'telegram'),

View file

@ -5,12 +5,12 @@ import { IUser } from '~/types/auth';
export const useUserDescription = (user?: Partial<IUser>) => {
const randomPhrase = useRandomPhrase('USER_DESCRIPTION');
const isActive = useUserActiveStatus(user?.last_seen);
if (!user) {
return '';
}
const isActive = useUserActiveStatus(user.last_seen);
if (!isActive) {
return 'Юнит деактивирован';
}

View file

@ -1,14 +1,14 @@
import { useCallback, useEffect } from "react";
import { useEffect } from 'react';
import isBefore from "date-fns/isBefore";
import isBefore from 'date-fns/isBefore';
import { useRandomPhrase } from "~/constants/phrases";
import { useLastSeenBoris } from "~/hooks/auth/useLastSeenBoris";
import { useBorisStats } from "~/hooks/boris/useBorisStats";
import { IComment } from "~/types";
import { useRandomPhrase } from '~/constants/phrases';
import { useLastSeenBoris } from '~/hooks/auth/useLastSeenBoris';
import { useBorisStats } from '~/hooks/boris/useBorisStats';
import { IComment } from '~/types';
export const useBoris = (comments: IComment[]) => {
const title = useRandomPhrase("BORIS_TITLE");
const title = useRandomPhrase('BORIS_TITLE');
const { lastSeen, setLastSeen } = useLastSeenBoris();

View file

@ -1,8 +1,8 @@
import { useCallback } from "react";
import { useCallback } from 'react';
export const useConfirmation = () =>
useCallback((prompt = "", onApprove: () => {}, onReject?: () => {}) => {
if (!window.confirm(prompt || "Уверен?")) {
useCallback((prompt = '', onApprove: () => {}, onReject?: () => {}) => {
if (!window.confirm(prompt || 'Уверен?')) {
onReject?.();
return;
}

View file

@ -29,9 +29,11 @@ export const useGlobalLoader = () => {
}
hideLoader();
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [flow.isRefreshed, getInitialNodes]);
useEffect(() => {
void getInitialNodes();
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [isUser]);
};

View file

@ -30,7 +30,7 @@ export const useSSRLoadingIndicator = (delay = 0) => {
Router.events.on('routeChangeStart', show);
Router.events.on('routeChangeComplete', hide);
Router.events.on('routeChangeError', hide);
}, []);
}, [delay]);
return shown;
};

View file

@ -1,4 +1,4 @@
import { useCallback, useEffect, useMemo } from 'react';
import { useEffect, useMemo } from 'react';
import { throttle } from 'throttle-debounce';
@ -44,5 +44,5 @@ export const useScrollEnd = (
window.addEventListener('scroll', eventHandler);
return () => window.removeEventListener('scroll', eventHandler);
}, [item, active, innerHeight, debouncedCallback]);
}, [item, active, innerHeight, debouncedCallback, threshold]);
};

View file

@ -1,4 +1,4 @@
import { useCallback, useEffect, useState } from "react";
import { useCallback, useEffect, useState } from 'react';
export const useWindowSize = () => {
const [size, setSize] = useState({
@ -22,9 +22,10 @@ export const useWindowSize = () => {
useEffect(() => {
onResize();
window.addEventListener("resize", onResize);
window.addEventListener('resize', onResize);
return () => window.removeEventListener("resize", onResize);
return () => window.removeEventListener('resize', onResize);
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);
return size;

View file

@ -1,42 +1,40 @@
import { useCallback, useMemo } from "react";
import { useCallback, useMemo } from 'react';
import useSWRInfinite, { SWRInfiniteKeyLoader } from "swr/infinite";
import useSWRInfinite, { SWRInfiniteKeyLoader } from 'swr/infinite';
import {
apiCreateNote,
apiDeleteNote,
apiListNotes,
apiUpdateNote,
} from "~/api/notes";
import { ApiGetNotesRequest } from "~/api/notes/types";
import { useAuth } from "~/hooks/auth/useAuth";
import { GetLabNodesRequest, ILabNode } from "~/types/lab";
import { Note } from "~/types/notes";
import { flatten, uniqBy } from "~/utils/ramda";
} from '~/api/notes';
import { ApiGetNotesRequest } from '~/api/notes/types';
import { useAuth } from '~/hooks/auth/useAuth';
import { GetLabNodesRequest, ILabNode } from '~/types/lab';
import { Note } from '~/types/notes';
import { flatten, uniqBy } from '~/utils/ramda';
const DEFAULT_COUNT = 20;
const getKey: (isUser: boolean, search: string) => SWRInfiniteKeyLoader = (
isUser,
search,
) => (index, prev: ILabNode[]) => {
if (!isUser) return null;
if (index > 0 && (!prev?.length || prev.length < 20)) return null;
const getKey: (isUser: boolean, search: string) => SWRInfiniteKeyLoader =
(isUser, search) => (index, prev: ILabNode[]) => {
if (!isUser) return null;
if (index > 0 && (!prev?.length || prev.length < 20)) return null;
const props: GetLabNodesRequest = {
limit: DEFAULT_COUNT,
offset: index * DEFAULT_COUNT,
search: search || "",
const props: GetLabNodesRequest = {
limit: DEFAULT_COUNT,
offset: index * DEFAULT_COUNT,
search: search || '',
};
return JSON.stringify(props);
};
return JSON.stringify(props);
};
const parseKey = (key: string): ApiGetNotesRequest => {
try {
return JSON.parse(key);
} catch (error) {
return { limit: DEFAULT_COUNT, offset: 0, search: "" };
return { limit: DEFAULT_COUNT, offset: 0, search: '' };
}
};
@ -74,7 +72,7 @@ export const useNotes = (search: string) => {
async (id: number, onSuccess?: () => void) => {
await apiDeleteNote(id);
await mutate(
data?.map(page => page.filter(it => it.id !== id)),
data?.map((page) => page.filter((it) => it.id !== id)),
{ revalidate: false },
);
onSuccess?.();
@ -86,7 +84,7 @@ export const useNotes = (search: string) => {
async (id: number, text: string, onSuccess?: () => void) => {
const result = await apiUpdateNote({ id, text });
await mutate(
data?.map(page => page.map(it => (it.id === id ? result : it))),
data?.map((page) => page.map((it) => (it.id === id ? result : it))),
{ revalidate: false },
);
onSuccess?.();
@ -94,7 +92,7 @@ export const useNotes = (search: string) => {
[mutate, data],
);
const notes = useMemo(() => uniqBy(n => n.id, flatten(data || [])), [data]);
const notes = useMemo(() => uniqBy((n) => n.id, flatten(data || [])), [data]);
const hasMore = (data?.[size - 1]?.length || 0) >= 1;
const loadMore = useCallback(() => setSize(size + 1), [setSize, size]);
@ -108,6 +106,6 @@ export const useNotes = (search: string) => {
remove,
update,
}),
[notes, hasMore, loadMore, data, isValidating, create, remove],
[notes, hasMore, loadMore, data, isValidating, create, remove, update],
);
};

View file

@ -1,7 +1,6 @@
import { useCallback } from 'react';
import { SidebarName } from '~/constants/sidebar';
import { ITag } from '~/types';
import { useSidebar } from '~/utils/providers/SidebarProvider';
export const useTagSidebar = () => {

View file

@ -1,6 +1,12 @@
import { useCallback, useMemo, useState } from 'react';
import { DragStartEvent, MouseSensor, TouchSensor, useSensor, useSensors } from '@dnd-kit/core';
import {
DragStartEvent,
MouseSensor,
TouchSensor,
useSensor,
useSensors,
} from '@dnd-kit/core';
import { DragEndEvent } from '@dnd-kit/core/dist/types';
import { moveArrItem } from '~/utils/fn';
@ -8,11 +14,11 @@ import { moveArrItem } from '~/utils/fn';
export const useSortableActions = <T>(
items: T[],
getID: (item: T) => string | number,
onSortEnd: (items: T[]) => void
onSortEnd: (items: T[]) => void,
) => {
const [draggingItem, setDraggingItem] = useState<T | null>(null);
const ids = useMemo(() => items.map(getID), [items]);
const ids = useMemo(() => items.map(getID), [getID, items]);
const onDragEnd = useCallback(
({ active, over }: DragEndEvent) => {
@ -22,12 +28,12 @@ export const useSortableActions = <T>(
return;
}
const oldIndex = items.findIndex(it => getID(it) === active.id);
const newIndex = items.findIndex(it => getID(it) === over.id);
const oldIndex = items.findIndex((it) => getID(it) === active.id);
const newIndex = items.findIndex((it) => getID(it) === over.id);
onSortEnd(moveArrItem(oldIndex, newIndex, items));
},
[items]
[getID, items, onSortEnd],
);
const onDragStart = useCallback(
@ -36,11 +42,11 @@ export const useSortableActions = <T>(
return;
}
const activeItem = items.find(it => getID(it) === active.id);
const activeItem = items.find((it) => getID(it) === active.id);
setDraggingItem(activeItem ?? null);
},
[items]
[getID, items],
);
const sensors = useSensors(
@ -50,7 +56,7 @@ export const useSortableActions = <T>(
tolerance: 5,
},
}),
useSensor(MouseSensor)
useSensor(MouseSensor),
);
return { sensors, onDragEnd, onDragStart, draggingItem, ids };

View file

@ -16,5 +16,6 @@ export const useFormAutoSubmit = <T>(
const timeout = setTimeout(onSubmit, delay);
return () => clearTimeout(timeout);
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [values]);
};