Skip to content

Commit e3021c1

Browse files
author
AdamMorris
committed
Stubbed out a lot of the store and got data loading.
1 parent cd3fc2c commit e3021c1

23 files changed

+404
-20
lines changed

.editorconfig

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
[*]
2+
end_of_line = lf
3+
insert_final_newline = true
4+
5+
[*.{js,ts,jsx,tsx}]
6+
indent_size = 2
7+
indent_style = space

package.json

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,14 @@
77
"@types/node": "12.7.5",
88
"@types/react": "16.9.2",
99
"@types/react-dom": "16.9.0",
10+
"@types/react-redux": "^7.1.2",
1011
"react": "^16.9.0",
1112
"react-dom": "^16.9.0",
13+
"react-redux": "^7.1.1",
1214
"react-scripts": "3.1.1",
15+
"redux": "^4.0.4",
16+
"redux-devtools-extension": "^2.13.8",
17+
"redux-saga": "^1.0.5",
1318
"typescript": "3.6.3"
1419
},
1520
"scripts": {
@@ -19,7 +24,14 @@
1924
"eject": "react-scripts eject"
2025
},
2126
"eslintConfig": {
22-
"extends": "react-app"
27+
"extends": "react-app",
28+
"rules": {
29+
"quotes": "double",
30+
"comma-dangle": [
31+
"error",
32+
"always-multiline"
33+
]
34+
}
2335
},
2436
"browserslist": {
2537
"production": [
File renamed without changes.

src/App.tsx

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,18 @@
1-
import React from "react";
2-
import logo from "./logo.svg";
1+
import React, { useState } from "react";
32
import "./App.css";
3+
import { IProjectInfo } from "./interfaces/IProjectInfo";
4+
import ProjectList from "./components/ProjectList";
45

56
const App: React.FC = () => {
7+
const [] = useState<IProjectInfo[]>([]);
8+
69
return (
7-
<div className="App">
8-
<header className="App-header">
9-
<p>
10-
Edit <code>src/App.tsx</code> and save to reload.
11-
</p>
12-
<a
13-
className="App-link"
14-
href="https://reactjs.org"
15-
target="_blank"
16-
rel="noopener noreferrer"
17-
>
18-
Learn React
19-
</a>
20-
</header>
21-
</div>
10+
<>
11+
<div className="header">
12+
<h1>glTF Project Explorer</h1>
13+
</div>
14+
<ProjectList></ProjectList>
15+
</>
2216
);
2317
};
2418

src/components/FilterBar.tsx

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import React from "react";
2+
import { IProjectInfo } from "../interfaces/IProjectInfo";
3+
4+
export interface IFilterBarProps {
5+
projects: IProjectInfo[];
6+
}
7+
8+
const FilterBar: React.FC<IFilterBarProps> = props => {
9+
return <div>This will be the filter bar.</div>;
10+
};
11+
12+
// TODO: Connect the filter bar.
13+
14+
export default FilterBar;

src/components/ProjectList.tsx

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import React from "react";
2+
import { connect } from "react-redux";
3+
import { IProjectInfo } from "../interfaces/IProjectInfo";
4+
import { IAppState } from "../interfaces/IAppState";
5+
6+
export interface IProjectListProps {
7+
projects: IProjectInfo[];
8+
}
9+
10+
const ProjectList: React.FC<IProjectListProps> = props => {
11+
const { projects } = props;
12+
13+
return (
14+
<>
15+
<ul>
16+
{projects &&
17+
projects.map(p => <li key={`${p.name}_${p.link}`}>{p.name}</li>)}
18+
</ul>
19+
</>
20+
);
21+
};
22+
23+
function mapStateToProps(state: IAppState): IProjectListProps {
24+
const {
25+
projects: { values: projects }
26+
} = state;
27+
28+
return { projects };
29+
}
30+
31+
export default connect(mapStateToProps)(ProjectList);

src/index.tsx

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,41 @@
11
import React from "react";
22
import ReactDOM from "react-dom";
3+
import { Provider } from "react-redux";
4+
import { applyMiddleware, createStore } from "redux";
5+
import { composeWithDevTools } from "redux-devtools-extension";
6+
import createSagaMiddleware from "@redux-saga/core";
37
import "./index.css";
48
import App from "./App";
9+
import rootReducer from "./store/Reducers";
10+
import rootSagas from "./store/Sagas";
511

6-
ReactDOM.render(<App />, document.getElementById("root"));
12+
// A note about the use of redux here; a lot of inner deliberations were made
13+
// before choosing to pull in both Redux and Sagas for this app. The idea is
14+
// to keep this app mostly simple, but Redux and Sagas were pulled in for two
15+
// major reasons:
16+
//
17+
// 1. We have to communicate data changes across the app to several components.
18+
// 2. Redux makes managing complex state changes (such as filtering) easy.
19+
//
20+
// Yes, this is probably over-engineered, but Redux is the best tool for this
21+
// potentially complex task. If you hate it, blame me and I'd be glad to bike
22+
// shed about it with you. -ANM
23+
24+
const initialState = {};
25+
26+
const sagaMiddleware = createSagaMiddleware({});
27+
28+
const store = createStore(
29+
rootReducer,
30+
initialState,
31+
composeWithDevTools(applyMiddleware(sagaMiddleware))
32+
);
33+
34+
sagaMiddleware.run(rootSagas);
35+
36+
ReactDOM.render(
37+
<Provider store={store}>
38+
<App />
39+
</Provider>,
40+
document.getElementById("root") as HTMLElement
41+
);

src/interfaces/IAppState.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import { IProjectInfo } from "./IProjectInfo";
2+
3+
export interface IProjectsState {
4+
isFetchingProjects: boolean;
5+
values: IProjectInfo[];
6+
}
7+
8+
export interface IAppState {
9+
projects: IProjectsState;
10+
}

src/interfaces/IProjectInfo.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
export interface IProjectInfo {
2+
name: string;
3+
description?: string;
4+
link?: string;
5+
task?: string[];
6+
license?: string[];
7+
type?: string[];
8+
language?: string[];
9+
inputs?: string[];
10+
outputs?: string[];
11+
}

src/services/DataService.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { IProjectInfo } from "../interfaces/IProjectInfo";
2+
3+
// Despite the data being a static file, we don't pull it in using Webpack so
4+
// we can change to using a restful service in the future.
5+
export function fetchProjects(): Promise<IProjectInfo[]> {
6+
return fetch("./data/glTF-projects-data.json")
7+
.then(r => r.json())
8+
.catch(error => console.error(`Error fetching data. Reason: ${error}`));
9+
}

0 commit comments

Comments
 (0)