Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add development guide #74

Merged
merged 1 commit into from
Dec 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions development.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Development guide

This project uses React framework with Typescript.
It uses Webpack to manage module bundles and assets.

## Project structure

All high-level development configurations (e.g. typescript, babel, and eslint) are in their own dedicated files in project root.

The project has a `pre-commit` hook that prevents committing changes that violate typing and linting configs.
To check if the code passes the checks, run `npm run lint` and `npx tsc`. Running `npm run lint:fix` will try to fix the issues that can be resolved automatically.

### Webpack

All webpack configs are in `webpack.*.js`.

Some dependencies like `maplibre` are bundled through their own entry in `entry` config to help with chunk size.

Browser polyfills (`src/polyfill.js`), global styling of the app (`src/styles/main.scss`), and global config (`src/config.js`) are loaded directly using their own dedicated entry in webpack.

The HTML entrypoint is `src/index.html`, which is loaded by `webpack-html-plugin`. Any global asset or remote resources (e.g. fonts) can be added here. The transpiled React code is injected into this file by webpack.

`webpack.dev.js` is used with `start` script in `package.json` for development, and `webpack.prod.js` is used with `build` script.

### Code

Description of main files under `src` folder.

| file/folder | description |
|-------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| app.tsx | The main entrypoint. It sets up the app, routing, default styling and themes, and some localizations.<br/>It also fetches some permanent data that is needed from the API in a `React.useEffect` hook.<br/>The rest of the data are fetches on-demand. |
| routes.tsx | Contains routes config. This config is used in `app.tsx` |
| store/context.ts | Uses React Context to store the data describing the state of the app, and functions for updating it. |
| store/reducers.ts | Reducers are functions that update the state stored in the context with the data received from dispatchers. |
| store/states.ts | The initial state of the app. |
| store/api.ts | Helper functions to interact with the API. |
| types/* | Typescript types |
| components/* | React components |
2 changes: 1 addition & 1 deletion src/components/Home/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ const Home = (): JSX.Element => (
}}
variant="h2"
>
The World&apos;s First Expedition of the Deep Sea
The World&apos;s First Exploration of the Deep Sea
</Typography>

<Typography
Expand Down
6 changes: 6 additions & 0 deletions src/routes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ import Loading from './components/Loading';

const LazyHome = lazy(() => import('./components/Home'));

/**
A mapping of routes to `RouteProps`.
The required property for each route is `element`, which must be a valid React component.

This mapping is used in `src/app.tsx` to set up all the routes.
* */
const routes: { [key: string]: import('react-router-dom').RouteProps } = {
'/': {
element: (
Expand Down
6 changes: 6 additions & 0 deletions src/store/contexts.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
/**
* Various context storage that hold data and functions that can be used by different components.
* These are accessible in any place in the app that `React.useContext` can be used.
* For clarity, data and dispatchers (functions that update the state) are store in separate contexts.
*/

import React from 'react';

import { dataStateInitialValue, filtersStateInitialValue } from './states';
Expand Down