/
ReadmeModal.tsx
60 lines (48 loc) · 1.73 KB
/
ReadmeModal.tsx
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
import app from '../../admin/app';
import Modal, { IInternalModalAttrs } from '../../common/components/Modal';
import LoadingIndicator from '../../common/components/LoadingIndicator';
import Placeholder from '../../common/components/Placeholder';
import ExtensionReadme from '../models/ExtensionReadme';
import type Mithril from 'mithril';
import type { Extension } from '../AdminApplication';
export interface IReadmeModalAttrs extends IInternalModalAttrs {
extension: Extension;
}
export default class ReadmeModal<CustomAttrs extends IReadmeModalAttrs = IReadmeModalAttrs> extends Modal<CustomAttrs> {
protected name!: string;
protected extName!: string;
protected readme!: ExtensionReadme;
oninit(vnode: Mithril.Vnode<CustomAttrs, this>) {
super.oninit(vnode);
app.store.models['extension-readmes'] = ExtensionReadme;
this.name = this.attrs.extension.id;
this.extName = this.attrs.extension.extra['flarum-extension'].title;
this.loading = true;
this.loadReadme();
}
className() {
return 'ReadmeModal Modal--large Modal--inverted';
}
title() {
return app.translator.trans('core.admin.extension.readme.title', {
extName: this.extName,
});
}
content() {
const text = app.translator.trans('core.admin.extension.readme.no_readme');
return (
<div className="Modal-body">
{this.loading ? (
<div className="ReadmeModal-loading">{LoadingIndicator.component()}</div>
) : (
<div>{this.readme.content() ? m.trust(this.readme.content()) : Placeholder.component({ text })}</div>
)}
</div>
);
}
async loadReadme() {
this.readme = await app.store.find('extension-readmes', this.name);
this.loading = false;
m.redraw();
}
}