first commit.

This commit is contained in:
2022-05-11 18:50:27 +09:00
commit 81de5e7154
106 changed files with 17122 additions and 0 deletions

49
src/App.module.css Normal file
View File

@ -0,0 +1,49 @@
.container {
width: 480px;
padding: 10px 10px 0 10px;
margin: 0 auto;
margin-bottom: 5px;
}
.main {
width: 100%;
min-height: 330px;
height: auto !important;
border: thin solid #bb3300;
text-align: left;
border-radius: 20px;
padding: 10px 0;
}
.header {
width: 100%;
height: 150px;
text-align: left;
margin-bottom: 0px;
padding-top: 10px;
padding-bottom: 5px;
background-image: url("./assets/images/logo.jpg");
background-repeat: no-repeat;
background-position: center center;
}
.header ul {
position: absolute;
top: 120px;
padding: 0;
}
.header ul li {
display: inline-block;
float: left;
}
.header ul li a {
display: block;
padding: 0 15px;
outline: none;
text-decoration: none;
line-height: 20px;
}
.footer {
font-size: 90%;
width: 100%;
clear: both;
text-align: center;
margin: 10px 0;
}

15
src/App.test.tsx Normal file
View File

@ -0,0 +1,15 @@
import { render } from "@testing-library/react";
import React from "react";
import { Provider } from "react-redux";
import App from "./App";
import { store } from "./app/store";
test("renders learn react link", () => {
const { getByText } = render(
<Provider store={store}>
<App />
</Provider>
);
expect(getByText(/learn/i)).toBeInTheDocument();
});

49
src/App.tsx Normal file
View File

@ -0,0 +1,49 @@
import React from "react";
import { BrowserRouter, NavLink, Route, Routes } from "react-router-dom";
import styles from "./App.module.css";
import CompatRedirect from "./features/compat-redirect/CompatRedirect";
import Contact from "./features/contact/Contact";
import Data from "./features/data/Data";
import Help from "./features/help/Help";
import News from "./features/news/News";
import PageTitle from "./features/page-title/PageTitle";
import Search from "./features/search/Search";
const App: React.FC = () => {
return (
<BrowserRouter>
<div className={styles.container}>
<div className={styles.header}>
<ul>
<li>
<NavLink to="/">Home</NavLink>
</li>
<li>
<NavLink to="/search">Search</NavLink>
</li>
<li>
<NavLink to="/help">Help</NavLink>
</li>
<li>
<NavLink to="/contact">Contact</NavLink>
</li>
</ul>
</div>
<PageTitle />
<div className={styles.main}>
<Routes>
<Route index element={<News />} />
<Route path="search/*" element={<Search />} />
<Route path="data/:name/*" element={<Data />} />
<Route path="help/*" element={<Help />} />
<Route path="contact" element={<Contact />} />
<Route path="*" element={<CompatRedirect />} />
</Routes>
</div>
<div className={styles.footer}>&copy;2014 Laboratory for cortical circuit plasticity, RIKEN BSI.</div>
</div>
</BrowserRouter>
);
};
export default App;

6
src/app/hooks.ts Normal file
View File

@ -0,0 +1,6 @@
import { TypedUseSelectorHook, useDispatch, useSelector } from "react-redux";
import type { AppDispatch, RootState } from "./store";
// Use throughout your app instead of plain `useDispatch` and `useSelector`
export const useAppDispatch = () => useDispatch<AppDispatch>();
export const useAppSelector: TypedUseSelectorHook<RootState> = useSelector;

14
src/app/store.ts Normal file
View File

@ -0,0 +1,14 @@
import { Action, configureStore, ThunkAction } from "@reduxjs/toolkit";
import pageTitleReducer from "../features/page-title/pageTitleSlice";
import searchResultsReducer from "../features/search-results/searchResultsSlice";
export const store = configureStore({
reducer: {
pageTitle: pageTitleReducer,
searchResults: searchResultsReducer,
},
});
export type AppDispatch = typeof store.dispatch;
export type RootState = ReturnType<typeof store.getState>;
export type AppThunk<ReturnType = void> = ThunkAction<ReturnType, RootState, unknown, Action<string>>;

306
src/assets/data.json Normal file
View File

@ -0,0 +1,306 @@
{
"TE0001": {
"pd": 67,
"recordingVolume": {
"width": 317,
"height": 317,
"depth": 90
},
"imagingDepth": {
"from": 120,
"to": 210
},
"cellType": ["E", "I", "G"],
"area": "L2\/3, V1",
"cellNum": 422,
"expDate": "Jun. 23 2009",
"releaseDate": "141101",
"geneType": "VGAT-Venus",
"remark": "3D arrangements of excitatory neurons, inhibitory neurons and astrocytes in the V1 layer 2\/3 of VGAT-Venus transgenic mouse at PD67."
},
"TE0002": {
"pd": 78,
"recordingVolume": {
"width": 317,
"height": 317,
"depth": 90
},
"imagingDepth": {
"from": 130,
"to": 220
},
"cellType": ["E", "I", "G"],
"area": "L2\/3, V1",
"cellNum": 348,
"expDate": "Dec. 17 2009",
"releaseDate": "141101",
"geneType": "VGAT-Venus",
"remark": "3D arrangements of excitatory neurons, inhibitory neurons and astrocytes in the V1 layer 2\/3 of VGAT-Venus transgenic mouse at PD78."
},
"TE0003": {
"pd": 70,
"recordingVolume": {
"width": 317,
"height": 317,
"depth": 105
},
"imagingDepth": {
"from": 120,
"to": 225
},
"cellType": ["E", "I", "G"],
"area": "L2\/3, V1",
"cellNum": 631,
"expDate": "Jan. 27 2010",
"releaseDate": "141101",
"geneType": "VGAT-Venus",
"remark": "3D arrangements of excitatory neurons, inhibitory neurons and astrocytes in the V1 layer 2\/3 of VGAT-Venus transgenic mouse at PD70."
},
"TE0004": {
"pd": 90,
"recordingVolume": {
"width": 317,
"height": 317,
"depth": 90
},
"imagingDepth": {
"from": 110,
"to": 200
},
"cellType": ["E", "I", "G"],
"area": "L2\/3, V1",
"cellNum": 759,
"expDate": "Dec. 5 2011",
"releaseDate": "141101",
"geneType": "VGAT-Venus",
"remark": "3D arrangements of excitatory neurons, inhibitory neurons and astrocytes in the V1 layer 2\/3 of VGAT-Venus transgenic mouse at PD90."
},
"TE0005": {
"pd": 75,
"recordingVolume": {
"width": 317,
"height": 317,
"depth": 105
},
"imagingDepth": {
"from": 125,
"to": 230
},
"cellType": ["E", "I", "G"],
"area": "L2\/3, V1",
"cellNum": 710,
"expDate": "May. 28 2012",
"releaseDate": "141101",
"geneType": "VGAT-Venus",
"remark": "3D arrangements of excitatory neurons, inhibitory neurons and astrocytes in the V1 layer 2\/3 of VGAT-Venus transgenic mouse at PD75."
},
"TE0006": {
"pd": 77,
"recordingVolume": {
"width": 317,
"height": 317,
"depth": 105
},
"imagingDepth": {
"from": 110,
"to": 215
},
"cellType": ["E", "P", "S", "G"],
"area": "L2\/3, V1",
"cellNum": 382,
"expDate": "Feb. 22 2011",
"releaseDate": "141101",
"geneType": "PV\/myrGFP-LDLRct",
"remark": "3D arrangements of PV neurons, SOM neurons, astrocytes and putative excitatory neurons in the V1 layer 2\/3 of PV\/myrGFP-LDLRct transgenic mouse at PD77."
},
"TE0007": {
"pd": 73,
"recordingVolume": {
"width": 317,
"height": 317,
"depth": 105
},
"imagingDepth": {
"from": 110,
"to": 215
},
"cellType": ["E", "P", "S", "G"],
"area": "L2\/3, V1",
"cellNum": 774,
"expDate": "Mar. 24 2011",
"releaseDate": "141101",
"geneType": "PV\/myrGFP-LDLRct",
"remark": "3D arrangements of PV neurons, SOM neurons, astrocytes and putative excitatory neurons in the V1 layer 2\/3 of PV\/myrGFP-LDLRct transgenic mouse at PD73."
},
"TE0008": {
"pd": 70,
"recordingVolume": {
"width": 317,
"height": 317,
"depth": 105
},
"imagingDepth": {
"from": 110,
"to": 215
},
"cellType": ["E", "P", "S", "G"],
"area": "L2\/3, V1",
"cellNum": 536,
"expDate": "Jun. 23 2011",
"releaseDate": "141101",
"geneType": "PV\/myrGFP-LDLRct",
"remark": "3D arrangements of PV neurons, SOM neurons, astrocytes and putative excitatory neurons in the V1 layer 2\/3 of PV\/myrGFP-LDLRct transgenic mouse at PD70."
},
"TE0009": {
"pd": 53,
"recordingVolume": {
"width": 317,
"height": 317,
"depth": 110
},
"imagingDepth": {
"from": 100,
"to": 210
},
"cellType": ["I"],
"area": "L2\/3, V1",
"cellNum": 42,
"expDate": "Oct. 10 2013",
"releaseDate": "141101",
"geneType": "Dlx5\/6-GCaMP3",
"remark": "3D arrangement of GABAergic\/inhibitory neurons in the V1 layer 2\/3 of Dlx5\/6-GCaMP3 transgenic mouse at PD53."
},
"TE0010": {
"pd": 100,
"recordingVolume": {
"width": 512,
"height": 512,
"depth": 110
},
"imagingDepth": {
"from": 90,
"to": 200
},
"cellType": ["I"],
"area": "L2\/3, V1",
"cellNum": 177,
"expDate": "Nov. 7 2013",
"releaseDate": "141101",
"geneType": "Dlx5\/6-GCaMP3",
"remark": "3D arrangement of GABAergic\/inhibitory neurons in the V1 layer 2\/3 of Dlx5\/6-GCaMP3 transgenic mouse at PD100."
},
"TE0011": {
"pd": 70,
"recordingVolume": {
"width": 512,
"height": 512,
"depth": 100
},
"imagingDepth": {
"from": 90,
"to": 200
},
"cellType": ["I"],
"area": "L2\/3, V1",
"cellNum": 194,
"expDate": "Nov. 25 2013",
"releaseDate": "141101",
"geneType": "Dlx5\/6-GCaMP3",
"remark": "3D arrangement of GABAergic\/inhibitory neurons in the V1 layer 2\/3 of Dlx5\/6-GCaMP3 transgenic mouse at PD70."
},
"TE0012": {
"pd": 78,
"recordingVolume": {
"width": 512,
"height": 512,
"depth": 110
},
"imagingDepth": {
"from": 90,
"to": 200
},
"cellType": ["I"],
"area": "L2\/3, V1",
"cellNum": 179,
"expDate": "Dec. 3 2013",
"releaseDate": "141101",
"geneType": "Dlx5\/6-GCaMP3",
"remark": "3D arrangement of GABAergic\/inhibitory neurons in the V1 layer 2\/3 of Dlx5\/6-GCaMP3 transgenic mouse at PD78."
},
"TE0013": {
"pd": 69,
"recordingVolume": {
"width": 512,
"height": 512,
"depth": 110
},
"imagingDepth": {
"from": 90,
"to": 200
},
"cellType": ["I"],
"area": "L2\/3, V1",
"cellNum": 144,
"expDate": "Dec. 19 2013",
"releaseDate": "141101",
"geneType": "Dlx5\/6-GCaMP3",
"remark": "3D arrangement of GABAergic\/inhibitory neurons in the V1 layer 2\/3 of Dlx5\/6-GCaMP3 transgenic mouse at PD69."
},
"TE0014": {
"pd": 44,
"recordingVolume": {
"width": 317,
"height": 317,
"depth": 110
},
"imagingDepth": {
"from": 90,
"to": 200
},
"cellType": ["I"],
"area": "L2\/3, V1",
"cellNum": 40,
"expDate": "Jul. 23 2014",
"releaseDate": "141101",
"geneType": "Dlx5\/6-GCaMP3",
"remark": "3D arrangement of GABAergic\/inhibitory neurons in the V1 layer 2\/3 of Dlx5\/6-GCaMP3 transgenic mouse at PD44."
},
"TE0015": {
"pd": 92,
"recordingVolume": {
"width": 512,
"height": 512,
"depth": 100
},
"imagingDepth": {
"from": 90,
"to": 200
},
"cellType": ["I"],
"area": "L2\/3, V1",
"cellNum": 125,
"expDate": "Jul. 30 2014",
"releaseDate": "141101",
"geneType": "Dlx5\/6-GCaMP3",
"remark": "3D arrangement of GABAergic\/inhibitory neurons in the V1 layer 2\/3 of Dlx5\/6-GCaMP3 transgenic mouse at PD92."
},
"TE0016": {
"pd": 47,
"recordingVolume": {
"width": 512,
"height": 512,
"depth": 100
},
"imagingDepth": {
"from": 90,
"to": 200
},
"cellType": ["I"],
"area": "L2\/3, V1",
"cellNum": 100,
"expDate": "Aug. 1 2014",
"releaseDate": "141101",
"geneType": "Dlx5\/6-GCaMP3",
"remark": "3D arrangement of GABAergic\/inhibitory neurons in the V1 layer 2\/3 of Dlx5\/6-GCaMP3 transgenic mouse at PD47."
}
}

BIN
src/assets/images/logo.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 63 KiB

10
src/assets/news.json Normal file
View File

@ -0,0 +1,10 @@
[
{
"date": "Nov. 1, 2014",
"desc": "16 datasets have been added to CelLoc-3D\nProvided by Ebina et al.\n(Lab. for Cortical Circuit Plasticity, RIKEN BSI)"
},
{
"date": "Nov. 1, 2014",
"desc": "CelLoc-3D becomes available online"
}
]

View File

@ -0,0 +1,43 @@
import React from "react";
import { Navigate, useLocation } from "react-router-dom";
import NotFound from "../not-found/NotFound";
const CompatRedirect: React.FC = () => {
const { pathname } = useLocation();
switch (pathname) {
case "/index.html":
return <Navigate to="/" />;
case "/Search.html":
return <Navigate to="/search" />;
case "/Help.html":
return <Navigate to="/help" />;
case "/Help_S1.html":
return <Navigate to="/help/search/1" />;
case "/Help_S2.html":
return <Navigate to="/help/search/2" />;
case "/Help_S3.html":
return <Navigate to="/help/search/3" />;
case "/Help_S4.html":
return <Navigate to="/help/search/4" />;
case "/Help_S5.html":
return <Navigate to="/help/search/5" />;
case "/Help_Dataset.html":
return <Navigate to="/help/dataset" />;
case "/Help_Viewer.html":
return <Navigate to="/help/viewer" />;
case "/Contact.html":
return <Navigate to="/help/contact" />;
case "/cgi-bin/SearchResult.cgi":
return <Navigate to="/search/results" />;
default:
const match = pathname.match(/^\/DB\/TE\/(3D-)?(.+)\.html$/);
if (match !== null) {
const url = "/data/" + match[2] + (typeof match[1] !== "undefined" ? "/viewer" : "");
return <Navigate to={url} />;
}
break;
}
return <NotFound />;
};
export default CompatRedirect;

View File

@ -0,0 +1,17 @@
.contact {
margin: 20px;
}
.contact h4 {
margin: 5px 0 10px 0;
}
.contact p {
margin: 5px 0 15px 15px;
}
.notice {
margin: 10px 0 20px;
color: #ff0000;
}
.note {
margin-left: 15px;
font-style: italic;
}

View File

@ -0,0 +1,36 @@
import React, { useEffect } from "react";
import { useAppDispatch } from "../../app/hooks";
import { setTitle } from "../page-title/pageTitleSlice";
import styles from "./Contact.module.css";
const Contact: React.FC = () => {
const dispatch = useAppDispatch();
useEffect(() => {
dispatch(setTitle("Contact Information"));
}, [dispatch]);
return (
<div className={styles.contact}>
<section className={styles.notice}>Notice: This site has been archived since May 2019 and is no longer updated.</section>
<h4>CelLoc-3D is managed by Teppei Ebina and Tadaharu Tsumoto</h4>
<p>
Laboratory for cortical circuit plasticity
<br />
Brain Science Institute, RIKEN
<br />
2-1, Hirosawa, Wako, Saitama, 351-0198 Japan
</p>
<h4>E-mail:</h4>
<p>
teppei-ebina (at) brain.riken.jp
<br />
<span className={styles.note}>or</span>
<br />
tsumoto (at) brain.riken.jp
<br />
<span className={styles.note}>(change (at) to @)</span>
</p>
</div>
);
};
export default Contact;

View File

@ -0,0 +1,21 @@
.detail {
margin: 10px 10px 20px 10px;
}
.title,
.author,
.detail figure,
.detail dl {
margin: 5px 0 10px 0;
}
.detail figure {
text-align: center;
}
.detail figure img {
width: 80%;
}
.detail dl dt {
font-weight: bold;
}
.detail dl dd {
margin-left: 30px;
}

View File

@ -0,0 +1,156 @@
import axios from "axios";
import React, { Component } from "react";
import { Link } from "react-router-dom";
import { useAppDispatch } from "../../app/hooks";
import DataUtils from "../data/DataUtils";
import Loading from "../loading/Loading";
import NotFound from "../not-found/NotFound";
import { setTitle } from "../page-title/pageTitleSlice";
import styles from "./DataDetail.module.css";
interface DetailDataJson {
title: string;
author: string;
figure: {
file: string;
caption: string;
};
download: string;
view: string;
mouseLine: string;
imagingArea: string;
cellType: string[];
postnatalDays: number;
imagingVolumeSize: string;
imagingDepth: string;
journal: string;
summary: string;
releaseDate: string;
}
interface PropsFC {
name: string;
}
interface Props extends PropsFC {
dispatch: any;
}
interface State {
name: string;
data: DetailDataJson | null;
}
class DataDetail extends Component<Props, State> {
isActive = false;
constructor(props: Props) {
super(props);
this.state = {
name: props.name,
data: null,
};
}
componentDidMount() {
const { name } = this.state;
this.isActive = true;
if (!DataUtils.exists(name)) {
if (name !== "") {
this.setState({ name: "" });
}
return;
}
axios
.get(`/data/${name}.json`, { responseType: "json" })
.then((response) => {
if (this.isActive) {
this.props.dispatch(setTitle(`DS: ${name}`));
this.setState({ data: response.data as DetailDataJson });
}
})
.catch((error) => {
if (this.isActive) {
this.setState({ name: "" });
}
});
}
componentWillUnmount() {
this.isActive = false;
}
render() {
const { name, data } = this.state;
if (name === "") {
return <NotFound />;
}
if (!data) {
return <Loading />;
}
return (
<section className={styles.detail}>
<h4 className={styles.title}>{data.title}</h4>
<div className={styles.author}>{data.author}</div>
<figure>
<img src={data.figure.file} alt={data.figure.caption} />
<figcaption>{data.figure.caption}</figcaption>
</figure>
<dl>
<dt>Download &amp; View</dt>
<dd>
<a href={data.download}>Text download</a>
</dd>
<dd>
<Link to={data.view}>View 3D structure</Link>
</dd>
</dl>
<dl>
<dt>Mouse line</dt>
<dd>{data.mouseLine}</dd>
</dl>
<dl>
<dt>Imaging area</dt>
<dd>{data.imagingArea}</dd>
</dl>
<dl>
<dt>Cell type</dt>
{data.cellType.map((value, key) => {
return <dd key={key}>{value}</dd>;
})}
</dl>
<dl>
<dt>Postnatal days</dt>
<dd>{data.postnatalDays}</dd>
</dl>
<dl>
<dt>Imaging volume size</dt>
<dd>{data.imagingVolumeSize}</dd>
</dl>
<dl>
<dt>Imaging depth</dt>
<dd>{data.imagingDepth}</dd>
</dl>
<dl>
<dt>Journal</dt>
<dd>{data.journal}</dd>
</dl>
<dl>
<dt>Summary</dt>
<dd dangerouslySetInnerHTML={{ __html: data.summary }}></dd>
</dl>
<dl>
<dt>Release date</dt>
<dd>{data.releaseDate}</dd>
</dl>
</section>
);
}
}
const DataDetailFC: React.FC<PropsFC> = (props) => {
const dispatch = useAppDispatch();
return <DataDetail dispatch={dispatch} name={props.name} />;
};
export default DataDetailFC;

View File

@ -0,0 +1,12 @@
.no_webgl {
margin: 10px auto;
text-align: center;
}
.back {
margin-bottom: 10px;
text-align: center;
}
.viewer {
width: 100%;
height: 400px;
}

View File

@ -0,0 +1,207 @@
import axios from "axios";
import React, { Component } from "react";
import { Link } from "react-router-dom";
import * as THREE from "three";
import { TrackballControls } from "three/examples/jsm/controls/TrackballControls";
import { useAppDispatch } from "../../app/hooks";
import DataUtils from "../data/DataUtils";
import Loading from "../loading/Loading";
import NotFound from "../not-found/NotFound";
import { setTitle } from "../page-title/pageTitleSlice";
import styles from "./DataViewer.module.css";
class Viewer3D {
private mount: HTMLDivElement;
private frameId: number | null = null;
private scene: THREE.Scene | null = null;
private camera: THREE.PerspectiveCamera | null = null;
private controls: TrackballControls | null = null;
private renderer: THREE.WebGLRenderer | null = null;
constructor(mount: HTMLDivElement) {
this.mount = mount;
this.start = this.start.bind(this);
this.stop = this.stop.bind(this);
this.animate = this.animate.bind(this);
}
init(data: string) {
const lines = data.split("\n");
const head = lines
.shift()
?.trim()
.split("\t")
.map((line, k) => {
return parseInt(line.replace(/^#/g, ""), 10) || 0;
});
if (typeof head === "undefined" || head.length !== 3 || head.includes(0)) {
return false;
}
const width = this.mount.clientWidth;
const height = this.mount.clientHeight;
const fov = 7.5 + (head[0] * 2.5) / 100.0;
this.camera = new THREE.PerspectiveCamera(fov, width / height, 1, 10000);
this.camera.position.x = 1300;
this.camera.position.y = 1300;
this.camera.position.z = 1100;
this.camera.up.set(0, 0, 1);
this.controls = new TrackballControls(this.camera, this.mount);
const obj3d = new THREE.Object3D();
this.scene = new THREE.Scene();
this.scene.add(obj3d);
const DrawCube = (width: number, height: number, depth: number) => {
const mesh = new THREE.Mesh(new THREE.BoxGeometry(width, height, depth * 2), new THREE.MeshBasicMaterial());
const cube = new THREE.BoxHelper(mesh, 0x000000);
return cube;
};
obj3d.add(DrawCube(head[0], head[1], head[2]));
const material = {
e: new THREE.MeshBasicMaterial({ color: 0x0000ff }),
i: new THREE.MeshBasicMaterial({ color: 0xff0000 }),
g: new THREE.MeshBasicMaterial({ color: 0x00ff00 }),
p: new THREE.MeshBasicMaterial({ color: 0xffff00 }),
s: new THREE.MeshBasicMaterial({ color: 0xff00ff }),
ps: new THREE.MeshBasicMaterial({ color: 0x00ffff }),
};
const geometory = new THREE.SphereGeometry(4, 10, 10);
lines.forEach((line) => {
const point = line.trim().split("\t");
if (point.length === 4 && material.hasOwnProperty(point[0])) {
const particle = new THREE.Mesh(geometory, material[point[0] as "e" | "i" | "g" | "p" | "s" | "ps"]);
particle.position.x = parseFloat(point[1]) - head[0] / 2.0;
particle.position.y = parseFloat(point[2]) - head[1] / 2.0;
particle.position.z = head[2] - parseFloat(point[3]) * 2.0;
obj3d.add(particle);
}
});
try {
this.renderer = new THREE.WebGLRenderer({ antialias: true });
this.renderer.setSize(width, height);
this.renderer.setClearColor(0xffffff);
this.mount.appendChild(this.renderer.domElement);
} catch (error) {
return false;
}
return true;
}
start() {
this.frameId = requestAnimationFrame(this.animate);
}
stop() {
this.frameId && cancelAnimationFrame(this.frameId);
this.renderer && this.mount.removeChild(this.renderer.domElement);
}
animate() {
this.controls && this.controls.update();
this.renderer && this.renderer.clear();
this.renderer && this.scene && this.camera && this.renderer.render(this.scene, this.camera);
this.frameId = requestAnimationFrame(this.animate);
}
}
interface PropsFC {
name: string;
}
interface Props extends PropsFC {
dispatch: any;
}
interface State {
name: string;
data: string;
}
class DataViewer extends Component<Props, State> {
private isActive = false;
private mount: HTMLDivElement | null = null;
private viewer: Viewer3D | null = null;
constructor(props: Props) {
super(props);
this.state = {
name: this.props.name,
data: "",
};
}
componentDidMount() {
const { name } = this.state;
this.isActive = true;
if (!DataUtils.exists(name)) {
if (name !== "") {
this.setState({ name: "" });
}
return;
}
axios
.get(`/data/${name}.dat`, { responseType: "text" })
.then((response) => {
if (this.isActive) {
this.props.dispatch(setTitle(`View 3D: ${name}`));
this.setState({ data: response.data });
}
})
.catch((error) => {
if (this.isActive) {
this.setState({ name: "" });
}
});
}
componentDidUpdate(prevProps: Props, prevState: State) {
if (this.mount && this.state.data !== "" && !this.viewer) {
const viewer = new Viewer3D(this.mount);
if (viewer.init(this.state.data)) {
this.viewer = viewer;
this.viewer.start();
} else {
this.setState({ name: "@@NOWEBGL@@" });
}
}
}
componentWillUnmount() {
this.isActive = false;
if (this.viewer) {
this.viewer.stop();
this.viewer = null;
}
}
render() {
const { name, data } = this.state;
switch (name) {
case "":
return <NotFound />;
case "@@NOWEBGL@@":
return <div className={styles.no_webgl}>It does not appear your computer supports WebGL.</div>;
}
if (data === "") {
return <Loading />;
}
return (
<section>
<div className={styles.back}>
<Link to={`/data/${name}`}>Back to {name}</Link>
</div>
<div
className={styles.viewer}
ref={(mount) => {
this.mount = mount;
}}
/>
</section>
);
}
}
const DataViewerFC: React.FC<PropsFC> = (props) => {
const dispatch = useAppDispatch();
return <DataViewer dispatch={dispatch} name={props.name} />;
};
export default DataViewerFC;

View File

@ -0,0 +1,3 @@
.data {
margin: 10px;
}

View File

@ -0,0 +1,25 @@
import React from "react";
import { Route, Routes, useParams } from "react-router-dom";
import DataDetail from "../data-detail/DataDetail";
import DataViewer from "../data-viewer/DataViewer";
import NotFound from "../not-found/NotFound";
import styles from "./Data.module.css";
import DataUtils from "./DataUtils";
const Data: React.FC = () => {
const { name } = useParams<"name">();
if (typeof name === "undefined" || !DataUtils.exists(name)) {
return <NotFound />;
}
return (
<div className={styles.data}>
<Routes>
<Route index element={<DataDetail name={name} />} />
<Route path="viewer" element={<DataViewer name={name} />} />
<Route path="*" element={<NotFound />} />
</Routes>
</div>
);
};
export default Data;

View File

@ -0,0 +1,89 @@
import JsonData_ from "../../assets/data.json";
const cellTypes = ["E", "I", "G", "P", "S"] as const;
type TCellType = typeof cellTypes[number];
interface JsonDataItem {
pd: number;
recordingVolume: {
width: number;
height: number;
depth: number;
};
imagingDepth: {
from: number;
to: number;
};
cellType: string[]; // TCellType[] or ("E"|"I"|"G"|"P"|"S")[];
area: string;
cellNum: number;
expDate: string;
releaseDate: string;
geneType: string;
remark: string;
}
interface JsonData {
[name: string]: JsonDataItem;
}
export interface SearchParams {
pdStart: number;
pdEnd: number;
widthMin: number;
widthMax: number;
depthMin: number;
depthMax: number;
cellType: string;
area: string;
geneType: string;
keyword: string;
}
interface SearchResult {
name: string;
item: JsonDataItem;
}
export type SearchResults = SearchResult[];
const jsonData: JsonData = JsonData_;
class DataUtils {
static exists(name: string): boolean {
return jsonData.hasOwnProperty(name);
}
static search(params: SearchParams): SearchResults {
const results: SearchResults = [];
for (let name in jsonData) {
const item = jsonData[name];
if (item.pd < params.pdStart || params.pdEnd < item.pd) {
continue;
}
if (item.recordingVolume.width < params.widthMin || params.widthMax < item.recordingVolume.width) {
continue;
}
if (item.imagingDepth.from < params.depthMin || params.depthMax < item.imagingDepth.to) {
continue;
}
if (params.cellType !== "any") {
if (!item.cellType.includes(params.cellType as TCellType)) {
continue;
}
}
if (params.area !== "all" && item.area !== params.area) {
continue;
}
if (params.geneType !== "all" && item.geneType !== params.geneType) {
continue;
}
if (params.keyword.length !== 0 && !item.remark.includes(params.keyword)) {
continue;
}
results.push({ name, item });
}
return results;
}
}
export default DataUtils;

View File

@ -0,0 +1,52 @@
.help {
margin: 10px;
}
.help p {
margin: 5px 15px 5px 15px;
}
.index {
margin: 0 0 16px 0;
padding-left: 30px;
}
.index li {
margin-bottom: 15px;
}
.search_links {
margin: 0 10px;
font-size: 75%;
text-align: right;
}
.search_links:after {
content: ".";
display: block;
height: 0;
font-size: 0;
clear: both;
visibility: hidden;
}
.search_links li {
display: inline-block;
}
.search_links li a {
display: block;
padding: 0 10px;
outline: none;
text-decoration: none;
}
.title {
font-weight: bold;
font-size: 100%;
margin: 5px;
}
.legend {
font-weight: bold;
margin-right: 5px;
}
.figure {
width: 100%;
margin: 15px 0;
text-align: center;
}
.figure img {
width: 320px;
}

210
src/features/help/Help.tsx Normal file
View File

@ -0,0 +1,210 @@
import React, { useEffect } from "react";
import { Link, Route, Routes } from "react-router-dom";
import { useAppDispatch } from "../../app/hooks";
import NotFound from "../not-found/NotFound";
import { setTitle } from "../page-title/pageTitleSlice";
import styles from "./Help.module.css";
const HelpIndex = () => {
const title = "Help";
const dispatch = useAppDispatch();
useEffect(() => {
dispatch(setTitle(title));
}, [dispatch, title]);
return (
<ul className={styles.index}>
<li>
<Link to="/help/search/1">Search datasets on your browser</Link>
</li>
<li>
<Link to="/help/dataset">Downloadable dataset format</Link>
</li>
<li>
<Link to="/help/viewer">3D Viewer Mannual</Link>
</li>
</ul>
);
};
const HelpSearchLinks = (
<div className={styles.search_links}>
<ul>
<li>
<Link to="/help/search/1">Step 1</Link>
</li>
<li>
<Link to="/help/search/2">Step 2</Link>
</li>
<li>
<Link to="/help/search/3">Step 3</Link>
</li>
<li>
<Link to="/help/search/4">Step 4</Link>
</li>
<li>
<Link to="/help/search/5">Step 5</Link>
</li>
</ul>
</div>
);
const HelpSearch1 = () => {
const title = "Help - Search dataset - Step 1";
const dispatch = useAppDispatch();
useEffect(() => {
dispatch(setTitle(title));
}, [dispatch, title]);
return (
<div>
{HelpSearchLinks}
<div className={styles.title}>Step 1</div>
<p>Click the "Search" link above.</p>
<div className={styles.figure}>
<img src="/images/help-search1.jpg" alt={title} />
</div>
</div>
);
};
const HelpSearch2 = () => {
const title = "Help - Search dataset - Step 2";
const dispatch = useAppDispatch();
useEffect(() => {
dispatch(setTitle(title));
}, [dispatch, title]);
return (
<div>
{HelpSearchLinks}
<div className={styles.title}>Step 2</div>
<p>Set parameter value and/or chose options.</p>
<div className={styles.figure}>
<img src="/images/help-search2.jpg" alt={title} />
</div>
</div>
);
};
const HelpSearch3 = () => {
const title = "Help - Search dataset - Step 3";
const dispatch = useAppDispatch();
useEffect(() => {
dispatch(setTitle(title));
}, [dispatch, title]);
return (
<div>
{HelpSearchLinks}
<div className={styles.title}>Step 3</div>
<p>Click the "Search" button.</p>
<div className={styles.figure}>
<img src="/images/help-search3.jpg" alt={title} />
</div>
</div>
);
};
const HelpSearch4 = () => {
const title = "Help - Search dataset - Step 4";
const dispatch = useAppDispatch();
useEffect(() => {
dispatch(setTitle(title));
}, [dispatch, title]);
return (
<div>
{HelpSearchLinks}
<div className={styles.title}>Step 4</div>
<p>Chose datasets that you want to download. Click dataset ID.</p>
<div className={styles.figure}>
<img src="/images/help-search4.jpg" alt={title} />
</div>
</div>
);
};
const HelpSearch5 = () => {
const title = "Help - Search dataset - Step 5";
const dispatch = useAppDispatch();
useEffect(() => {
dispatch(setTitle(title));
}, [dispatch, title]);
return (
<div>
{HelpSearchLinks}
<div className={styles.title}>Step 5</div>
<p>
The result page consists of details of the dataset.
<br />
Click the links in the "Download &amp; View" section to download the dataset and/or view 3D model on your browser.{" "}
</p>
<div className={styles.figure}>
<img src="/images/help-search5.jpg" alt={title} />
</div>
</div>
);
};
const HelpDataset = () => {
const title = "Help - Downloadable dataset format";
const dispatch = useAppDispatch();
useEffect(() => {
dispatch(setTitle(title));
}, [dispatch, title]);
return (
<section>
<div className={styles.title}>Dataset Format</div>
<div className={styles.figure}>
<img src="/images/help-dataset.jpg" alt={title} />
</div>
<p>
<span className={styles.legend}>First row:</span> The first row of the data file indicates the size of the imaging volume. The first, second and third column represent the width, height and depth of the volume, respectively.
</p>
<p>
<span className={styles.legend}>Other rows:</span> Each row consists of the type (first column) and the position (second to fourth columns for x, y and z position) of the cell.
</p>
</section>
);
};
const HelpViewer = () => {
const title = "Help - 3D Viewer Manual";
const dispatch = useAppDispatch();
useEffect(() => {
dispatch(setTitle(title));
}, [dispatch, title]);
return (
<section>
<div className={styles.title}>3D Viewer Manual</div>
<div className={styles.figure}>
<img src="/images/help-viewer.jpg" alt={title} />
</div>
<p>
<span className={styles.legend}>Rotate:</span> Left click and drag.
</p>
<p>
<span className={styles.legend}>Move:</span> Right click and drag.
</p>
<p>
<span className={styles.legend}>Zoom In/Out:</span> Use mouse wheel.
</p>
</section>
);
};
const Help: React.FC = () => {
return (
<div className={styles.help}>
<Routes>
<Route index element={<HelpIndex />} />
<Route path="search/1" element={<HelpSearch1 />} />
<Route path="search/2" element={<HelpSearch2 />} />
<Route path="search/3" element={<HelpSearch3 />} />
<Route path="search/4" element={<HelpSearch4 />} />
<Route path="search/5" element={<HelpSearch5 />} />
<Route path="dataset" element={<HelpDataset />} />
<Route path="viewer" element={<HelpViewer />} />
<Route path="*" element={<NotFound />} />
</Routes>
</div>
);
};
export default Help;

View File

@ -0,0 +1,4 @@
.loading {
margin: 120px 0;
text-align: center;
}

View File

@ -0,0 +1,15 @@
import React, { useEffect } from "react";
import { useAppDispatch } from "../../app/hooks";
import { setTitle } from "../page-title/pageTitleSlice";
import styles from "./Loading.module.css";
const Loading: React.FC = () => {
const dispatch = useAppDispatch();
useEffect(() => {
dispatch(setTitle("Loading now..."));
}, [dispatch]);
return <div className={styles.loading}>Loading now...</div>;
};
export default Loading;

View File

@ -0,0 +1,24 @@
.news {
margin: 10px;
}
.item {
margin: 0 10px 10px 10px;
}
.item:after {
content: ".";
display: block;
height: 0;
font-size: 0;
clear: both;
visibility: hidden;
}
.date {
width: 25%;
float: left;
text-align: left;
}
.desc {
width: 70%;
float: right;
text-align: left;
}

View File

@ -0,0 +1,37 @@
import React, { useEffect } from "react";
import { useAppDispatch } from "../../app/hooks";
import JsonNews_ from "../../assets/news.json";
import { setTitle } from "../page-title/pageTitleSlice";
import styles from "./News.module.css";
const nl2br = require("react-nl2br");
interface IJsonNewsItem {
date: string;
desc: string;
}
type IJsonNews = IJsonNewsItem[];
const JsonNews: IJsonNews = JsonNews_;
const News: React.FC = () => {
const dispatch = useAppDispatch();
useEffect(() => {
dispatch(setTitle("What's new"));
}, [dispatch]);
return (
<div className={styles.news}>
{JsonNews.map((item, key) => {
return (
<div className={styles.item} key={key}>
<div className={styles.date}>{item.date}</div>
<div className={styles.desc}>{nl2br(item.desc)}</div>
</div>
);
})}
</div>
);
};
export default News;

View File

@ -0,0 +1,4 @@
.notFound {
margin: 120px 0;
text-align: center;
}

View File

@ -0,0 +1,15 @@
import React, { useEffect } from "react";
import { useAppDispatch } from "../../app/hooks";
import { setTitle } from "../page-title/pageTitleSlice";
import styles from "./NotFound.module.css";
const NotFound: React.FC = () => {
const dispatch = useAppDispatch();
useEffect(() => {
dispatch(setTitle("Page Not Found"));
}, [dispatch]);
return <div className={styles.notFound}>Page not found.</div>;
};
export default NotFound;

View File

@ -0,0 +1,6 @@
.pageTitle {
width: 100%;
height: 30px;
font-size: 150%;
margin-bottom: 10px;
}

View File

@ -0,0 +1,19 @@
import React from "react";
import { Helmet } from "react-helmet-async";
import { useAppSelector } from "../../app/hooks";
import styles from "./PageTitle.module.css";
import { selectPageTitle } from "./pageTitleSlice";
const PageTitle: React.FC = () => {
const title = useAppSelector(selectPageTitle);
return (
<>
<Helmet>
<title>{title} - CelLoc3D Server</title>
</Helmet>
<div className={styles.pageTitle}>{title}</div>
</>
);
};
export default PageTitle;

View File

@ -0,0 +1,25 @@
import { createSlice, PayloadAction } from "@reduxjs/toolkit";
import { RootState } from "../../app/store";
export interface PageTitleState {
value: string;
}
const initialState: PageTitleState = {
value: "",
};
const pageTitleSlice = createSlice({
name: "pageTitle",
initialState,
reducers: {
setTitle: (state, action: PayloadAction<string>) => {
state.value = action.payload;
},
},
});
export const { setTitle } = pageTitleSlice.actions;
export const selectPageTitle = (state: RootState) => state.pageTitle.value;
export default pageTitleSlice.reducer;

View File

@ -0,0 +1,41 @@
.formGroup {
margin: 0 10px;
height: 40px;
}
.formGroup:after {
content: ".";
display: block;
height: 0;
font-size: 0;
clear: both;
visibility: hidden;
}
.formGroup label {
width: 55%;
float: left;
}
.value {
float: right;
text-align: right;
}
.range {
margin: 0 10px;
}
.txtParam {
width: 50px;
}
.txtParamStr {
width: 100px;
}
.txtKeyword {
width: 150px;
}
.selParam {
width: 150px;
}
.submit {
text-align: center;
}
.submit input {
padding: 5px 15px;
}

View File

@ -0,0 +1,198 @@
import React, { Component } from "react";
import { useNavigate } from "react-router-dom";
import { useAppDispatch } from "../../app/hooks";
import DataUtils, { SearchResults } from "../data/DataUtils";
import { setTitle } from "../page-title/pageTitleSlice";
import { setResults } from "../search-results/searchResultsSlice";
import styles from "./SearchForm.module.css";
interface FCProps {}
interface Props extends FCProps {
navigate: any;
dispatch: any;
}
interface State {
pdStart: string;
pdEnd: string;
widthMin: string;
widthMax: string;
depthMin: string;
depthMax: string;
cellType: string;
area: string;
geneType: string;
keyword: string;
}
class SearchForm extends Component<Props, State> {
constructor(props: Props) {
super(props);
this.state = {
pdStart: "44",
pdEnd: "100",
widthMin: "317",
widthMax: "512",
depthMin: "90",
depthMax: "230",
cellType: "any",
area: "all",
geneType: "all",
keyword: "",
};
this.handleInputChange = this.handleInputChange.bind(this);
this.handleSelectChange = this.handleSelectChange.bind(this);
this.handleSubmit = this.handleSubmit.bind(this);
}
componentDidMount() {
this.props.dispatch(setTitle("Database Search"));
}
doSearch(): SearchResults {
const toNumber = (v: string): number => parseInt(v.trim(), 10);
const params = {
pdStart: toNumber(this.state.pdStart),
pdEnd: toNumber(this.state.pdEnd),
widthMin: toNumber(this.state.widthMin),
widthMax: toNumber(this.state.widthMax),
depthMin: toNumber(this.state.depthMin),
depthMax: toNumber(this.state.depthMax),
cellType: this.state.cellType.trim(),
area: this.state.area.trim(),
geneType: this.state.geneType.trim(),
keyword: this.state.keyword.trim(),
};
return DataUtils.search(params);
}
handleInputChange: React.ChangeEventHandler<HTMLInputElement> = (event: React.ChangeEvent<HTMLInputElement>) => {
const target = event.target;
const value = target.value;
const name = target.name;
switch (name) {
case "pdStart":
this.setState({ pdStart: value });
break;
case "pdEnd":
this.setState({ pdStart: value });
break;
case "widthMin":
this.setState({ widthMin: value });
break;
case "widthMax":
this.setState({ widthMax: value });
break;
case "depthMin":
this.setState({ depthMin: value });
break;
case "depthMax":
this.setState({ depthMax: value });
break;
case "cellType":
this.setState({ cellType: value });
break;
case "keyword":
this.setState({ keyword: value });
break;
}
};
handleSelectChange: React.ChangeEventHandler<HTMLSelectElement> = (event: React.ChangeEvent<HTMLSelectElement>) => {
const target = event.target;
const value = target.value;
const name = target.name;
switch (name) {
case "area":
this.setState({ area: value });
break;
case "geneType":
this.setState({ geneType: value });
break;
}
};
handleSubmit: React.FormEventHandler<HTMLFormElement> = (event: React.FormEvent) => {
event.preventDefault();
const results = this.doSearch();
this.props.dispatch(setResults(results));
this.props.navigate("/search/results");
};
render() {
return (
<form onSubmit={this.handleSubmit}>
<div className={styles.formGroup}>
<label htmlFor="pdStart">Postnatal Days</label>
<div className={styles.value}>
<input type="number" name="pdStart" className={styles.txtParam} value={this.state.pdStart} onChange={this.handleInputChange} />
<span className={styles.range}>-</span>
<input type="number" name="pdEnd" className={styles.txtParam} value={this.state.pdEnd} onChange={this.handleInputChange} />
</div>
</div>
<div className={styles.formGroup}>
<label htmlFor="widthMin">Recording volume width (height)</label>
<div className={styles.value}>
<input type="number" name="widthMin" className={styles.txtParam} value={this.state.widthMin} onChange={this.handleInputChange} />
<span className={styles.range}>-</span>
<input type="number" name="widthMax" className={styles.txtParam} value={this.state.widthMax} onChange={this.handleInputChange} />
</div>
</div>
<div className={styles.formGroup}>
<label htmlFor="depthMin">Recording volume depth</label>
<div className={styles.value}>
<input type="number" name="depthMin" className={styles.txtParam} value={this.state.depthMin} onChange={this.handleInputChange} />
<span className={styles.range}>-</span>
<input type="number" name="depthMax" className={styles.txtParam} value={this.state.depthMax} onChange={this.handleInputChange} />
</div>
</div>
<div className={styles.formGroup}>
<label htmlFor="cellType">Cell type (E, I, G, P, S, or "any")</label>
<div className={styles.value}>
<input type="text" name="cellType" className={styles.txtParamStr} value={this.state.cellType} onChange={this.handleInputChange} />
</div>
</div>
<div className={styles.formGroup}>
<label htmlFor="area">Target area</label>
<div className={styles.value}>
<select name="area" className={styles.selParam} value={this.state.area} onChange={this.handleSelectChange}>
<option value="all">All</option>
<option value="L2/3, V1">L2/3 in the visual cortex</option>
</select>
</div>
</div>
<div className={styles.formGroup}>
<label htmlFor="geneType">Mouse line</label>
<div className={styles.value}>
<select name="geneType" className={styles.selParam} value={this.state.geneType} onChange={this.handleSelectChange}>
<option value="all">All</option>
<option value="VGAT-Venus">VGAT-Venus</option>
<option value="PV/myrGFP-LDLRct">PV/myrGFP-LDLRct</option>
<option value="Dlx5/6-GCaMP3">Dlx5/6-GCaMP3</option>
</select>
</div>
</div>
<div className={styles.formGroup}>
<label htmlFor="keyword">Keyword Search</label>
<div className={styles.value}>
<input type="text" name="keyword" className={styles.txtKeyword} value={this.state.keyword} onChange={this.handleInputChange} />
</div>
</div>
<div className={styles.formGroup}>
<div className={styles.submit}>
<input type="submit" value="Search" />
</div>
</div>
</form>
);
}
}
const SearchFormFC: React.FC<FCProps> = (props: FCProps) => {
const navigate = useNavigate();
const dispatch = useAppDispatch();
return <SearchForm navigate={navigate} dispatch={dispatch} />;
};
export default SearchFormFC;

View File

@ -0,0 +1,17 @@
.empty,
.error {
margin: 120px 0;
text-align: center;
}
.error {
color: red;
}
.result {
margin: 10px 10px 20px 10px;
}
.title {
font-size: 105%;
}
.remark {
margin: 5px 5px 0 10px;
}

View File

@ -0,0 +1,37 @@
import React, { useEffect } from "react";
import { Link } from "react-router-dom";
import { useAppDispatch, useAppSelector } from "../../app/hooks";
import { setTitle } from "../page-title/pageTitleSlice";
import styles from "./SearchResults.module.css";
import { selectSearchResults } from "./searchResultsSlice";
const SearchResults: React.FC = () => {
const results = useAppSelector(selectSearchResults);
const dispatch = useAppDispatch();
useEffect(() => {
dispatch(setTitle("Search Results"));
}, [dispatch]);
return (
<div>
{results.length === 0 ? (
<div className={styles.empty}>No search results found.</div>
) : (
results.map((result, key) => {
return (
<div className={styles.result} key={key}>
<div className={styles.title}>
<Link to={`/data/${result.name}`}>
{key + 1}. {result.name}
</Link>
</div>
<div className={styles.remark}>{result.item.remark}</div>
</div>
);
})
)}
</div>
);
};
export default SearchResults;

View File

@ -0,0 +1,26 @@
import { createSlice, PayloadAction } from "@reduxjs/toolkit";
import { RootState } from "../../app/store";
import { SearchResults } from "../data/DataUtils";
export interface SearchResultsState {
value: SearchResults;
}
const initialState: SearchResultsState = {
value: [],
};
const searchResultsSlice = createSlice({
name: "searchResults",
initialState,
reducers: {
setResults: (state, action: PayloadAction<SearchResults>) => {
state.value = action.payload;
},
},
});
export const { setResults } = searchResultsSlice.actions;
export const selectSearchResults = (state: RootState) => state.searchResults.value;
export default searchResultsSlice.reducer;

View File

@ -0,0 +1,3 @@
.search {
margin: 10px;
}

View File

@ -0,0 +1,20 @@
import React from "react";
import { Route, Routes } from "react-router-dom";
import NotFound from "../not-found/NotFound";
import SearchForm from "../search-form/SearchForm";
import SearchResults from "../search-results/SearchResults";
import styles from "./Search.module.css";
const Search: React.FC = () => {
return (
<div className={styles.search}>
<Routes>
<Route index element={<SearchForm />} />
<Route path="results" element={<SearchResults />} />
<Route path="*" element={<NotFound />} />
</Routes>
</div>
);
};
export default Search;

13
src/index.css Normal file
View File

@ -0,0 +1,13 @@
@import-normalize;
body {
margin: 0;
padding: 0;
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Roboto", "Oxygen", "Ubuntu", "Cantarell", "Fira Sans", "Droid Sans", "Helvetica Neue", sans-serif;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
}
code {
font-family: source-code-pro, Menlo, Monaco, Consolas, "Courier New", monospace;
}

26
src/index.tsx Normal file
View File

@ -0,0 +1,26 @@
import React from "react";
import "react-app-polyfill/ie11";
import "react-app-polyfill/stable";
import ReactDOM from "react-dom";
import { HelmetProvider } from "react-helmet-async";
import { Provider } from "react-redux";
import App from "./App";
import { store } from "./app/store";
import "./index.css";
// import * as serviceWorker from "./serviceWorker";
ReactDOM.render(
<React.StrictMode>
<Provider store={store}>
<HelmetProvider>
<App />
</HelmetProvider>
</Provider>
</React.StrictMode>,
document.getElementById("root")
);
// If you want your app to work offline and load faster, you can change
// unregister() to register() below. Note this comes with some pitfalls.
// Learn more about service workers: https://bit.ly/CRA-PWA
// serviceWorker.unregister();

1
src/react-app-env.d.ts vendored Normal file
View File

@ -0,0 +1 @@
/// <reference types="react-scripts" />

133
src/serviceWorker.ts Normal file
View File

@ -0,0 +1,133 @@
// This optional code is used to register a service worker.
// register() is not called by default.
// This lets the app load faster on subsequent visits in production, and gives
// it offline capabilities. However, it also means that developers (and users)
// will only see deployed updates on subsequent visits to a page, after all the
// existing tabs open on the page have been closed, since previously cached
// resources are updated in the background.
// To learn more about the benefits of this model and instructions on how to
// opt-in, read https://bit.ly/CRA-PWA
const isLocalhost = Boolean(
window.location.hostname === "localhost" ||
// [::1] is the IPv6 localhost address.
window.location.hostname === "[::1]" ||
// 127.0.0.0/8 are considered localhost for IPv4.
window.location.hostname.match(/^127(?:\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}$/)
);
type Config = {
onSuccess?: (registration: ServiceWorkerRegistration) => void;
onUpdate?: (registration: ServiceWorkerRegistration) => void;
};
export function register(config?: Config) {
if (process.env.NODE_ENV === "production" && "serviceWorker" in navigator) {
// The URL constructor is available in all browsers that support SW.
const publicUrl = new URL(process.env.PUBLIC_URL, window.location.href);
if (publicUrl.origin !== window.location.origin) {
// Our service worker won't work if PUBLIC_URL is on a different origin
// from what our page is served on. This might happen if a CDN is used to
// serve assets; see https://github.com/facebook/create-react-app/issues/2374
return;
}
window.addEventListener("load", () => {
const swUrl = `${process.env.PUBLIC_URL}/service-worker.js`;
if (isLocalhost) {
// This is running on localhost. Let's check if a service worker still exists or not.
checkValidServiceWorker(swUrl, config);
// Add some additional logging to localhost, pointing developers to the
// service worker/PWA documentation.
navigator.serviceWorker.ready.then(() => {
console.log("This web app is being served cache-first by a service " + "worker. To learn more, visit https://bit.ly/CRA-PWA");
});
} else {
// Is not localhost. Just register service worker
registerValidSW(swUrl, config);
}
});
}
}
function registerValidSW(swUrl: string, config?: Config) {
navigator.serviceWorker
.register(swUrl)
.then((registration) => {
registration.onupdatefound = () => {
const installingWorker = registration.installing;
if (installingWorker == null) {
return;
}
installingWorker.onstatechange = () => {
if (installingWorker.state === "installed") {
if (navigator.serviceWorker.controller) {
// At this point, the updated precached content has been fetched,
// but the previous service worker will still serve the older
// content until all client tabs are closed.
console.log("New content is available and will be used when all " + "tabs for this page are closed. See https://bit.ly/CRA-PWA.");
// Execute callback
if (config && config.onUpdate) {
config.onUpdate(registration);
}
} else {
// At this point, everything has been precached.
// It's the perfect time to display a
// "Content is cached for offline use." message.
console.log("Content is cached for offline use.");
// Execute callback
if (config && config.onSuccess) {
config.onSuccess(registration);
}
}
}
};
};
})
.catch((error) => {
console.error("Error during service worker registration:", error);
});
}
function checkValidServiceWorker(swUrl: string, config?: Config) {
// Check if the service worker can be found. If it can't reload the page.
fetch(swUrl, {
headers: { "Service-Worker": "script" },
})
.then((response) => {
// Ensure service worker exists, and that we really are getting a JS file.
const contentType = response.headers.get("content-type");
if (response.status === 404 || (contentType != null && contentType.indexOf("javascript") === -1)) {
// No service worker found. Probably a different app. Reload the page.
navigator.serviceWorker.ready.then((registration) => {
registration.unregister().then(() => {
window.location.reload();
});
});
} else {
// Service worker found. Proceed as normal.
registerValidSW(swUrl, config);
}
})
.catch(() => {
console.log("No internet connection found. App is running in offline mode.");
});
}
export function unregister() {
if ("serviceWorker" in navigator) {
navigator.serviceWorker.ready
.then((registration) => {
registration.unregister();
})
.catch((error) => {
console.error(error.message);
});
}
}

5
src/setupTests.ts Normal file
View File

@ -0,0 +1,5 @@
// jest-dom adds custom jest matchers for asserting on DOM nodes.
// allows you to do things like:
// expect(element).toHaveTextContent(/react/i)
// learn more: https://github.com/testing-library/jest-dom
import "@testing-library/jest-dom/extend-expect";