chore: add eslint and cleanup (#118)

* refactor: modified existing react imports to conform with the recommended approach of not using the default export directly, since it will be deprecated in one of the future releases. see https://reactjs.org/blog/2020/09/22/introducing-the-new-jsx-transform.html for more info. note: react types don't require importing of react.
refactor: cleaned up some of the imports

* feat: added eslint and fixed all the errors/warning. eslint can now be invoked by running "npm run lint".
chore: updated .gitignore not to include unnecessary artefacts.
refactor: re-organized some of the imports.

* refactor: converted remaining few typed functional components to proper prop argument structure.

* fix: fixed small react-query invalidation bug for the FilterDetails component.

Co-authored-by: anonymous <anonymous>
This commit is contained in:
stacksmash76 2022-02-08 18:10:47 +01:00 committed by GitHub
parent d1f08903d1
commit fe06363530
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
29 changed files with 463 additions and 343 deletions

View file

@ -1,14 +1,15 @@
import { Fragment, useEffect } from "react";
import { Fragment } from "react";
import { useMutation } from "react-query";
import { queryClient } from "../../App";
import { toast } from "react-hot-toast";
import { XIcon } from "@heroicons/react/solid";
import { Dialog, Transition } from "@headlessui/react";
import DEBUG from "../../components/debug";
import APIClient from "../../api/APIClient";
import { Field, Form, Formik } from "formik";
import type { FieldProps } from "formik";
import { toast } from 'react-hot-toast'
import { queryClient } from "../../App";
import APIClient from "../../api/APIClient";
import DEBUG from "../../components/debug";
import Toast from '../../components/notifications/Toast';
import { Field, FieldProps, Form, Formik } from "formik";
function FilterAddForm({ isOpen, toggle }: any) {
const mutation = useMutation((filter: Filter) => APIClient.filters.create(filter), {
@ -20,23 +21,8 @@ function FilterAddForm({ isOpen, toggle }: any) {
}
})
useEffect(() => {
// console.log("render add action form")
}, []);
const handleSubmit = (data: any) => {
mutation.mutate(data)
}
const validate = (values: any) => {
const errors = {} as any;
if (!values.name) {
errors.name = "Required";
}
return errors;
}
const handleSubmit = (data: any) => mutation.mutate(data);
const validate = (values: any) => values.name ? {} : { name: "Required" };
return (
<Transition.Root show={isOpen} as={Fragment}>

View file

@ -300,7 +300,7 @@ export function DownloadClientAddForm({ isOpen, toggle }: any) {
});
});
},
onError: (error) => {
onError: () => {
console.log('not added')
setIsTesting(false);
setIsErrorTest(true);
@ -319,7 +319,7 @@ export function DownloadClientAddForm({ isOpen, toggle }: any) {
testClientMutation.mutate(data);
};
let initialValues: InitialValues = {
const initialValues: InitialValues = {
name: "",
type: "QBITTORRENT",
enabled: true,
@ -480,7 +480,7 @@ export function DownloadClientUpdateForm({ client, isOpen, toggle }: any) {
});
});
},
onError: (error) => {
onError: () => {
setIsTesting(false);
setIsErrorTest(true);
sleep(2500).then(() => {
@ -505,7 +505,7 @@ export function DownloadClientUpdateForm({ client, isOpen, toggle }: any) {
testClientMutation.mutate(data);
};
let initialValues = {
const initialValues = {
id: client.id,
name: client.name,
type: client.type,

View file

@ -1,18 +1,24 @@
import { Fragment } from "react";
import { toast } from "react-hot-toast";
import { useMutation, useQuery } from "react-query";
import { sleep } from "../../utils";
import Select, { components } from "react-select";
import { Field, Form, Formik } from "formik";
import type { FieldProps } from "formik";
import { XIcon } from "@heroicons/react/solid";
import { Dialog, Transition } from "@headlessui/react";
import { Field, FieldProps, Form, Formik } from "formik";
import DEBUG from "../../components/debug";
import Select, { components } from "react-select";
import { queryClient } from "../../App";
import APIClient from "../../api/APIClient";
import { TextFieldWide, PasswordFieldWide, SwitchGroupWide } from "../../components/inputs/input_wide";
import { toast } from 'react-hot-toast'
import Toast from '../../components/notifications/Toast';
import { sleep } from "../../utils";
import { queryClient } from "../../App";
import DEBUG from "../../components/debug";
import APIClient from "../../api/APIClient";
import {
TextFieldWide,
PasswordFieldWide,
SwitchGroupWide
} from "../../components/inputs/input_wide";
import { SlideOver } from "../../components/panels";
import Toast from '../../components/notifications/Toast';
const Input = (props: any) => {
return (
@ -67,28 +73,19 @@ export function IndexerAddForm({ isOpen, toggle }: AddProps) {
}
})
const ircMutation = useMutation((network: Network) => APIClient.irc.createNetwork(network), {
onSuccess: (data) => {
// console.log("irc mutation: ", data);
// queryClient.invalidateQueries(['networks']);
// sleep(1500)
// toggle()
}
})
const ircMutation = useMutation(
(network: Network) => APIClient.irc.createNetwork(network)
);
const onSubmit = (formData: any) => {
let ind = data && data.find(i => i.identifier === formData.identifier)
const ind = data && data.find(i => i.identifier === formData.identifier);
if (!ind)
return;
if (!ind) {
return
}
let channels: Channel[] = []
const channels: Channel[] = [];
if (ind.irc.channels.length) {
ind.irc.channels.forEach(element => {
channels.push({ name: element, password: "" })
channels.push({ name: element, password: "" });
});
}
@ -105,17 +102,13 @@ export function IndexerAddForm({ isOpen, toggle }: AddProps) {
}
mutation.mutate(formData, {
onSuccess: (data) => {
// create irc
ircMutation.mutate(network)
}
})
onSuccess: () => ircMutation.mutate(network)
});
};
const renderSettingFields = (indexer: string) => {
if (indexer !== "") {
let ind = data && data.find(i => i.identifier === indexer)
const ind = data && data.find(i => i.identifier === indexer);
return (
<div key="opt">
{ind && ind.settings && ind.settings.map((f: any, idx: number) => {
@ -140,10 +133,8 @@ export function IndexerAddForm({ isOpen, toggle }: AddProps) {
}
const renderIrcSettingFields = (indexer: string) => {
if (indexer !== "") {
let ind = data && data.find(i => i.identifier === indexer)
const ind = data && data.find(i => i.identifier === indexer);
return (
<Fragment>
{ind && ind.irc && ind.irc.settings && (
@ -366,7 +357,7 @@ export function IndexerUpdateForm({ isOpen, toggle, indexer }: UpdateProps) {
)
}
let initialValues = {
const initialValues = {
id: indexer.id,
name: indexer.name,
enabled: indexer.enabled,
@ -390,7 +381,7 @@ export function IndexerUpdateForm({ isOpen, toggle, indexer }: UpdateProps) {
onSubmit={onSubmit}
initialValues={initialValues}
>
{({ values }: any) => (
{() => (
<div className="py-6 space-y-6 sm:py-0 sm:space-y-0 divide-y divide-gray-200 dark:divide-gray-700">
<div className="space-y-1 px-4 sm:space-y-0 sm:grid sm:grid-cols-3 sm:gap-4 sm:px-6 sm:py-5">
<div>

View file

@ -1,15 +1,20 @@
import { useMutation } from "react-query";
import { toast } from "react-hot-toast";
import { XIcon } from "@heroicons/react/solid";
import { queryClient } from "../../App";
import { Field, FieldArray } from "formik";
import type { FieldProps } from "formik";
import { Field, FieldArray, FieldProps } from "formik";
import { queryClient } from "../../App";
import APIClient from "../../api/APIClient";
import { TextFieldWide, PasswordFieldWide, SwitchGroupWide, NumberFieldWide } from "../../components/inputs/input_wide";
import { toast } from 'react-hot-toast';
import Toast from '../../components/notifications/Toast';
import {
TextFieldWide,
PasswordFieldWide,
SwitchGroupWide,
NumberFieldWide
} from "../../components/inputs/input_wide";
import { SlideOver } from "../../components/panels";
import Toast from '../../components/notifications/Toast';
function ChannelsFieldArray({ values }: any) {
return (
@ -79,7 +84,7 @@ function ChannelsFieldArray({ values }: any) {
export function IrcNetworkAddForm({ isOpen, toggle }: any) {
const mutation = useMutation((network: Network) => APIClient.irc.createNetwork(network), {
onSuccess: (data) => {
onSuccess: () => {
queryClient.invalidateQueries(['networks']);
toast.custom((t) => <Toast type="success" body="IRC Network added" t={t} />)
toggle()
@ -92,11 +97,15 @@ export function IrcNetworkAddForm({ isOpen, toggle }: any) {
const onSubmit = (data: any) => {
// easy way to split textarea lines into array of strings for each newline.
// parse on the field didn't really work.
let cmds = data.connect_commands && data.connect_commands.length > 0 ? data.connect_commands.replace(/\r\n/g, "\n").split("\n") : [];
data.connect_commands = cmds
console.log("formated", data)
const cmds = (
data.connect_commands && data.connect_commands.length > 0 ?
data.connect_commands.replace(/\r\n/g, "\n").split("\n") :
[]
);
data.connect_commands = cmds;
console.log("formated", data);
mutation.mutate(data)
mutation.mutate(data);
};
const validate = (values: any) => {