Skip to content

Commit 54ac874

Browse files
committed
Merge branch 'beta'
2 parents 2a9cbc1 + 83c8c64 commit 54ac874

File tree

7 files changed

+87
-31
lines changed

7 files changed

+87
-31
lines changed

package-lock.json

Lines changed: 58 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
"gedcomx-js": "^2.8.0",
3333
"react": "^18.1.0",
3434
"react-dom": "^18.1.0",
35+
"react-router-dom": "^6.3.0",
3536
"react-scripts": "5.0.1",
3637
"typescript": "^4.7.4",
3738
"web-vitals": "^2.1.4",

src/App.tsx

Lines changed: 18 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import Uploader from "./components/Uploader";
99
import View from "./components/View";
1010
import {graphModel, loadData} from "./backend/ModelGraph";
1111
import {ReactNode} from "react";
12+
import {BrowserRouter, Route, Routes} from "react-router-dom";
1213

1314
interface State {
1415
notifications: ReactNode[]
@@ -31,35 +32,29 @@ class App extends React.Component<any, State> {
3132
}
3233

3334
render() {
34-
if (!this.state.dataAvailable) {
35-
// show upload form
36-
return (
37-
<>
38-
<Header/>
39-
<main>
40-
{this.state.notifications}
41-
<Uploader onFileSelected={this.onFileSelected.bind(this)}/>
42-
<NavigationTutorial/>
43-
</main>
44-
</>
45-
);
46-
}
47-
48-
return (
49-
<>
50-
<Header/>
35+
return <BrowserRouter basename={"family-tree"}>
36+
<Header/>
5137
{this.state.notifications}
52-
<View/>
53-
</>
54-
);
38+
<Routes>
39+
<Route path="/" element={
40+
<main>
41+
<Uploader onFileSelected={this.onFileSelected.bind(this)}/>
42+
<NavigationTutorial/>
43+
</main>
44+
}/>
45+
<Route path="/view" element={<View/>}/>
46+
</Routes>
47+
</BrowserRouter>
5548
}
5649

5750
onFileSelected(fileContent) {
5851
sessionStorage.setItem("familyData", fileContent);
5952
loadData(JSON.parse(fileContent));
60-
this.setState({
61-
dataAvailable: true
62-
});
53+
if (window.location.href.endsWith("/")) {
54+
window.location.href += "view";
55+
} else {
56+
window.location.href += "/view";
57+
}
6358
}
6459

6560
componentDidMount() {

src/backend/ModelGraph.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ class ModelGraph extends GedcomX.Root {
5858
}
5959

6060
let startPerson: GedcomX.Person;
61-
if (startId !== null) {
61+
if (startId !== null && startId.length > 0) {
6262
startPerson = this.getPersonById(startId);
6363
} else {
6464
startPerson = this.persons[0];

src/components/Header.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
import './Header.css';
2+
import {Link} from 'react-router-dom';
23
import {translationToString} from "../main";
34

45
function Header() {
56
return (
67
<header>
7-
<a href="/" onClick={removeData}>
8+
<Link to="/" onClick={removeData}>
89
<img src={process.env.PUBLIC_URL + "/logo.svg"} width="40" height="100%" alt={translationToString({
910
en: "A smiling tree.",
1011
de: "Ein lächelnder Baum."
1112
}) + " 🌳"}/>
12-
</a>
13+
</Link>
1314
<span id="title">{translationToString({
1415
en: "Family tree",
1516
de: "Stammbaum"

src/components/InfoPanel.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import {Component} from "react";
33
import SearchField from "./SearchField";
44
import {Person} from "gedcomx-js";
55
import {PersonFactTypes} from "../backend/gedcomx-enums";
6+
import {Link} from "react-router-dom";
67

78
interface Props {
89
onRefocus: (newFocus: Person) => void,
@@ -14,9 +15,9 @@ class InfoPanel extends Component<Props, null> {
1415
let person = this.props.person;
1516
return (
1617
<aside id="info-panel">
17-
<a href={"?id=" + person.getId()}>
18+
<Link to={`#${person.getId()}`}>
1819
<pre className="id">{person.getId()}</pre>
19-
</a>
20+
</Link>
2021
<SearchField onRefocus={this.props.onRefocus} person={person}/>
2122
{person.getMarriedName() && <h2 className="birth-name">{person.getBirthName()}</h2>}
2223
{person.getAlsoKnownAs() && <h2 className="alsoKnownAs">{person.getAlsoKnownAs()}</h2>}

src/components/View.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,12 +76,12 @@ class View extends Component<any, State> {
7676
let view: string = url.searchParams.get("view-all") || ViewMode.DEFAULT;
7777
console.debug(`View: ${view}`);
7878

79-
let focusId = url.searchParams.get("id");
79+
let focusId = url.hash.substring(1);
8080
let viewGraph = graphModel.buildViewGraph(focusId, ViewMode[view]);
8181
console.assert(viewGraph.nodes.length > 0,
82-
"Viewgraph has no nodes!");
82+
"View graph has no nodes!");
8383
console.assert(viewGraph.links.length > 0,
84-
"Viewgraph has no links!");
84+
"View graph has no links!");
8585
this.state = {
8686
activeView: view,
8787
viewGraph: viewGraph,

0 commit comments

Comments
 (0)