88} from "common/format/upload" ;
99import { ManageCaveParams , ManageCaveResponse } from "common/modals/types" ;
1010import { actionForGame } from "common/util/action-for-game" ;
11- import { Dispatch } from "common/types" ;
1211import { ambientWind } from "common/util/navigation" ;
1312import React from "react" ;
1413import Button from "renderer/basics/Button" ;
@@ -18,7 +17,7 @@ import LastPlayed from "renderer/basics/LastPlayed";
1817import TimeAgo from "renderer/basics/TimeAgo" ;
1918import TotalPlaytime from "renderer/basics/TotalPlaytime" ;
2019import UploadIcon from "renderer/basics/UploadIcon" ;
21- import { hook } from "renderer/hocs/hook " ;
20+ import { useAppDispatch } from "renderer/hooks/redux " ;
2221import CaveLaunchSettings from "renderer/modal-widgets/CaveLaunchSettings" ;
2322import { ModalWidgetDiv } from "renderer/modal-widgets/styles" ;
2423import styled , * as styles from "renderer/styles" ;
@@ -148,24 +147,68 @@ const ManageCaveDiv = styled(ModalWidgetDiv)`
148147 max-width: 90vw;
149148` ;
150149
151- class ManageCave extends React . PureComponent < Props > {
152- override render ( ) {
153- return < ManageCaveDiv > { this . renderCave ( ) } </ ManageCaveDiv > ;
154- }
150+ const UploadTitle = ( { upload } : { upload : Upload } ) => (
151+ < >
152+ < UploadIcon upload = { upload } />
153+ < Spacer />
154+ { formatUploadTitle ( upload ) }
155+ </ >
156+ ) ;
157+
158+ type Props = ModalWidgetProps < ManageCaveParams , ManageCaveResponse > ;
159+
160+ const ManageCave = ( { modal } : Props ) => {
161+ const dispatch = useAppDispatch ( ) ;
162+ const { cave, fromManageGame } = modal . widgetParams ;
163+ const { game } = cave ;
164+ const caveId = cave . id ;
165+
166+ // closes the dialog, then does something with the install
167+ const closeAnd = (
168+ action : Parameters < typeof actions . closeModal > [ 0 ] [ "action" ]
169+ ) => {
170+ dispatch ( actions . closeModal ( { wind : ambientWind ( ) , action } ) ) ;
171+ } ;
172+
173+ const onSwitchVersion = ( ) =>
174+ closeAnd ( actions . switchVersionCaveRequest ( { cave } ) ) ;
175+ const onUninstall = ( ) => closeAnd ( actions . queueCaveUninstall ( { caveId } ) ) ;
176+ const onReinstall = ( ) => closeAnd ( actions . queueCaveReinstall ( { caveId } ) ) ;
177+ const onUpdateCheck = ( ) =>
178+ closeAnd (
179+ actions . checkForGameUpdate ( { caveId, suppressNotification : false } )
180+ ) ;
181+
182+ const onClose = ( ) => {
183+ dispatch ( actions . closeModal ( { wind : modal . wind , id : modal . id } ) ) ;
184+ } ;
185+
186+ const onBack = ( ) => {
187+ dispatch (
188+ actions . closeModal ( {
189+ wind : modal . wind ,
190+ id : modal . id ,
191+ action : actions . manageGame ( { game } ) ,
192+ } )
193+ ) ;
194+ } ;
195+
196+ const onExplore = ( ) => {
197+ dispatch ( actions . exploreCave ( { caveId } ) ) ;
198+ } ;
155199
156- renderCave ( ) : JSX . Element {
157- const { cave } = this . props . modal . widgetParams ;
158- const { game } = cave ;
159-
160- const u = cave . upload ;
161- const caveSummary = getCaveSummary ( cave ) ;
162- const hasLastPlayed = Boolean ( caveSummary . interaction ?. lastRunAt ) ;
163- // mirrors what TotalPlaytime renders — without this the grid would show a
164- // stopwatch icon with nothing next to it for a game that's never been played
165- const hasPlaytime =
166- ( caveSummary . interaction ?. secondsRun ?? 0 ) > 0 &&
167- actionForGame ( game , caveSummary ) === "launch" ;
168- return (
200+ const u = cave . upload ;
201+ const caveSummary = getCaveSummary ( cave ) ;
202+ const hasLastPlayed = Boolean ( caveSummary . interaction ?. lastRunAt ) ;
203+ // mirrors what TotalPlaytime renders — without this the grid would show a
204+ // stopwatch icon with nothing next to it for a game that's never been played
205+ const hasPlaytime =
206+ ( caveSummary . interaction ?. secondsRun ?? 0 ) > 0 &&
207+ actionForGame ( game , caveSummary ) === "launch" ;
208+ return (
209+ < ManageCaveDiv >
210+ { /* the dialog host reuses this widget when another install's dialog
211+ takes over, the key gives its launch settings a fresh start */ }
169212 < CaveItem key = { cave . id } >
170213 < div
171214 style = { {
@@ -178,7 +221,9 @@ class ManageCave extends React.PureComponent<Props> {
178221 >
179222 < CaveDetails >
180223 < CaveDetailsRow >
181- < Title > { formatUpload ( u ) } </ Title >
224+ < Title >
225+ < UploadTitle upload = { u } />
226+ </ Title >
182227 </ CaveDetailsRow >
183228 { cave . build ? (
184229 < >
@@ -238,7 +283,7 @@ class ManageCave extends React.PureComponent<Props> {
238283 </ div >
239284 </ div >
240285 < CaveItemBigActions >
241- < QuickAction type = "button" onClick = { this . onExplore } >
286+ < QuickAction type = "button" onClick = { onExplore } >
242287 < QuickActionIcon icon = "folder-open" />
243288 < QuickActionLabel >
244289 < QuickActionTitle > { T ( showInExplorerString ( ) ) } </ QuickActionTitle >
@@ -253,7 +298,7 @@ class ManageCave extends React.PureComponent<Props> {
253298 </ QuickActionSubtitle >
254299 </ QuickActionLabel >
255300 </ QuickAction >
256- < QuickAction type = "button" onClick = { this . onUpdateCheck } >
301+ < QuickAction type = "button" onClick = { onUpdateCheck } >
257302 < QuickActionIcon icon = "repeat" />
258303 < QuickActionLabel >
259304 < QuickActionTitle >
@@ -263,7 +308,7 @@ class ManageCave extends React.PureComponent<Props> {
263308 </ QuickAction >
264309
265310 { u && u . channelName !== "" ? (
266- < QuickAction type = "button" onClick = { this . onSwitchVersion } >
311+ < QuickAction type = "button" onClick = { onSwitchVersion } >
267312 < QuickActionIcon icon = "shuffle" />
268313 < QuickActionLabel >
269314 < QuickActionTitle >
@@ -275,119 +320,33 @@ class ManageCave extends React.PureComponent<Props> {
275320 </ CaveItemBigActions >
276321 < CaveLaunchSettings caveId = { cave . id } />
277322 < ModalButtons >
278- { this . props . modal . widgetParams . fromManageGame ? (
279- < Button icon = "arrow-left" onClick = { this . onBack } >
323+ { fromManageGame ? (
324+ < Button icon = "arrow-left" onClick = { onBack } >
280325 { T ( [ "prompt.action.back" ] ) }
281326 </ Button >
282327 ) : (
283- < Button onClick = { this . onClose } > { T ( [ "prompt.action.close" ] ) } </ Button >
328+ < Button onClick = { onClose } > { T ( [ "prompt.action.close" ] ) } </ Button >
284329 ) }
285330 < Filler />
286331 < Button
287332 icon = "repeat"
288- onClick = { this . onReinstall }
333+ onClick = { onReinstall }
289334 className = "manage-reinstall"
290335 >
291336 { T ( [ "prompt.uninstall.reinstall" ] ) }
292337 </ Button >
293338 < ModalButtonSpacer />
294339 < Button
295340 icon = "uninstall"
296- onClick = { this . onUninstall }
341+ onClick = { onUninstall }
297342 className = "manage-uninstall"
298343 >
299344 { T ( [ "prompt.uninstall.uninstall" ] ) }
300345 </ Button >
301346 </ ModalButtons >
302347 </ CaveItem >
303- ) ;
304- }
305-
306- onSwitchVersion = ( ev : React . MouseEvent < HTMLElement > ) => {
307- const cave = this . props . modal . widgetParams . cave ;
308- const { dispatch } = this . props ;
309- dispatch (
310- actions . closeModal ( {
311- wind : ambientWind ( ) ,
312- action : actions . switchVersionCaveRequest ( { cave } ) ,
313- } )
314- ) ;
315- } ;
316-
317- onClose = ( ) => {
318- const { dispatch } = this . props ;
319- const { wind, id } = this . props . modal ;
320- dispatch ( actions . closeModal ( { wind, id } ) ) ;
321- } ;
322-
323- onBack = ( ) => {
324- const { dispatch } = this . props ;
325- const { wind, id } = this . props . modal ;
326- const { game } = this . props . modal . widgetParams . cave ;
327- dispatch (
328- actions . closeModal ( {
329- wind,
330- id,
331- action : actions . manageGame ( { game } ) ,
332- } )
333- ) ;
334- } ;
335-
336- onUninstall = ( ev : React . MouseEvent < HTMLElement > ) => {
337- const caveId = this . props . modal . widgetParams . cave . id ;
338- const { dispatch } = this . props ;
339- dispatch (
340- actions . closeModal ( {
341- wind : ambientWind ( ) ,
342- action : actions . queueCaveUninstall ( { caveId } ) ,
343- } )
344- ) ;
345- } ;
346-
347- onReinstall = ( ev : React . MouseEvent < HTMLElement > ) => {
348- const caveId = this . props . modal . widgetParams . cave . id ;
349- const { dispatch } = this . props ;
350- dispatch (
351- actions . closeModal ( {
352- wind : ambientWind ( ) ,
353- action : actions . queueCaveReinstall ( { caveId } ) ,
354- } )
355- ) ;
356- } ;
357-
358- onUpdateCheck = ( ev : React . MouseEvent < HTMLElement > ) => {
359- const caveId = this . props . modal . widgetParams . cave . id ;
360- const { dispatch } = this . props ;
361- dispatch (
362- actions . closeModal ( {
363- wind : ambientWind ( ) ,
364- action : actions . checkForGameUpdate ( {
365- caveId,
366- suppressNotification : false ,
367- } ) ,
368- } )
369- ) ;
370- } ;
371-
372- onExplore = ( ev : React . MouseEvent < HTMLElement > ) => {
373- const caveId = this . props . modal . widgetParams . cave . id ;
374- const { dispatch } = this . props ;
375- dispatch ( actions . exploreCave ( { caveId } ) ) ;
376- } ;
377- }
378-
379- interface Props extends ModalWidgetProps < ManageCaveParams , ManageCaveResponse > {
380- dispatch : Dispatch ;
381- }
382-
383- export default hook ( ) ( ManageCave ) ;
384-
385- function formatUpload ( upload : Upload ) : JSX . Element {
386- return (
387- < >
388- < UploadIcon upload = { upload } />
389- < Spacer />
390- { formatUploadTitle ( upload ) }
391- </ >
348+ </ ManageCaveDiv >
392349 ) ;
393- }
350+ } ;
351+
352+ export default ManageCave ;
0 commit comments