mirror of
https://github.com/idanoo/autobrr
synced 2025-07-23 08:49:13 +00:00
feat(web): move from react-router to @tanstack/router (#1338)
* fix(auth): invalid cookie handling and wrongful basic auth invalidation * fix(auth): fix test to reflect new HTTP status code * fix(auth/web): do not throw on error * fix(http): replace http codes in middleware to prevent basic auth invalidation fix typo in comment * fix test * fix(web): api client handle 403 * refactor(http): auth_test use testify.assert * refactor(http): set session opts after valid login * refactor(http): send more client headers * fix(http): test * refactor(web): move router to tanstack/router * refactor(web): use route loaders and suspense * refactor(web): useSuspense for settings * refactor(web): invalidate cookie in middleware * fix: loclfile * fix: load filter/id * fix(web): login, onboard, types, imports * fix(web): filter load * fix(web): build errors * fix(web): ts-expect-error * fix(tests): filter_test.go * fix(filters): tests * refactor: remove duplicate spinner components refactor: ReleaseTable.tsx loading animation refactor: remove dedicated `pendingComponent` for `settingsRoute` * fix: refactor missed SectionLoader to RingResizeSpinner * fix: substitute divides with borders to account for unloaded elements * fix(api): action status URL param * revert: action status URL param add comment * fix(routing): notfound handling and split files * fix(filters): notfound get params * fix(queries): colon * fix(queries): comments ts-ignore * fix(queries): extract queryKeys * fix(queries): remove err * fix(routes): move zob schema inline * fix(auth): middleware and redirect to login * fix(auth): failing test * fix(logs): invalidate correct key * fix(logs): invalidate correct key * fix(logs): invalidate correct key * fix: JSX element stealing focus from searchbar * reimplement empty release table state text * fix(context): use deep-copy * fix(releases): empty state and filter input warnings * fix(releases): empty states * fix(auth): onboarding * fix(cache): invalidate queries --------- Co-authored-by: ze0s <43699394+zze0s@users.noreply.github.com>
This commit is contained in:
parent
cc9656cd41
commit
1a23b69bcf
64 changed files with 2543 additions and 2091 deletions
|
@ -5,17 +5,18 @@
|
|||
|
||||
import { Fragment } from "react";
|
||||
import { useMutation, useQueryClient } from "@tanstack/react-query";
|
||||
import { useNavigate } from "@tanstack/react-router";
|
||||
import { toast } from "react-hot-toast";
|
||||
import { XMarkIcon } from "@heroicons/react/24/solid";
|
||||
import { Dialog, Transition } from "@headlessui/react";
|
||||
import type { FieldProps } from "formik";
|
||||
import { Field, Form, Formik, FormikErrors, FormikValues } from "formik";
|
||||
import { useNavigate } from "react-router-dom";
|
||||
|
||||
import { APIClient } from "@api/APIClient";
|
||||
import { FilterKeys } from "@api/query_keys";
|
||||
import { DEBUG } from "@components/debug";
|
||||
import Toast from "@components/notifications/Toast";
|
||||
import { filterKeys } from "@screens/filters/List";
|
||||
|
||||
|
||||
interface filterAddFormProps {
|
||||
isOpen: boolean;
|
||||
|
@ -28,13 +29,12 @@ export function FilterAddForm({ isOpen, toggle }: filterAddFormProps) {
|
|||
const mutation = useMutation({
|
||||
mutationFn: (filter: Filter) => APIClient.filters.create(filter),
|
||||
onSuccess: (filter) => {
|
||||
queryClient.invalidateQueries({ queryKey: filterKeys.lists() });
|
||||
queryClient.invalidateQueries({ queryKey: FilterKeys.lists() });
|
||||
|
||||
toast.custom((t) => <Toast type="success" body={`Filter ${filter.name} was added`} t={t} />);
|
||||
|
||||
toggle();
|
||||
if (filter.id) {
|
||||
navigate(filter.id.toString());
|
||||
navigate({ to: "/filters/$filterId", params: { filterId: filter.id }})
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
|
@ -12,9 +12,9 @@ import type { FieldProps } from "formik";
|
|||
import { Field, Form, Formik, FormikErrors, FormikValues } from "formik";
|
||||
|
||||
import { APIClient } from "@api/APIClient";
|
||||
import { ApiKeys } from "@api/query_keys";
|
||||
import { DEBUG } from "@components/debug";
|
||||
import Toast from "@components/notifications/Toast";
|
||||
import { apiKeys } from "@screens/settings/Api";
|
||||
|
||||
interface apiKeyAddFormProps {
|
||||
isOpen: boolean;
|
||||
|
@ -27,7 +27,7 @@ export function APIKeyAddForm({ isOpen, toggle }: apiKeyAddFormProps) {
|
|||
const mutation = useMutation({
|
||||
mutationFn: (apikey: APIKey) => APIClient.apikeys.create(apikey),
|
||||
onSuccess: (_, key) => {
|
||||
queryClient.invalidateQueries({ queryKey: apiKeys.lists() });
|
||||
queryClient.invalidateQueries({ queryKey: ApiKeys.lists() });
|
||||
|
||||
toast.custom((t) => <Toast type="success" body={`API key ${key.name} was added`} t={t}/>);
|
||||
|
||||
|
|
|
@ -13,6 +13,7 @@ import { toast } from "react-hot-toast";
|
|||
import { classNames, sleep } from "@utils";
|
||||
import { DEBUG } from "@components/debug";
|
||||
import { APIClient } from "@api/APIClient";
|
||||
import { DownloadClientKeys } from "@api/query_keys";
|
||||
import { DownloadClientTypeOptions, DownloadRuleConditionOptions } from "@domain/constants";
|
||||
import Toast from "@components/notifications/Toast";
|
||||
import { useToggle } from "@hooks/hooks";
|
||||
|
@ -24,7 +25,6 @@ import {
|
|||
SwitchGroupWide,
|
||||
TextFieldWide
|
||||
} from "@components/inputs";
|
||||
import { clientKeys } from "@screens/settings/DownloadClient";
|
||||
import { DocsLink, ExternalLink } from "@components/ExternalLink";
|
||||
import { SelectFieldBasic } from "@components/inputs/select_wide";
|
||||
|
||||
|
@ -693,7 +693,7 @@ export function DownloadClientAddForm({ isOpen, toggle }: formProps) {
|
|||
const addMutation = useMutation({
|
||||
mutationFn: (client: DownloadClient) => APIClient.download_clients.create(client),
|
||||
onSuccess: () => {
|
||||
queryClient.invalidateQueries({ queryKey: clientKeys.lists() });
|
||||
queryClient.invalidateQueries({ queryKey: DownloadClientKeys.lists() });
|
||||
toast.custom((t) => <Toast type="success" body="Client was added" t={t} />);
|
||||
|
||||
toggle();
|
||||
|
@ -865,8 +865,8 @@ export function DownloadClientUpdateForm({ client, isOpen, toggle }: updateFormP
|
|||
const mutation = useMutation({
|
||||
mutationFn: (client: DownloadClient) => APIClient.download_clients.update(client),
|
||||
onSuccess: () => {
|
||||
queryClient.invalidateQueries({ queryKey: clientKeys.lists() });
|
||||
queryClient.invalidateQueries({ queryKey: clientKeys.detail(client.id) });
|
||||
queryClient.invalidateQueries({ queryKey: DownloadClientKeys.lists() });
|
||||
queryClient.invalidateQueries({ queryKey: DownloadClientKeys.detail(client.id) });
|
||||
|
||||
toast.custom((t) => <Toast type="success" body={`${client.name} was updated successfully`} t={t} />);
|
||||
toggle();
|
||||
|
@ -878,8 +878,8 @@ export function DownloadClientUpdateForm({ client, isOpen, toggle }: updateFormP
|
|||
const deleteMutation = useMutation({
|
||||
mutationFn: (clientID: number) => APIClient.download_clients.delete(clientID),
|
||||
onSuccess: () => {
|
||||
queryClient.invalidateQueries({ queryKey: clientKeys.lists() });
|
||||
queryClient.invalidateQueries({ queryKey: clientKeys.detail(client.id) });
|
||||
queryClient.invalidateQueries({ queryKey: DownloadClientKeys.lists() });
|
||||
queryClient.invalidateQueries({ queryKey: DownloadClientKeys.detail(client.id) });
|
||||
|
||||
toast.custom((t) => <Toast type="success" body={`${client.name} was deleted.`} t={t} />);
|
||||
toggleDeleteModal();
|
||||
|
|
|
@ -9,6 +9,7 @@ import { toast } from "react-hot-toast";
|
|||
import { useFormikContext } from "formik";
|
||||
|
||||
import { APIClient } from "@api/APIClient";
|
||||
import { FeedKeys } from "@api/query_keys";
|
||||
import Toast from "@components/notifications/Toast";
|
||||
import { SlideOver } from "@components/panels";
|
||||
import { NumberFieldWide, PasswordFieldWide, SwitchGroupWide, TextFieldWide } from "@components/inputs";
|
||||
|
@ -17,7 +18,7 @@ import { componentMapType } from "./DownloadClientForms";
|
|||
import { sleep } from "@utils";
|
||||
import { ImplementationBadges } from "@screens/settings/Indexer";
|
||||
import { FeedDownloadTypeOptions } from "@domain/constants";
|
||||
import { feedKeys } from "@screens/settings/Feed";
|
||||
|
||||
|
||||
interface UpdateProps {
|
||||
isOpen: boolean;
|
||||
|
@ -50,7 +51,7 @@ export function FeedUpdateForm({ isOpen, toggle, feed }: UpdateProps) {
|
|||
const mutation = useMutation({
|
||||
mutationFn: (feed: Feed) => APIClient.feeds.update(feed),
|
||||
onSuccess: () => {
|
||||
queryClient.invalidateQueries({ queryKey: feedKeys.lists() });
|
||||
queryClient.invalidateQueries({ queryKey: FeedKeys.lists() });
|
||||
|
||||
toast.custom((t) => <Toast type="success" body={`${feed.name} was updated successfully`} t={t} />);
|
||||
toggle();
|
||||
|
@ -62,7 +63,7 @@ export function FeedUpdateForm({ isOpen, toggle, feed }: UpdateProps) {
|
|||
const deleteMutation = useMutation({
|
||||
mutationFn: (feedID: number) => APIClient.feeds.delete(feedID),
|
||||
onSuccess: () => {
|
||||
queryClient.invalidateQueries({ queryKey: feedKeys.lists() });
|
||||
queryClient.invalidateQueries({ queryKey: FeedKeys.lists() });
|
||||
|
||||
toast.custom((t) => <Toast type="success" body={`${feed.name} was deleted.`} t={t} />);
|
||||
}
|
||||
|
|
|
@ -15,13 +15,13 @@ import { Dialog, Transition } from "@headlessui/react";
|
|||
import { classNames, sleep } from "@utils";
|
||||
import { DEBUG } from "@components/debug";
|
||||
import { APIClient } from "@api/APIClient";
|
||||
import { FeedKeys, IndexerKeys, ReleaseKeys } from "@api/query_keys";
|
||||
import { IndexersSchemaQueryOptions } from "@api/queries";
|
||||
import { SlideOver } from "@components/panels";
|
||||
import Toast from "@components/notifications/Toast";
|
||||
import { PasswordFieldWide, SwitchGroupWide, TextFieldWide } from "@components/inputs";
|
||||
import { SelectFieldBasic, SelectFieldCreatable } from "@components/inputs/select_wide";
|
||||
import { FeedDownloadTypeOptions } from "@domain/constants";
|
||||
import { feedKeys } from "@screens/settings/Feed";
|
||||
import { indexerKeys } from "@screens/settings/Indexer";
|
||||
import { DocsLink } from "@components/ExternalLink";
|
||||
import * as common from "@components/inputs/common";
|
||||
|
||||
|
@ -263,17 +263,14 @@ export function IndexerAddForm({ isOpen, toggle }: AddProps) {
|
|||
const [indexer, setIndexer] = useState<IndexerDefinition>({} as IndexerDefinition);
|
||||
|
||||
const queryClient = useQueryClient();
|
||||
const { data } = useQuery({
|
||||
queryKey: ["indexerDefinition"],
|
||||
queryFn: APIClient.indexers.getSchema,
|
||||
enabled: isOpen,
|
||||
refetchOnWindowFocus: false
|
||||
});
|
||||
const { data } = useQuery(IndexersSchemaQueryOptions(isOpen));
|
||||
|
||||
const mutation = useMutation({
|
||||
mutationFn: (indexer: Indexer) => APIClient.indexers.create(indexer),
|
||||
onSuccess: () => {
|
||||
queryClient.invalidateQueries({ queryKey: indexerKeys.lists() });
|
||||
queryClient.invalidateQueries({ queryKey: IndexerKeys.lists() });
|
||||
queryClient.invalidateQueries({ queryKey: IndexerKeys.options() });
|
||||
queryClient.invalidateQueries({ queryKey: ReleaseKeys.indexers() });
|
||||
|
||||
toast.custom((t) => <Toast type="success" body="Indexer was added" t={t} />);
|
||||
sleep(1500);
|
||||
|
@ -291,7 +288,7 @@ export function IndexerAddForm({ isOpen, toggle }: AddProps) {
|
|||
const feedMutation = useMutation({
|
||||
mutationFn: (feed: FeedCreate) => APIClient.feeds.create(feed),
|
||||
onSuccess: () => {
|
||||
queryClient.invalidateQueries({ queryKey: feedKeys.lists() });
|
||||
queryClient.invalidateQueries({ queryKey: FeedKeys.lists() });
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -738,7 +735,7 @@ export function IndexerUpdateForm({ isOpen, toggle, indexer }: UpdateProps) {
|
|||
const mutation = useMutation({
|
||||
mutationFn: (indexer: Indexer) => APIClient.indexers.update(indexer),
|
||||
onSuccess: () => {
|
||||
queryClient.invalidateQueries({ queryKey: indexerKeys.lists() });
|
||||
queryClient.invalidateQueries({ queryKey: IndexerKeys.lists() });
|
||||
|
||||
toast.custom((t) => <Toast type="success" body={`${indexer.name} was updated successfully`} t={t} />);
|
||||
sleep(1500);
|
||||
|
@ -755,7 +752,9 @@ export function IndexerUpdateForm({ isOpen, toggle, indexer }: UpdateProps) {
|
|||
const deleteMutation = useMutation({
|
||||
mutationFn: (id: number) => APIClient.indexers.delete(id),
|
||||
onSuccess: () => {
|
||||
queryClient.invalidateQueries({ queryKey: indexerKeys.lists() });
|
||||
queryClient.invalidateQueries({ queryKey: IndexerKeys.lists() });
|
||||
queryClient.invalidateQueries({ queryKey: IndexerKeys.options() });
|
||||
queryClient.invalidateQueries({ queryKey: ReleaseKeys.indexers() });
|
||||
|
||||
toast.custom((t) => <Toast type="success" body={`${indexer.name} was deleted.`} t={t} />);
|
||||
|
||||
|
|
|
@ -14,8 +14,8 @@ import Select from "react-select";
|
|||
import { Dialog } from "@headlessui/react";
|
||||
|
||||
import { IrcAuthMechanismTypeOptions, OptionBasicTyped } from "@domain/constants";
|
||||
import { ircKeys } from "@screens/settings/Irc";
|
||||
import { APIClient } from "@api/APIClient";
|
||||
import { IrcKeys } from "@api/query_keys";
|
||||
import { NumberFieldWide, PasswordFieldWide, SwitchGroupWide, TextFieldWide } from "@components/inputs";
|
||||
import { SlideOver } from "@components/panels";
|
||||
import Toast from "@components/notifications/Toast";
|
||||
|
@ -132,7 +132,7 @@ export function IrcNetworkAddForm({ isOpen, toggle }: AddFormProps) {
|
|||
const mutation = useMutation({
|
||||
mutationFn: (network: IrcNetwork) => APIClient.irc.createNetwork(network),
|
||||
onSuccess: () => {
|
||||
queryClient.invalidateQueries({ queryKey: ircKeys.lists() });
|
||||
queryClient.invalidateQueries({ queryKey: IrcKeys.lists() });
|
||||
|
||||
toast.custom((t) => <Toast type="success" body="IRC Network added. Please allow up to 30 seconds for the network to come online." t={t} />);
|
||||
toggle();
|
||||
|
@ -288,7 +288,7 @@ export function IrcNetworkUpdateForm({
|
|||
const updateMutation = useMutation({
|
||||
mutationFn: (network: IrcNetwork) => APIClient.irc.updateNetwork(network),
|
||||
onSuccess: () => {
|
||||
queryClient.invalidateQueries({ queryKey: ircKeys.lists() });
|
||||
queryClient.invalidateQueries({ queryKey: IrcKeys.lists() });
|
||||
|
||||
toast.custom((t) => <Toast type="success" body={`${network.name} was updated successfully`} t={t} />);
|
||||
|
||||
|
@ -301,7 +301,7 @@ export function IrcNetworkUpdateForm({
|
|||
const deleteMutation = useMutation({
|
||||
mutationFn: (id: number) => APIClient.irc.deleteNetwork(id),
|
||||
onSuccess: () => {
|
||||
queryClient.invalidateQueries({ queryKey: ircKeys.lists() });
|
||||
queryClient.invalidateQueries({ queryKey: IrcKeys.lists() });
|
||||
|
||||
toast.custom((t) => <Toast type="success" body={`${network.name} was deleted.`} t={t} />);
|
||||
|
||||
|
|
|
@ -13,7 +13,7 @@ import { useMutation, useQueryClient } from "@tanstack/react-query";
|
|||
import { toast } from "react-hot-toast";
|
||||
|
||||
import { APIClient } from "@api/APIClient";
|
||||
import { notificationKeys } from "@screens/settings/Notifications";
|
||||
import { NotificationKeys } from "@api/query_keys";
|
||||
import { EventOptions, NotificationTypeOptions, SelectOption } from "@domain/constants";
|
||||
import { DEBUG } from "@components/debug";
|
||||
import { SlideOver } from "@components/panels";
|
||||
|
@ -294,7 +294,7 @@ export function NotificationAddForm({ isOpen, toggle }: AddProps) {
|
|||
const createMutation = useMutation({
|
||||
mutationFn: (notification: ServiceNotification) => APIClient.notifications.create(notification),
|
||||
onSuccess: () => {
|
||||
queryClient.invalidateQueries({ queryKey: notificationKeys.lists() });
|
||||
queryClient.invalidateQueries({ queryKey: NotificationKeys.lists() });
|
||||
|
||||
toast.custom((t) => <Toast type="success" body="Notification added!" t={t} />);
|
||||
toggle();
|
||||
|
@ -565,7 +565,7 @@ export function NotificationUpdateForm({ isOpen, toggle, notification }: UpdateP
|
|||
const mutation = useMutation({
|
||||
mutationFn: (notification: ServiceNotification) => APIClient.notifications.update(notification),
|
||||
onSuccess: () => {
|
||||
queryClient.invalidateQueries({ queryKey: notificationKeys.lists() });
|
||||
queryClient.invalidateQueries({ queryKey: NotificationKeys.lists() });
|
||||
|
||||
toast.custom((t) => <Toast type="success" body={`${notification.name} was updated successfully`} t={t}/>);
|
||||
toggle();
|
||||
|
@ -577,7 +577,7 @@ export function NotificationUpdateForm({ isOpen, toggle, notification }: UpdateP
|
|||
const deleteMutation = useMutation({
|
||||
mutationFn: (notificationID: number) => APIClient.notifications.delete(notificationID),
|
||||
onSuccess: () => {
|
||||
queryClient.invalidateQueries({ queryKey: notificationKeys.lists() });
|
||||
queryClient.invalidateQueries({ queryKey: NotificationKeys.lists() });
|
||||
|
||||
toast.custom((t) => <Toast type="success" body={`${notification.name} was deleted.`} t={t}/>);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue