Commit 98504417 authored by Stefan Probst's avatar Stefan Probst
Browse files

feat: add sources screen

parent 22c16dd3
Pipeline #208033 passed with stages
in 9 minutes and 12 seconds
import { Dialog } from '@reach/dialog'
import { Fragment, useState } from 'react'
import { Fragment } from 'react'
import type { MediaDetails } from '@/api/sshoc'
import { AddMediaForm as AddThumbnailForm } from '@/components/item/AddMediaForm/AddMediaForm'
import { Icon } from '@/elements/Icon/Icon'
import { Svg as CloseIcon } from '@/elements/icons/small/cross.svg'
import { MediaError } from '@/lib/error/MediaError'
import { useDialogState } from '@/lib/hooks/useDialogState'
import { FormFieldAddButton } from '@/modules/form/components/FormFieldAddButton/FormFieldAddButton'
import { FormSection } from '@/modules/form/components/FormSection/FormSection'
import { FormField } from '@/modules/form/FormField'
......@@ -98,17 +99,6 @@ export function ThumbnailFormSection(
)
}
function useDialogState(initialState = false) {
const [isOpen, setIsOpen] = useState(initialState)
function open() {
setIsOpen(true)
}
function close() {
setIsOpen(false)
}
return { isOpen, open, close }
}
interface DialogProps {
isOpen: boolean
onDismiss: () => void
......
<svg
xmlns="http://www.w3.org/2000/svg"
viewBox="0 0 14.619 14.745"
fill="currentColor"
>
<g transform="translate(-2 -2)">
<path
d="M12.49,10.857H11.6a5.517,5.517,0,0,0,1.256-3.431,5.439,5.439,0,1,0-2.12,4.3v.894l4.129,4.129,1.759-1.759Zm-5.064.287a3.719,3.719,0,1,1,3.719-3.719A3.719,3.719,0,0,1,7.426,11.144Z"
/>
</g>
</svg>
import { useState } from 'react'
/**
* Manages dialog state.
*/
export function useDialogState(
initialState = false,
): {
isOpen: boolean
open: () => void
close: () => void
toggle: () => void
} {
const [isOpen, setIsOpen] = useState(initialState)
function open() {
setIsOpen(true)
}
function close() {
setIsOpen(false)
}
function toggle() {
setIsOpen((isOpen) => !isOpen)
}
return { isOpen, open, close, toggle }
}
......@@ -31,6 +31,7 @@ const fields = [
label: 'Items to moderate',
pathname: '/account/moderate',
icon: ModerateItemsIcon,
roles: ['administrator', 'moderator'],
},
{
label: 'Sources',
......
......@@ -10,6 +10,7 @@ import { useGetLoggedInUser, useSearchItems } from '@/api/sshoc'
import type { ItemCategory, ItemSearchQuery } from '@/api/sshoc/types'
import { ProgressSpinner } from '@/elements/ProgressSpinner/ProgressSpinner'
import { Select } from '@/elements/Select/Select'
import { useToast } from '@/elements/Toast/useToast'
import { useAuth } from '@/modules/auth/AuthContext'
import ProtectedView from '@/modules/auth/ProtectedView'
import { useErrorHandlers } from '@/modules/error/useErrorHandlers'
......@@ -42,6 +43,7 @@ export default function ContributedItemsScreen(): JSX.Element {
const auth = useAuth()
const handleErrors = useErrorHandlers()
const toast = useToast()
const items = useSearchItems(
{
...query,
......@@ -56,6 +58,8 @@ export default function ContributedItemsScreen(): JSX.Element {
enabled: auth.session?.accessToken != null && user.data?.username != null,
keepPreviousData: true,
onError(error) {
toast.error('Failed to fetch contributed items')
if (error instanceof Error) {
handleErrors(error)
}
......
......@@ -10,6 +10,7 @@ import { useGetMyDraftItems } from '@/api/sshoc'
import type { ItemCategory } from '@/api/sshoc/types'
import { ProgressSpinner } from '@/elements/ProgressSpinner/ProgressSpinner'
import { Select } from '@/elements/Select/Select'
import { useToast } from '@/elements/Toast/useToast'
import { useAuth } from '@/modules/auth/AuthContext'
import ProtectedView from '@/modules/auth/ProtectedView'
import { useErrorHandlers } from '@/modules/error/useErrorHandlers'
......@@ -39,12 +40,15 @@ export default function DraftItemsScreen(): JSX.Element {
const auth = useAuth()
const handleErrors = useErrorHandlers()
const toast = useToast()
const items = useGetMyDraftItems(
query,
{
enabled: auth.session?.accessToken != null,
keepPreviousData: true,
onError(error) {
toast.error('Failed to fetch draft items')
if (error instanceof Error) {
handleErrors(error)
}
......
......@@ -10,6 +10,7 @@ import { useSearchItems } from '@/api/sshoc'
import type { ItemCategory, ItemSearchQuery } from '@/api/sshoc/types'
import { ProgressSpinner } from '@/elements/ProgressSpinner/ProgressSpinner'
import { Select } from '@/elements/Select/Select'
import { useToast } from '@/elements/Toast/useToast'
import { useAuth } from '@/modules/auth/AuthContext'
import ProtectedView from '@/modules/auth/ProtectedView'
import { useErrorHandlers } from '@/modules/error/useErrorHandlers'
......@@ -40,6 +41,7 @@ export default function ModerateItemsScreen(): JSX.Element {
const auth = useAuth()
const handleErrors = useErrorHandlers()
const toast = useToast()
const items = useSearchItems(
{
...query,
......@@ -51,6 +53,8 @@ export default function ModerateItemsScreen(): JSX.Element {
enabled: auth.session?.accessToken != null,
keepPreviousData: true,
onError(error) {
toast.error('Failed to fetch items to moderate')
if (error instanceof Error) {
handleErrors(error)
}
......
This diff is collapsed.
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment