Skip to content

Commit a5e7561

Browse files
committed
move loader and initialization to react
1 parent a2067a7 commit a5e7561

File tree

14 files changed

+259
-182
lines changed

14 files changed

+259
-182
lines changed

buildprocess/webpack.config.js

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ module.exports = function (devMode) {
1010
// Base configuration
1111
const config = {
1212
mode: devMode ? "development" : "production",
13-
entry: "./entry.js",
13+
entry: "./entry.jsx",
1414
output: {
1515
path: path.resolve(__dirname, "..", "wwwroot", "build"),
1616
filename: "TerriaMap.js",
@@ -28,8 +28,7 @@ module.exports = function (devMode) {
2828
{
2929
test: /\.(ts|js)x?$/,
3030
include: [
31-
path.resolve(__dirname, "..", "index.js"),
32-
path.resolve(__dirname, "..", "entry.js"),
31+
path.resolve(__dirname, "..", "entry.jsx"),
3332
path.resolve(__dirname, "..", "plugins.ts"),
3433
path.resolve(__dirname, "..", "lib")
3534
],
@@ -80,12 +79,6 @@ module.exports = function (devMode) {
8079
}
8180
}
8281
},
83-
// handle css files - inject in html tag
84-
{
85-
test: /loader\.css$/,
86-
include: [path.resolve(__dirname, "..", "lib", "Styles")],
87-
use: ["style-loader", "css-loader"]
88-
},
8982
// handle scss files
9083
{
9184
test: /\.scss$/,
@@ -100,6 +93,7 @@ module.exports = function (devMode) {
10093
defaultExport: true
10194
}
10295
},
96+
{ loader: "terriajs-typings-for-css-modules-loader" },
10397
{
10498
loader: "css-loader",
10599
options: {

entry.js

Lines changed: 0 additions & 32 deletions
This file was deleted.

entry.jsx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { UserInterface } from "./lib/Views/UserInterface";
2+
import Variables from "./lib/Styles/variables.scss";
3+
import { createRoot } from "react-dom/client";
4+
5+
const container = document.getElementById("ui");
6+
const root = createRoot(container);
7+
8+
root.render(<UserInterface themeOverrides={Variables} />);

index.js

Lines changed: 0 additions & 106 deletions
This file was deleted.

lib/Views/Loader.tsx

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import globeGif from "../Styles/globe.gif";
2+
import Styles from "./loader.scss";
3+
4+
export const Loader = () => {
5+
return (
6+
<div
7+
className={Styles.loaderUi}
8+
style={{
9+
backgroundColor: "#383F4D"
10+
}}
11+
>
12+
<img src={globeGif} />
13+
</div>
14+
);
15+
};

lib/Views/UserInterface.jsx

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,34 @@
11
import PropTypes from "prop-types";
2-
import React from "react";
2+
import { useSyncExternalStore } from "react";
33
import RelatedMaps from "terriajs/lib/ReactViews/RelatedMaps/RelatedMaps";
4-
import {
5-
ExperimentalMenu,
6-
MenuLeft
7-
} from "terriajs/lib/ReactViews/StandardUserInterface/customizable/Groups";
4+
import { MenuLeft } from "terriajs/lib/ReactViews/StandardUserInterface/customizable/Groups";
85
import MenuItem from "terriajs/lib/ReactViews/StandardUserInterface/customizable/MenuItem";
96
import StandardUserInterface from "terriajs/lib/ReactViews/StandardUserInterface/StandardUserInterface";
107
import version from "../../version";
118
import "./global.scss";
9+
import { Loader } from "./Loader";
10+
import { terriaStore } from "./terriaStore";
1211

13-
export default function UserInterface(props) {
14-
const relatedMaps = props.viewState.terria.configParameters.relatedMaps;
12+
export const UserInterface = ({ themeOverrides }) => {
13+
const { terria, viewState, status } = useSyncExternalStore(
14+
terriaStore.subscribe,
15+
terriaStore.getSnapshot
16+
);
17+
18+
if (status === "loading") {
19+
return <Loader />;
20+
}
21+
const relatedMaps = viewState.terria.configParameters.relatedMaps;
1522
const aboutButtonHrefUrl =
16-
props.viewState.terria.configParameters.aboutButtonHrefUrl;
23+
viewState.terria.configParameters.aboutButtonHrefUrl;
1724

1825
return (
19-
<StandardUserInterface {...props} version={version}>
26+
<StandardUserInterface
27+
terria={terria}
28+
viewState={viewState}
29+
themeOverrides={themeOverrides}
30+
version={version}
31+
>
2032
<MenuLeft>
2133
{aboutButtonHrefUrl ? (
2234
<MenuItem
@@ -29,12 +41,11 @@ export default function UserInterface(props) {
2941
<RelatedMaps relatedMaps={relatedMaps} />
3042
) : null}
3143
</MenuLeft>
32-
<ExperimentalMenu />
44+
{/* <ExperimentalMenu /> */}
3345
</StandardUserInterface>
3446
);
35-
}
47+
};
3648

3749
UserInterface.propTypes = {
38-
terria: PropTypes.object,
39-
viewState: PropTypes.object
50+
themeOverrides: PropTypes.object
4051
};

lib/Views/global.scss.d.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
declare namespace GlobalScssNamespace {
2+
export interface IGlobalScss {
3+
rcSliderTooltipZoomDownIn: string;
4+
rcSliderTooltipZoomDownOut: string;
5+
"react-datepicker__month--selecting-range": string;
6+
"react-datepicker__year--selecting-range": string;
7+
reactDatepickerMonthSelectingRange: string;
8+
reactDatepickerYearSelectingRange: string;
9+
}
10+
}
11+
12+
declare const GlobalScssModule: GlobalScssNamespace.IGlobalScss & {
13+
/** WARNING: Only available when `css-loader` is used without `style-loader` or `mini-css-extract-plugin` */
14+
locals: GlobalScssNamespace.IGlobalScss;
15+
};
16+
17+
export = GlobalScssModule;
File renamed without changes.

lib/Views/loader.scss.d.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
declare namespace LoaderScssNamespace {
2+
export interface ILoaderScss {
3+
"loader-ui": string;
4+
"loader-ui-hide": string;
5+
loaderUi: string;
6+
loaderUiHide: string;
7+
}
8+
}
9+
10+
declare const LoaderScssModule: LoaderScssNamespace.ILoaderScss & {
11+
/** WARNING: Only available when `css-loader` is used without `style-loader` or `mini-css-extract-plugin` */
12+
locals: LoaderScssNamespace.ILoaderScss;
13+
};
14+
15+
export = LoaderScssModule;

lib/Views/render.jsx

Lines changed: 0 additions & 21 deletions
This file was deleted.

0 commit comments

Comments
 (0)