-
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Expand file tree
/
Copy pathabout.tsx
More file actions
150 lines (133 loc) · 5.63 KB
/
about.tsx
File metadata and controls
150 lines (133 loc) · 5.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
import Modal from "../react/Modal.js";
import { t } from "../../services/i18n.js";
import { formatDateTime } from "../../utils/formatters.js";
import server from "../../services/server.js";
import utils from "../../services/utils.js";
import openService from "../../services/open.js";
import { useState } from "preact/hooks";
import type { AppInfo, Contributor, ContributorList } from "@triliumnext/commons";
import { useTriliumEvent } from "../react/hooks.jsx";
import { Card, CardSection } from "../react/Card.js";
import "./about.css";
import { Trans } from "react-i18next";
import type React from "react";
import icon from "../../assets/icon.svg";
import iconAlt from "../../assets/icon-alt.svg";
import { useCallback, useEffect } from "react";
import contributors from "../../../../../contributors.json";
export default function AboutDialog() {
const [appInfo, setAppInfo] = useState<AppInfo | null>(null);
const [shown, setShown] = useState(false);
const [isNightly, setNightly] = useState(false);
const onLoad = useCallback(async () => {
if (!appInfo) {
setAppInfo(await server.get<AppInfo>("app-info"));
}
setShown(true);
}, []);
useTriliumEvent("openAboutDialog", onLoad);
useEffect(() => {
setNightly(!!appInfo?.appVersion.includes("test"));
}, [appInfo])
return (
<Modal
className="about-dialog"
size="md"
show={shown}
onHidden={() => setShown(false)}
>
<div className="about-dialog-content">
<img src={(isNightly) ? iconAlt : icon} width="128" />
<h2>Trilium Notes {isNightly && <span>Nightly</span>}</h2>
<a className="tn-link" href="https://triliumnotes.org/" target="_blank">
triliumnotes.org
</a>
<Card className="property-sheet-card">
<CardSection>
<div>{t("about.version_label")}</div>
<div className="selectable-text">
{t("about.version", {
appVersion: appInfo?.appVersion,
dbVersion: appInfo?.dbVersion,
syncVersion: appInfo?.syncVersion
})}
<div>
<Trans
i18nKey="about.build_info"
values={{
buildDate: appInfo?.buildDate ? formatDateTime(appInfo.buildDate) : ""
}}
components={{
buildRevision: revisionLink(appInfo)
}}
/>
</div>
</div>
</CardSection>
<CardSection>
<div>{t("about.contributors_label")}</div>
<div className="contributor-list use-tn-links">
<Contributors data={contributors as ContributorList} />
<a href="https://github.com/TriliumNext/Trilium/graphs/contributors" target="_blank">
{t("about.contributor_full_list")}
</a>
</div>
</CardSection>
<CardSection>
<div>{t("about.data_directory")}</div>
<div className="selectable-text">
{appInfo?.dataDirectory && (<DirectoryLink directory={appInfo.dataDirectory} />)}
</div>
</CardSection>
</Card>
</div>
<footer>
<a href="https://github.com/TriliumNext/Trilium" target="_blank">
<i class='bx bxl-github'></i>
GitHub
</a>
<a href="https://triliumnotes.org/en/support-us" target="_blank">
<i class='bx bx-heart' ></i>
{t("about.donate")}
</a>
</footer>
</Modal>
);
}
function revisionLink(appInfo: AppInfo | null) {
return <>
{appInfo?.buildRevision && <a href={`https://github.com/TriliumNext/Trilium/commit/${appInfo.buildRevision}`} target="_blank" className="tn-link">
{appInfo.buildRevision.substring(0, 7)}
</a>}
</> as React.ReactElement;
}
function Contributors(params: {data: ContributorList}) {
return params.data.contributors.map((c, index, array) => {
return <>
<ContributorListItem data={c} />
{/* Add a comma between items */}
{(index < array.length - 1) ? ", " : ". "}
</>
});
}
function ContributorListItem({data}: {data: Contributor}) {
let roleString = "";
if (data.role) {
roleString = t(`about.contributor_roles.${data.role}`);
}
return <>
<a href={data.url} target="_blank">{data.fullName ?? data.name}</a>
{roleString && <span> ({roleString})</span>}
</>
}
function DirectoryLink({ directory }: { directory: string}) {
if (utils.isElectron()) {
const onClick = (e: MouseEvent) => {
e.preventDefault();
openService.openDirectory(directory);
};
return <a className="tn-link selectable-text" href="#" onClick={onClick}>{directory}</a>
} else {
return <span className="selectable-text">{directory}</span>;
}
}