Skip to content

Commit

Permalink
fix(ui): Added feedback to the manual rule & collection handling buttons
Browse files Browse the repository at this point in the history
  • Loading branch information
jorenn92 committed Jan 19, 2024
1 parent 6233b71 commit f1183c0
Show file tree
Hide file tree
Showing 6 changed files with 81 additions and 42 deletions.
4 changes: 1 addition & 3 deletions server/src/modules/api/lib/plextvApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,9 +167,7 @@ export class PlexTvApi extends ExternalApiService {
responseType: 'text',
});

const parsedXml = (await parseStringPromise(
response,
)) as UsersResponse;
const parsedXml = (await parseStringPromise(response)) as UsersResponse;
return parsedXml;
}

Expand Down
9 changes: 9 additions & 0 deletions ui/src/components/Collection/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import CollectionDetail from './CollectionDetail'
import CollectionOverview from './CollectionOverview'
import { EPlexDataType } from '../../utils/PlexDataType-enum'
import { IPlexMetadata } from '../Overview/Content'
import { useToasts } from 'react-toast-notifications'

export interface ICollection {
id?: number
Expand Down Expand Up @@ -47,6 +48,7 @@ const Collection = () => {
}>({ open: false, collection: undefined })
const [library, setLibrary] = useState<ILibrary>()
const [collections, setCollections] = useState<ICollection[]>()
const { addToast } = useToasts()

useEffect(() => {
document.title = 'Maintainerr - Collections'
Expand Down Expand Up @@ -74,6 +76,13 @@ const Collection = () => {

const doActions = () => {
PostApiHandler('/collections/handle', {})
addToast(
'Initiated collection handling in the background, Consult the logs for status updates.',
{
autoDismiss: true,
appearance: 'success',
},
)
}

const openDetail = (collection: ICollection) => {
Expand Down
4 changes: 2 additions & 2 deletions ui/src/components/Common/AddButton/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ const AddButton = (props: IAddButton) => {
className="add-button bg-amber-600 hover:bg-amber-500 flex m-auto h-9 rounded text-zinc-200 shadow-md"
onClick={props.onClick}
>
{<PlusCircleIcon className="m-auto h-5 ml-5" />}
<p className="m-auto rules-button-text ml-1 mr-5">{props.text}</p>
{<PlusCircleIcon className="m-auto h-5 ml-4" />}
<p className="m-auto rules-button-text ml-1 mr-4">{props.text}</p>
</button>
)
}
Expand Down
25 changes: 22 additions & 3 deletions ui/src/components/Common/ExecuteButton/index.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,37 @@
import { PlayIcon } from '@heroicons/react/solid'
import { useEffect, useState } from 'react'
import { SmallLoadingSpinner } from '../LoadingSpinner'

interface IExecuteButton {
text: string
onClick: () => void
}

const ExecuteButton = (props: IExecuteButton) => {
const [clicked, setClicked] = useState(false)

useEffect(() => {
setTimeout(() => {
setClicked(false)
}, 10000)
}, [clicked])
const onClick = () => {
setClicked(true)
props.onClick()
}

return (
<button
className="edit-button flex m-auto rounded h-9 text-zinc-200 shadow-md"
onClick={props.onClick}
disabled={clicked}
onClick={onClick}
>
{<PlayIcon className="m-auto h-5 ml-5" />}{' '}
<p className="m-auto rules-button-text ml-1 mr-5">{props.text}</p>
{clicked ? (
<SmallLoadingSpinner className="h-5 m-auto ml-2" />
) : (
<PlayIcon className="m-auto h-5 ml-4" />
)}{' '}
<p className="m-auto rules-button-text ml-1 mr-4">{props.text}</p>
</button>
)
}
Expand Down
66 changes: 37 additions & 29 deletions ui/src/components/Common/LoadingSpinner/index.tsx
Original file line number Diff line number Diff line change
@@ -1,33 +1,41 @@
import React from 'react';
import React from 'react'

export const SmallLoadingSpinner: React.FC = () => {
interface SmallLoadingSpinnerProps {
className?: string
}

export const SmallLoadingSpinner: React.FC<SmallLoadingSpinnerProps> = (
props: SmallLoadingSpinnerProps,
) => {
return (
<div className="inset-0 flex h-full w-full items-center justify-center text-zinc-200">
<svg
className="h-10 w-10"
viewBox="0 0 38 38"
xmlns="http://www.w3.org/2000/svg"
stroke="currentColor"
>
<g fill="none" fillRule="evenodd">
<g transform="translate(1 1)" strokeWidth="2">
<circle strokeOpacity=".5" cx="18" cy="18" r="18" />
<path d="M36 18c0-9.94-8.06-18-18-18">
<animateTransform
attributeName="transform"
type="rotate"
from="0 18 18"
to="360 18 18"
dur="1s"
repeatCount="indefinite"
/>
</path>
<div className={`${props.className ? props.className : ''}`}>
<div className="inset-0 flex h-full w-full items-center justify-center text-zinc-200">
<svg
className={props.className ? props.className : 'h-10 w-10'}
viewBox="0 0 38 38"
xmlns="http://www.w3.org/2000/svg"
stroke="currentColor"
>
<g fill="none" fillRule="evenodd">
<g transform="translate(1 1)" strokeWidth="2">
<circle strokeOpacity=".5" cx="18" cy="18" r="18" />
<path d="M36 18c0-9.94-8.06-18-18-18">
<animateTransform
attributeName="transform"
type="rotate"
from="0 18 18"
to="360 18 18"
dur="1s"
repeatCount="indefinite"
/>
</path>
</g>
</g>
</g>
</svg>
</svg>
</div>
</div>
);
};
)
}

const LoadingSpinner: React.FC = () => {
return (
Expand Down Expand Up @@ -55,7 +63,7 @@ const LoadingSpinner: React.FC = () => {
</g>
</svg>
</div>
);
};
)
}

export default LoadingSpinner;
export default LoadingSpinner
15 changes: 10 additions & 5 deletions ui/src/components/Rules/index.tsx
Original file line number Diff line number Diff line change
@@ -1,24 +1,22 @@
import { RefreshIcon } from '@heroicons/react/outline'
import { PlayIcon } from '@heroicons/react/solid'
import { debounce } from 'lodash'
import React, { useContext, useEffect, useState } from 'react'
import LibrariesContext from '../../contexts/libraries-context'
import React, { useEffect, useState } from 'react'
import GetApiHandler, { PostApiHandler } from '../../utils/ApiHandler'
import AddButton from '../Common/AddButton'
import ExecuteButton from '../Common/ExecuteButton'
import LibrarySwitcher from '../Common/LibrarySwitcher'
import LoadingSpinner from '../Common/LoadingSpinner'
import RuleGroup, { IRuleGroup } from './RuleGroup'
import AddModal from './RuleGroup/AddModal'
import { useToasts } from 'react-toast-notifications'

const Rules: React.FC = () => {
const [addModalActive, setAddModal] = useState(false)
const [editModalActive, setEditModal] = useState(false)
const [data, setData] = useState()
const [editData, setEditData] = useState<IRuleGroup>()
const LibrariesCtx = useContext(LibrariesContext)
const [selectedLibrary, setSelectedLibrary] = useState<number>(9999)
const [isLoading, setIsLoading] = useState(true)
const { addToast } = useToasts()

const fetchData = async () => {
if (selectedLibrary === 9999) return await GetApiHandler('/rules')
Expand Down Expand Up @@ -58,6 +56,13 @@ const Rules: React.FC = () => {

const sync = () => {
PostApiHandler(`/rules/execute`, {})
addToast(
'Initiated rule execution in the background. Consult the logs for status updates.',
{
autoDismiss: true,
appearance: 'success',
},
)
}

if (!data || isLoading) {
Expand Down

0 comments on commit f1183c0

Please sign in to comment.