-
Notifications
You must be signed in to change notification settings - Fork 69
/
main.ts
80 lines (73 loc) · 2.5 KB
/
main.ts
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
/**
* Copyright 2021 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* Entrypoint for topic pages.
*/
import React from "react";
import ReactDOM from "react-dom";
import { DEFAULT_PAGE_PLACE_TYPE } from "../../constants/subject_page_constants";
import { loadLocaleData } from "../../i18n/i18n";
import { NamedTypedPlace } from "../../shared/types";
import { TopicsSummary } from "../../types/app/topic_page_types";
import { App } from "./app";
window.onload = () => {
loadLocaleData("en", [import("../../i18n/compiled-lang/en/units.json")]).then(
() => {
renderPage();
}
);
};
function renderPage(): void {
// Get topic and render menu.
const topic = document.getElementById("metadata").dataset.topicId;
// TODO(beets): remove these if they remain unused.
const dcid = document.getElementById("metadata").dataset.placeDcid;
const morePlaces = JSON.parse(
document.getElementById("metadata").dataset.morePlaces
);
const placeName = document.getElementById("place-name").dataset.pn;
const placeType =
document.getElementById("place-type").dataset.pt || DEFAULT_PAGE_PLACE_TYPE;
const pageConfig = JSON.parse(
document.getElementById("topic-config").dataset.config
);
const topicsSummary: TopicsSummary = JSON.parse(
document.getElementById("topic-config").dataset.topicsSummary
);
// TODO(beets): use locale from URL
const locale = "en";
loadLocaleData(locale, [
import(`../../i18n/compiled-lang/${locale}/place.json`),
// TODO(beets): Figure out how to place this where it's used so dependencies can be automatically resolved.
import(`../../i18n/compiled-lang/${locale}/stats_var_labels.json`),
import(`../../i18n/compiled-lang/${locale}/units.json`),
]);
const place: NamedTypedPlace = {
dcid,
name: placeName || dcid,
types: [placeType],
};
ReactDOM.render(
React.createElement(App, {
place,
morePlaces,
topic,
pageConfig,
topicsSummary,
}),
document.getElementById("body")
);
}