fix(web): unauthorized errors (#320)

- fix(ErrorPage): add padding to the page for mobile devices

- chore(react-query): wrap APIClient calls in anonymous functions to avoid passing react-query context variables by accident

- fix incorrect ordering of ErrorBoundary and QueryClientProvider (ErrorBoundary is now the parent)
This commit is contained in:
stacksmash76 2022-06-22 22:26:53 +02:00 committed by GitHub
parent aa500fd13d
commit c4efbd6e20
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 28 additions and 26 deletions

View file

@ -32,17 +32,17 @@ export function App() {
const settings = SettingsContext.useValue(); const settings = SettingsContext.useValue();
return ( return (
<QueryClientProvider client={queryClient}> <ErrorBoundary
<Toaster position="top-right" /> onReset={reset}
<ErrorBoundary fallbackRender={ErrorPage}
onReset={reset} >
fallbackRender={ErrorPage} <QueryClientProvider client={queryClient}>
> <Toaster position="top-right" />
<LocalRouter isLoggedIn={authContext.isLoggedIn} /> <LocalRouter isLoggedIn={authContext.isLoggedIn} />
{settings.debug ? ( {settings.debug ? (
<ReactQueryDevtools initialIsOpen={false} /> <ReactQueryDevtools initialIsOpen={false} />
) : null} ) : null}
</ErrorBoundary> </QueryClientProvider>
</QueryClientProvider> </ErrorBoundary>
); );
} }

View file

@ -13,7 +13,7 @@ export const ErrorPage = ({ error, resetErrorBoundary }: FallbackProps) => {
}); });
return ( return (
<div className="min-h-screen flex flex-col justify-center py-12 sm:px-6 lg:px-8"> <div className="min-h-screen flex flex-col justify-center py-12 px-2 sm:px-6 lg:px-8">
<div className="sm:mx-auto sm:w-full sm:max-w-screen-md md:max-w-screen-lg lg:max-w-screen-xl"> <div className="sm:mx-auto sm:w-full sm:max-w-screen-md md:max-w-screen-lg lg:max-w-screen-xl">
<h1 className="text-3xl font-bold leading-6 text-gray-900 dark:text-gray-200 mt-4 mb-3"> <h1 className="text-3xl font-bold leading-6 text-gray-900 dark:text-gray-200 mt-4 mb-3">
We caught an unrecoverable error! We caught an unrecoverable error!

View file

@ -173,7 +173,9 @@ interface AddProps {
export function IndexerAddForm({ isOpen, toggle }: AddProps) { export function IndexerAddForm({ isOpen, toggle }: AddProps) {
const [indexer, setIndexer] = useState<IndexerDefinition>({} as IndexerDefinition); const [indexer, setIndexer] = useState<IndexerDefinition>({} as IndexerDefinition);
const { data } = useQuery("indexerDefinition", APIClient.indexers.getSchema, const { data } = useQuery(
"indexerDefinition",
() => APIClient.indexers.getSchema(),
{ {
enabled: isOpen, enabled: isOpen,
refetchOnWindowFocus: false refetchOnWindowFocus: false

View file

@ -34,7 +34,7 @@ export const Stats = () => {
return ( return (
<div> <div>
<h3 className="text-2xl font-medium leading-6 text-gray-900 dark:text-gray-200"> <h3 className="text-2xl font-medium leading-6 text-gray-900 dark:text-gray-200">
Stats Stats
</h3> </h3>
<dl className="grid grid-cols-1 gap-5 mt-5 sm:grid-cols-2 lg:grid-cols-3"> <dl className="grid grid-cols-1 gap-5 mt-5 sm:grid-cols-2 lg:grid-cols-3">

View file

@ -309,7 +309,7 @@ export default function FilterDetails() {
export function General() { export function General() {
const { isLoading, data: indexers } = useQuery( const { isLoading, data: indexers } = useQuery(
["filters", "indexer_list"], ["filters", "indexer_list"],
APIClient.indexers.getOptions, () => APIClient.indexers.getOptions(),
{ refetchOnWindowFocus: false } { refetchOnWindowFocus: false }
); );
@ -535,7 +535,7 @@ interface FilterActionsProps {
export function FilterActions({ filter, values }: FilterActionsProps) { export function FilterActions({ filter, values }: FilterActionsProps) {
const { data } = useQuery( const { data } = useQuery(
["filters", "download_clients"], ["filters", "download_clients"],
APIClient.download_clients.getAll, () => APIClient.download_clients.getAll(),
{ refetchOnWindowFocus: false } { refetchOnWindowFocus: false }
); );

View file

@ -24,7 +24,7 @@ export default function Filters() {
const { isLoading, error, data } = useQuery( const { isLoading, error, data } = useQuery(
["filters"], ["filters"],
APIClient.filters.getAll, () => APIClient.filters.getAll(),
{ refetchOnWindowFocus: false } { refetchOnWindowFocus: false }
); );

View file

@ -78,7 +78,7 @@ function DownloadClientSettings() {
const { error, data } = useQuery( const { error, data } = useQuery(
"downloadClients", "downloadClients",
APIClient.download_clients.getAll, () => APIClient.download_clients.getAll(),
{ refetchOnWindowFocus: false } { refetchOnWindowFocus: false }
); );

View file

@ -20,10 +20,10 @@ import { EmptySimple } from "../../components/emptystates";
import { componentMapType } from "../../forms/settings/DownloadClientForms"; import { componentMapType } from "../../forms/settings/DownloadClientForms";
function FeedSettings() { function FeedSettings() {
const { data } = useQuery<Feed[], Error>("feeds", APIClient.feeds.find, const { data } = useQuery(
{ "feeds",
refetchOnWindowFocus: false () => APIClient.feeds.find(),
} { refetchOnWindowFocus: false }
); );
return ( return (

View file

@ -74,7 +74,7 @@ function IndexerSettings() {
const { error, data } = useQuery( const { error, data } = useQuery(
"indexer", "indexer",
APIClient.indexers.getAll, () => APIClient.indexers.getAll(),
{ refetchOnWindowFocus: false } { refetchOnWindowFocus: false }
); );
@ -137,7 +137,7 @@ function IndexerSettings() {
</tr> </tr>
</thead> </thead>
<tbody className="light:bg-white divide-y divide-gray-200 dark:divide-gray-700"> <tbody className="light:bg-white divide-y divide-gray-200 dark:divide-gray-700">
{data && data.map((indexer: IndexerDefinition, idx: number) => ( {data.map((indexer, idx) => (
<ListItem indexer={indexer} key={idx} /> <ListItem indexer={indexer} key={idx} />
))} ))}
</tbody> </tbody>

View file

@ -17,7 +17,7 @@ export const IrcSettings = () => {
const { data } = useQuery( const { data } = useQuery(
"networks", "networks",
APIClient.irc.getNetworks, () => APIClient.irc.getNetworks(),
{ {
refetchOnWindowFocus: false, refetchOnWindowFocus: false,
// Refetch every 3 seconds // Refetch every 3 seconds

View file

@ -10,10 +10,10 @@ import { componentMapType } from "../../forms/settings/DownloadClientForms";
function NotificationSettings() { function NotificationSettings() {
const [addNotificationsIsOpen, toggleAddNotifications] = useToggle(false); const [addNotificationsIsOpen, toggleAddNotifications] = useToggle(false);
const { data } = useQuery<Notification[], Error>("notifications", APIClient.notifications.getAll, const { data } = useQuery(
{ "notifications",
refetchOnWindowFocus: false () => APIClient.notifications.getAll(),
} { refetchOnWindowFocus: false }
); );
return ( return (