fix: refresh list on delete (#178)

This commit is contained in:
Nite Knite
2023-05-23 23:06:16 +08:00
committed by GitHub
parent e2bf18053c
commit 380b4b3ddc
4 changed files with 15 additions and 6 deletions

View File

@@ -16,10 +16,12 @@ import AppsContext from '@/context/app-context'
export type AppCardProps = {
app: App
onDelete?: () => void
}
const AppCard = ({
app,
onDelete
}: AppCardProps) => {
const { t } = useTranslation()
const { notify } = useContext(ToastContext)
@@ -35,6 +37,8 @@ const AppCard = ({
try {
await deleteApp(app.id)
notify({ type: 'success', message: t('app.appDeleted') })
if (onDelete)
onDelete()
mutateApps()
}
catch (e: any) {
@@ -47,7 +51,7 @@ const AppCard = ({
<>
<Link href={`/app/${app.id}/overview`} className={style.listItem}>
<div className={style.listItemTitle}>
<AppIcon size='small' icon={app.icon} background={app.icon_background}/>
<AppIcon size='small' icon={app.icon} background={app.icon_background} />
<div className={style.listItemHeading}>
<div className={style.listItemHeadingContent}>{app.name}</div>
</div>

View File

@@ -42,7 +42,9 @@ const Apps = () => {
return (
<nav className='grid content-start grid-cols-1 gap-4 px-12 pt-8 sm:grid-cols-2 lg:grid-cols-4 grow shrink-0'>
{data?.map(({ data: apps }) => apps.map(app => (<AppCard key={app.id} app={app} />)))}
{data?.map(({ data: apps }) => apps.map(app => (
<AppCard key={app.id} app={app} onDelete={mutate} />
)))}
<NewAppCard ref={anchorRef} onSuccess={mutate} />
</nav>
)