-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: Converted ReleaseNotes to ReleaseNotesModal
- Loading branch information
1 parent
69f55b8
commit bb3f884
Showing
6 changed files
with
125 additions
and
36 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
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,115 @@ | ||
/* eslint-disable promise/always-return */ | ||
/* eslint-disable react/no-danger */ | ||
/* eslint-disable react/prop-types */ | ||
/* eslint-disable react/jsx-props-no-spreading */ | ||
import { | ||
CircularProgress, | ||
Dialog, | ||
DialogContent, | ||
DialogTitle, | ||
Grid, | ||
Typography, | ||
useTheme, | ||
} from '@material-ui/core'; | ||
import { remote } from 'electron'; | ||
import { UpdateCheckResult, UpdateInfo } from 'electron-updater'; | ||
import React, { FC, useEffect, useState } from 'react'; | ||
import { ModalProps } from './ModalProvider'; | ||
|
||
type ReleaseNotesModalProps = ModalProps; | ||
|
||
const disableLinks = (str, theme) => { | ||
let result = ''; | ||
const temp = str.toString().split('\n'); | ||
if (temp) { | ||
const tempRest = temp.slice(1); | ||
result = tempRest | ||
.join('\n') | ||
.replaceAll( | ||
'<a href', | ||
`<span style='color:${theme.palette.text.disabled};' id` | ||
) | ||
.replaceAll('</a>', '</span>'); | ||
} | ||
return result; | ||
}; | ||
|
||
const ReleaseNotesModal: FC<ReleaseNotesModalProps> = ({ ...props }) => { | ||
const { close } = props; | ||
const theme = useTheme(); | ||
const [updateInfo, setUpdateInfo] = useState<UpdateInfo | undefined>(); | ||
const [loading, setLoading] = useState<boolean>(true); | ||
const info: Promise<UpdateCheckResult> = remote | ||
.require('electron-updater') | ||
.autoUpdater.checkForUpdates(); | ||
|
||
useEffect(() => { | ||
info | ||
.then((res: UpdateCheckResult) => { | ||
setUpdateInfo(res.updateInfo); | ||
setLoading(false); | ||
}) | ||
.catch(() => { | ||
setLoading(false); | ||
}); | ||
}, []); | ||
|
||
let content: JSX.Element; | ||
if (loading) { | ||
// Loading | ||
content = ( | ||
<DialogContent> | ||
<Grid | ||
container | ||
justify="center" | ||
alignItems="center" | ||
style={{ height: '200px' }} | ||
> | ||
<Grid item> | ||
<CircularProgress /> | ||
</Grid> | ||
</Grid> | ||
</DialogContent> | ||
); | ||
} else if (updateInfo) { | ||
// Update Info received | ||
content = ( | ||
<> | ||
<DialogTitle disableTypography> | ||
<Typography variant="h5">{`Version ${updateInfo?.version}`}</Typography> | ||
</DialogTitle> | ||
<DialogContent dividers> | ||
<div | ||
dangerouslySetInnerHTML={{ | ||
__html: disableLinks(updateInfo?.releaseNotes, theme), | ||
}} | ||
/> | ||
</DialogContent> | ||
</> | ||
); | ||
} else { | ||
// Error | ||
content = ( | ||
<DialogContent> | ||
<Grid | ||
container | ||
justify="center" | ||
alignItems="center" | ||
style={{ height: '200px' }} | ||
> | ||
<Grid item> | ||
<Typography>Error loading release notes!</Typography> | ||
</Grid> | ||
</Grid> | ||
</DialogContent> | ||
); | ||
} | ||
|
||
return ( | ||
<Dialog {...props} onClose={close} fullWidth> | ||
{content} | ||
</Dialog> | ||
); | ||
}; | ||
|
||
export default ReleaseNotesModal; |
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