forked from SteamDeckHomebrew/decky-loader
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rebase warning messages on latest main
- Loading branch information
Marco Rodolfi
committed
Aug 9, 2024
1 parent
93b3919
commit 457e099
Showing
6 changed files
with
164 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
import { ConfirmModal } from '@decky/ui'; | ||
import { FC, useEffect, useState } from 'react'; | ||
import { FaExclamationTriangle } from 'react-icons/fa'; | ||
|
||
import TranslationHelper, { TranslationClass } from '../../utils/TranslationHelper'; | ||
import { WarnThirdPartyType } from '../../utils/globalTypes'; | ||
|
||
interface WarnThirdPartyProps { | ||
seconds?: number; | ||
type: WarnThirdPartyType; | ||
onOK(): void; | ||
onCancel(): void; | ||
closeModal?(): void; | ||
} | ||
|
||
const WarnThirdParty: FC<WarnThirdPartyProps> = ({ seconds = 5, type, onOK, onCancel, closeModal }) => { | ||
const [waitTimer, setWaitTimer] = useState(seconds); | ||
|
||
useEffect(() => { | ||
// exit early when we reach 0 | ||
if (waitTimer <= 0) return; | ||
|
||
// save intervalId to clear the interval when the | ||
// component re-renders | ||
const intervalId = setInterval(() => { | ||
setWaitTimer(waitTimer - 1); | ||
}, 1000); | ||
|
||
// clear interval on re-render to avoid memory leaks | ||
return () => clearInterval(intervalId); | ||
// add waitTimer as a dependency to re-rerun the effect | ||
// when we update it | ||
}, [waitTimer]); | ||
|
||
return ( | ||
<ConfirmModal | ||
bOKDisabled={waitTimer > 0} | ||
closeModal={closeModal} | ||
onOK={async () => { | ||
await onOK(); | ||
}} | ||
onCancel={async () => { | ||
await onCancel(); | ||
}} | ||
strTitle={ | ||
<div> | ||
<FaExclamationTriangle /> | ||
<TranslationHelper transClass={TranslationClass.WARN_THIRD_PARTY} transText="title" warnType={type} /> | ||
</div> | ||
} | ||
strOKButtonText={ | ||
waitTimer > 0 ? ( | ||
<div> | ||
<TranslationHelper | ||
transClass={TranslationClass.WARN_THIRD_PARTY} | ||
transText="button_processing" | ||
i18nArgs={{ | ||
timer: waitTimer, | ||
}} | ||
/> | ||
</div> | ||
) : ( | ||
<div> | ||
<TranslationHelper transClass={TranslationClass.WARN_THIRD_PARTY} transText="button_idle" /> | ||
</div> | ||
) | ||
} | ||
> | ||
<span style={{ color: 'red' }}> | ||
<div> | ||
<TranslationHelper transClass={TranslationClass.WARN_THIRD_PARTY} transText="desc" warnType={type} /> | ||
</div> | ||
</span> | ||
</ConfirmModal> | ||
); | ||
}; | ||
|
||
export default WarnThirdParty; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export enum WarnThirdPartyType { | ||
REPO = 0, | ||
ZIP = 1, | ||
} |