Files
ThreadNet-Web/src/components/views/dialogs/ChangelogDialog.tsx
T

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

124 lines
3.8 KiB
TypeScript
Raw Normal View History

/*
2024-09-09 14:57:16 +01:00
Copyright 2024 New Vector Ltd.
Copyright 2019 Michael Telatynski <7t3chguy@gmail.com>
2024-09-09 14:57:16 +01:00
Copyright 2016 Aviral Dasgupta
2024-09-09 14:57:16 +01:00
SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only
Please see LICENSE files in the repository root for full details.
*/
import React from "react";
2021-10-22 17:23:32 -05:00
2018-04-13 00:43:44 +01:00
import { _t } from "../../../languageHandler";
2021-07-02 17:08:27 +02:00
import QuestionDialog from "./QuestionDialog";
import Spinner from "../elements/Spinner";
2023-07-19 09:03:56 +01:00
import Heading from "../typography/Heading";
2021-06-14 21:26:15 +01:00
interface IProps {
newVersion: string;
version: string;
onFinished: (success: boolean) => void;
}
2023-03-06 17:21:09 +00:00
type State = Partial<Record<(typeof REPOS)[number], null | string | Commit[]>>;
2023-02-13 11:39:16 +00:00
interface Commit {
sha: string;
html_url: string;
commit: {
message: string;
};
}
2024-09-06 14:08:23 +01:00
const REPOS = ["element-hq/element-web", "element-hq/matrix-react-sdk", "matrix-org/matrix-js-sdk"] as const;
2023-02-13 11:39:16 +00:00
export default class ChangelogDialog extends React.Component<IProps, State> {
public constructor(props: IProps) {
super(props);
this.state = {};
}
2023-03-06 17:21:09 +00:00
private async fetchChanges(repo: (typeof REPOS)[number], oldVersion: string, newVersion: string): Promise<void> {
2022-10-12 18:59:07 +01:00
const url = `https://riot.im/github/repos/${repo}/compare/${oldVersion}...${newVersion}`;
try {
const res = await fetch(url);
if (!res.ok) {
this.setState({ [repo]: res.statusText });
return;
}
const body = await res.json();
this.setState({ [repo]: body.commits });
} catch (err) {
this.setState({ [repo]: err instanceof Error ? err.message : _t("error|unknown") });
2022-10-12 18:59:07 +01:00
}
}
public componentDidMount(): void {
const version = this.props.newVersion.split("-");
const version2 = this.props.version.split("-");
2018-10-26 22:50:35 -05:00
if (version == null || version2 == null) return;
// parse versions of form: [vectorversion]-react-[react-sdk-version]-js-[js-sdk-version]
2022-10-12 18:59:07 +01:00
for (let i = 0; i < REPOS.length; i++) {
const oldVersion = version2[2 * i];
const newVersion = version[2 * i];
2022-10-12 18:59:07 +01:00
this.fetchChanges(REPOS[i], oldVersion, newVersion);
}
}
2023-02-13 11:39:16 +00:00
private elementsForCommit(commit: Commit): JSX.Element {
return (
<li key={commit.sha} className="mx_ChangelogDialog_li">
<a href={commit.html_url} target="_blank" rel="noreferrer noopener">
{commit.commit.message.split("\n")[0]}
</a>
</li>
);
}
public render(): React.ReactNode {
const logs = REPOS.map((repo) => {
let content;
if (this.state[repo] == null) {
content = <Spinner key={repo} />;
} else if (typeof this.state[repo] === "string") {
content = _t("update|error_unable_load_commit", {
msg: this.state[repo],
});
} else {
2023-02-13 11:39:16 +00:00
content = (this.state[repo] as Commit[]).map(this.elementsForCommit);
}
return (
<div key={repo}>
2023-07-19 09:03:56 +01:00
<Heading as="h2" size="4">
{repo}
</Heading>
<ul>{content}</ul>
</div>
2018-10-26 22:50:35 -05:00
);
});
const content = (
<div className="mx_ChangelogDialog_content">
{this.props.version == null || this.props.newVersion == null ? (
<h2>{_t("update|unavailable")}</h2>
) : (
logs
)}
</div>
);
return (
<QuestionDialog
title={_t("update|changelog")}
description={content}
button={_t("action|update")}
onFinished={this.props.onFinished}
2021-04-27 17:23:27 +02:00
/>
2018-10-26 22:50:35 -05:00
);
}
}