-
-
Notifications
You must be signed in to change notification settings - Fork 187
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5032c0c
commit 87b0d27
Showing
4 changed files
with
72 additions
and
98 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -47,4 +47,4 @@ | |
"semver": "^7.6.0" | ||
}, | ||
"private": true | ||
} | ||
} |
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 |
---|---|---|
@@ -1,81 +1,61 @@ | ||
import { t } from "i18next"; | ||
import React from "react"; | ||
|
||
import { | ||
LATEST_RELEASE_URL, | ||
MARKETPLACE_VERSION, | ||
RELEASES_URL, | ||
} from "../../../constants"; | ||
import { LATEST_RELEASE_URL, MARKETPLACE_VERSION, RELEASES_URL } from "../../../constants"; | ||
import { getMarkdownHTML } from "../../../logic/Utils"; | ||
|
||
async function fetchLatestReleaseInfo(): Promise<{ | ||
version: string; | ||
changelog: string | null; | ||
version: string; | ||
changelog: string | null; | ||
} | null> { | ||
try { | ||
const result = await fetch(LATEST_RELEASE_URL); | ||
const resultJson = await result.json(); | ||
const { body, tag_name, message } = resultJson; | ||
return body && tag_name && !message | ||
? { | ||
version: tag_name.replace("v", ""), | ||
changelog: await getMarkdownHTML( | ||
body.match(/## What's Changed([\s\S]*?)(\r\n\r|\n\n##)/)[1], | ||
"spicetify", | ||
"marketplace", | ||
), | ||
} | ||
: null; | ||
} catch (error) { | ||
console.error(error); | ||
return null; | ||
} | ||
try { | ||
const result = await fetch(LATEST_RELEASE_URL); | ||
const resultJson = await result.json(); | ||
const { body, tag_name, message } = resultJson; | ||
return body && tag_name && !message | ||
? { | ||
version: tag_name.replace("v", ""), | ||
changelog: await getMarkdownHTML(body.match(/## What's Changed([\s\S]*?)(\r\n\r|\n\n##)/)[1], "spicetify", "marketplace") | ||
} | ||
: null; | ||
} catch (error) { | ||
console.error(error); | ||
return null; | ||
} | ||
} | ||
|
||
function UpdateModal(): React.ReactElement { | ||
const [releaseInfo, setReleaseInfo] = React.useState<{ | ||
version: string; | ||
changelog: string | null; | ||
} | null>(null); | ||
const [releaseInfo, setReleaseInfo] = React.useState<{ | ||
version: string; | ||
changelog: string | null; | ||
} | null>(null); | ||
|
||
React.useEffect(() => { | ||
fetchLatestReleaseInfo().then((releaseInfo) => setReleaseInfo(releaseInfo)); | ||
}, []); | ||
React.useEffect(() => { | ||
fetchLatestReleaseInfo().then((releaseInfo) => setReleaseInfo(releaseInfo)); | ||
}, []); | ||
|
||
return ( | ||
<div id="marketplace-update-container"> | ||
<div id="marketplace-update-description"> | ||
<h4>{t("updateModal.description")}</h4> | ||
<a href={`${RELEASES_URL}/tag/v${MARKETPLACE_VERSION}`}> | ||
{t("updateModal.currentVersion", { version: MARKETPLACE_VERSION })} | ||
</a> | ||
<a href={`${RELEASES_URL}/tag/v${releaseInfo?.version}`}> | ||
{t("updateModal.latestVersion", { version: releaseInfo?.version })} | ||
</a> | ||
</div> | ||
<hr /> | ||
<div id="marketplace-update-whats-changed"> | ||
<h3 className="marketplace-update-header"> | ||
{t("updateModal.whatsChanged")} | ||
</h3> | ||
<details> | ||
<summary>{t("updateModal.seeChangelog")}</summary> | ||
<ul | ||
dangerouslySetInnerHTML={{ __html: releaseInfo?.changelog ?? "" }} | ||
/> | ||
</details> | ||
</div> | ||
<hr /> | ||
<div id="marketplace-update-guide"> | ||
<h3 className="marketplace-update-header"> | ||
{t("updateModal.howToUpgrade")} | ||
</h3> | ||
<a href="https://github.com/spicetify/marketplace/wiki/Installation"> | ||
{t("updateModal.viewGuide")} | ||
</a> | ||
</div> | ||
</div> | ||
); | ||
return ( | ||
<div id="marketplace-update-container"> | ||
<div id="marketplace-update-description"> | ||
<h4>{t("updateModal.description")}</h4> | ||
<a href={`${RELEASES_URL}/tag/v${MARKETPLACE_VERSION}`}>{t("updateModal.currentVersion", { version: MARKETPLACE_VERSION })}</a> | ||
<a href={`${RELEASES_URL}/tag/v${releaseInfo?.version}`}>{t("updateModal.latestVersion", { version: releaseInfo?.version })}</a> | ||
</div> | ||
<hr /> | ||
<div id="marketplace-update-whats-changed"> | ||
<h3 className="marketplace-update-header">{t("updateModal.whatsChanged")}</h3> | ||
<details> | ||
<summary>{t("updateModal.seeChangelog")}</summary> | ||
<ul dangerouslySetInnerHTML={{ __html: releaseInfo?.changelog ?? "" }} /> | ||
</details> | ||
</div> | ||
<hr /> | ||
<div id="marketplace-update-guide"> | ||
<h3 className="marketplace-update-header">{t("updateModal.howToUpgrade")}</h3> | ||
<a href="https://github.com/spicetify/marketplace/wiki/Installation">{t("updateModal.viewGuide")}</a> | ||
</div> | ||
</div> | ||
); | ||
} | ||
|
||
export default UpdateModal; |
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