From 6312dfbc71e0b9d1d0ff5ebb76d5f90deb7c4ad0 Mon Sep 17 00:00:00 2001 From: Misode Date: Wed, 9 Nov 2022 19:08:25 +0100 Subject: [PATCH] Add fixed bugs tab to versions --- src/app/components/Card.tsx | 2 +- src/app/components/versions/Issue.tsx | 15 +++++++++++ src/app/components/versions/IssueList.tsx | 23 ++++++++++++++++ src/app/components/versions/VersionDetail.tsx | 16 +++++++++--- src/app/components/versions/index.ts | 1 + src/app/pages/Versions.tsx | 6 +++-- src/app/services/DataFetcher.ts | 26 +++++++++++++++++++ src/locales/en.json | 2 ++ 8 files changed, 84 insertions(+), 7 deletions(-) create mode 100644 src/app/components/versions/Issue.tsx create mode 100644 src/app/components/versions/IssueList.tsx diff --git a/src/app/components/Card.tsx b/src/app/components/Card.tsx index 13ffc4ac..ee17ca09 100644 --- a/src/app/components/Card.tsx +++ b/src/app/components/Card.tsx @@ -17,5 +17,5 @@ export function Card({ title, overlay, link, children }: Props) { return link === undefined ?
{content}
- : {content} + : {content} } diff --git a/src/app/components/versions/Issue.tsx b/src/app/components/versions/Issue.tsx new file mode 100644 index 00000000..f9193ad0 --- /dev/null +++ b/src/app/components/versions/Issue.tsx @@ -0,0 +1,15 @@ +import type { Bugfix } from '../../services/DataFetcher.js' +import { Badge } from '../Badge.jsx' +import { Card } from '../Card.jsx' + +interface Props { + fix: Bugfix +} +export function Issue({ fix }: Props) { + return +
{fix.summary}
+
+ {fix.categories.map(c => )} +
+
+} diff --git a/src/app/components/versions/IssueList.tsx b/src/app/components/versions/IssueList.tsx new file mode 100644 index 00000000..2b49082f --- /dev/null +++ b/src/app/components/versions/IssueList.tsx @@ -0,0 +1,23 @@ +import { useLocale } from '../../contexts/Locale.jsx' +import { useAsync } from '../../hooks/useAsync.js' +import { fetchBugfixes } from '../../services/DataFetcher.js' +import type { VersionId } from '../../services/Schemas.js' +import { Issue } from './Issue.jsx' + +interface Props { + version: string +} +export function IssueList({ version }: Props) { + const { locale } = useLocale() + const { value: issues, loading } = useAsync(() => fetchBugfixes(version as VersionId), [version]) + + return
+ {issues === undefined || loading ? <> + {locale('loading')} + : issues.length === 0 ? <> + {locale('versions.fixes.no_results')} + : <> + {issues?.map(issue => )} + } +
+} diff --git a/src/app/components/versions/VersionDetail.tsx b/src/app/components/versions/VersionDetail.tsx index 522ed96b..eef39d1c 100644 --- a/src/app/components/versions/VersionDetail.tsx +++ b/src/app/components/versions/VersionDetail.tsx @@ -1,14 +1,15 @@ -import { useMemo, useState } from 'preact/hooks' +import { useEffect, useMemo } from 'preact/hooks' import { useLocale } from '../../contexts/index.js' import { useAsync } from '../../hooks/useAsync.js' +import { useSearchParam } from '../../hooks/useSearchParam.js' import type { VersionMeta } from '../../services/index.js' import { fetchChangelogs, getArticleLink } from '../../services/index.js' import { Giscus } from '../Giscus.js' import { Octicon } from '../Octicon.js' import { ChangelogList } from './ChangelogList.js' -import { VersionMetaData } from './index.js' +import { IssueList, VersionMetaData } from './index.js' -type Tab = 'changelog' | 'discussion' +const Tabs = ['changelog', 'discussion', 'fixes'] interface Props { id: string, @@ -17,7 +18,12 @@ interface Props { export function VersionDetail({ id, version }: Props) { const { locale } = useLocale() - const [tab, setTab] = useState('changelog') + const [tab, setTab] = useSearchParam('tab') + useEffect(() => { + if (tab === undefined || !Tabs.includes(tab)) { + setTab(Tabs[0]) + } + }, [tab]) const { value: changes } = useAsync(fetchChangelogs, []) @@ -47,6 +53,7 @@ export function VersionDetail({ id, version }: Props) {
setTab('changelog')}>{locale('versions.technical_changes')} setTab('discussion')}>{locale('versions.discussion')} + setTab('fixes')}>{locale('versions.fixes')} {articleLink && {locale('versions.article')} {Octicon.link_external} @@ -55,6 +62,7 @@ export function VersionDetail({ id, version }: Props) {
{tab === 'changelog' && } {tab === 'discussion' && } + {tab === 'fixes' && }
diff --git a/src/app/components/versions/index.ts b/src/app/components/versions/index.ts index 22b66a7f..1ffd2e69 100644 --- a/src/app/components/versions/index.ts +++ b/src/app/components/versions/index.ts @@ -1,6 +1,7 @@ export * from '../Badge.jsx' export * from './ChangelogEntry.js' export * from './ChangelogList.js' +export * from './IssueList.jsx' export * from './VersionDetail.js' export * from './VersionEntry.js' export * from './VersionList.js' diff --git a/src/app/pages/Versions.tsx b/src/app/pages/Versions.tsx index 374fb730..f8913941 100644 --- a/src/app/pages/Versions.tsx +++ b/src/app/pages/Versions.tsx @@ -14,6 +14,8 @@ export function Versions({}: Props) { const [selectedId] = useSearchParam('id') const selected = (versions ?? []).find(v => v.id === selectedId) + + const [tab] = useSearchParam('tab') useTitle( selected ? `Minecraft ${selected.name}` : 'Versions Explorer', @@ -29,9 +31,9 @@ export function Versions({}: Props) { {selectedId ? <> diff --git a/src/app/services/DataFetcher.ts b/src/app/services/DataFetcher.ts index 6caa08a5..6775e6da 100644 --- a/src/app/services/DataFetcher.ts +++ b/src/app/services/DataFetcher.ts @@ -18,6 +18,7 @@ const latestVersion = __LATEST_VERSION__ ?? '' const mcmetaUrl = 'https://raw.githubusercontent.com/misode/mcmeta' const mcmetaTarballUrl = 'https://github.com/misode/mcmeta/tarball' const changesUrl = 'https://raw.githubusercontent.com/misode/technical-changes' +const fixesUrl = 'https://raw.githubusercontent.com/misode/mcfixes' type McmetaTypes = 'summary' | 'data' | 'data-json' | 'assets' | 'assets-json' | 'registries' | 'atlas' @@ -235,6 +236,31 @@ export async function fetchChangelogs(): Promise { } } +export interface Bugfix { + id: string, + summary: string, + labels: string[], + status: string, + confirmation_status: string, + categories: string[], + priority: string, + fix_versions: string[], + creation_date: string, + resolution_date: string, + updated_date: string, + watches: number, + votes: number, +} + +export async function fetchBugfixes(version: VersionId): Promise { + try { + const fixes = await cachedFetch(`${fixesUrl}/main/versions/${version}.json`, { refresh: true }) + return fixes + } catch (e) { + throw new Error(`Error occured while fetching bugfixes: ${message(e)}`) + } +} + interface FetchOptions { decode?: (r: Response) => Promise refresh?: boolean diff --git a/src/locales/en.json b/src/locales/en.json index b4bc585e..3995d460 100644 --- a/src/locales/en.json +++ b/src/locales/en.json @@ -205,6 +205,8 @@ "versions.resource_pack_format": "Resource pack format", "versions.technical_changes": "Technical changes", "versions.discussion": "Discussion", + "versions.fixes": "Fixed bugs", + "versions.fixes.no_results": "No fixes", "versions.minecraft_versions": "Minecraft Versions", "versions.latest_snapshot": "Latest snapshot", "versions.latest_release": "Latest release",