From ddda9f8b970015b3d9bbc18d0ef79cb5ff368ea7 Mon Sep 17 00:00:00 2001 From: JensForstmann <19289807+JensForstmann@users.noreply.github.com> Date: Mon, 9 Oct 2023 16:41:12 +0200 Subject: [PATCH] Always refresh round backup files when opening the dialog --- frontend/src/components/MatchMapCard.tsx | 27 +++++++-- frontend/src/components/Modal.tsx | 16 +++--- frontend/src/components/RoundBackups.tsx | 71 +++++++++--------------- 3 files changed, 59 insertions(+), 55 deletions(-) diff --git a/frontend/src/components/MatchMapCard.tsx b/frontend/src/components/MatchMapCard.tsx index c6214dd..f952b94 100644 --- a/frontend/src/components/MatchMapCard.tsx +++ b/frontend/src/components/MatchMapCard.tsx @@ -1,4 +1,4 @@ -import { Component } from 'solid-js'; +import { Component, createSignal } from 'solid-js'; import { IMatchMap, IMatchMapUpdateDto, @@ -50,6 +50,21 @@ export const MatchMapCard: Component<{ _switchTeamInternals: true, }); }; + const [roundBackupFiles, setRoundBackupFiles] = createSignal(); + const loadRoundBackupFiles = async () => { + const resp = await fetcher<{ latestFiles: string[]; total: number }>( + 'GET', + `/api/matches/${props.match.id}/server/round_backups?count=15` + ); + if (resp) { + setRoundBackupFiles(resp.latestFiles); + } + }; + const openRoundBackup = () => { + loadRoundBackupFiles(); + modalRef?.showModal(); + }; + let modalRef: HTMLDialogElement | undefined; const teamA = () => { @@ -78,7 +93,7 @@ export const MatchMapCard: Component<{ [t('change map name'), changeMapName], [t('change map state'), changeMapState], props.match.currentMap === props.mapIndex - ? [t('load round backup'), () => modalRef?.showModal()] + ? [t('load round backup'), openRoundBackup] : [t('switch to this map'), mustConfirm(loadThisMap)], [t('switch team internals'), switchTeamInternals], ]} @@ -100,10 +115,14 @@ export const MatchMapCard: Component<{

{t(props.map.state)}

- + setRoundBackupFiles(undefined)}>

{t('Load Round Backup')}

- modalRef?.close()} /> + modalRef?.close()} + roundBackupFiles={roundBackupFiles()} + />
diff --git a/frontend/src/components/Modal.tsx b/frontend/src/components/Modal.tsx index 4cfceec..fdd1a3f 100644 --- a/frontend/src/components/Modal.tsx +++ b/frontend/src/components/Modal.tsx @@ -1,12 +1,14 @@ -import { Component, JSX } from 'solid-js'; +import { Component, ComponentProps, JSX, splitProps } from 'solid-js'; import { t } from '../utils/locale'; -export const Modal: Component<{ - children: JSX.Element; - ref?: HTMLDialogElement; -}> = (props) => { +export const Modal: Component< + ComponentProps<'dialog'> & { + children: JSX.Element; + } +> = (props) => { + const [local, others] = splitProps(props, ['children']); return ( - +