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

WIP: Feat/state managment #20

Open
wants to merge 22 commits into
base: master
Choose a base branch
from
Open
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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
# production
/build

# webstorm
.idea

# misc
.DS_Store
.env
Expand Down
44 changes: 31 additions & 13 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,19 @@
"@vx/gradient": "^0.0.195",
"d3-array": "^2.4.0",
"d3-dsv": "^1.2.0",
"d3-ease": "^1.0.6",
"d3-scale": "^3.2.1",
"d3-shape": "^1.3.7",
"date-fns": "^2.12.0",
"deck.gl": "^8.1.1",
"global": "^4.4.0",
"now": "^17.1.1",
"positic": "1.0.10",
"react": "^16.13.0",
"react-dom": "^16.13.0",
"react-map-gl": "^5.2.3",
"react-scripts": "3.4.0",
"recoil": "0.0.11",
"source-map-explorer": "^2.4.2",
"styled-components": "^5.0.1",
"styled-icons": "^10.2.1",
Expand Down
Binary file modified public/favicon.ico
Binary file not shown.
Binary file modified public/logo192.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified public/logo512.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
36 changes: 34 additions & 2 deletions src/App.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React from "react";
import { createGlobalStyle, ThemeProvider } from "styled-components";
import { RecoilRoot, useRecoilTransactionObserver_UNSTABLE } from "recoil";

import MarvinFont from "./assets/fonts/MarvinVisionsTrial-Variable.ttf";
import Main from "./components/main/Main";
Expand Down Expand Up @@ -40,13 +41,36 @@ body {
background: #1f252d;
margin:0;
font-family: MyFont;
font-weight: 170;
font-weight: 200;
font-variation-settings: "opsz" 99;
font-feature-settings: "ss02" 0,"ss03" 0,"ss06" 0;
}
`;

const App = () => {
const initializeState = ({ set }) => {
Object.entries(localStorage).forEach(([key, value]) => {
if (!key.includes("mapbox")) {
const parsedValue = JSON.parse(value).value;
set({ key }, parsedValue);
}
});
};

const Inner = () => {
useRecoilTransactionObserver_UNSTABLE(({ snapshot }) => {
for (const modifiedAtom of snapshot.getNodes_UNSTABLE({
isModified: true,
})) {
const atomLoadable = snapshot.getLoadable(modifiedAtom);
if (atomLoadable.state === "hasValue") {

localStorage.setItem(
modifiedAtom.key,
JSON.stringify({ value: atomLoadable.contents })
);
}
}
});
return (
<ThemeProvider theme={THEME}>
<Main />
Expand All @@ -55,4 +79,12 @@ const App = () => {
);
};

const App = () => {
return (
<RecoilRoot initializeState={initializeState}>
<Inner />
</RecoilRoot>
);
};

export default App;
54 changes: 36 additions & 18 deletions src/components/analytics/Analytics.js
Original file line number Diff line number Diff line change
@@ -1,27 +1,43 @@
import React, { useEffect, useState } from "react";
import { useRecoilValue } from "recoil";

import styled from "./style";
import RadialProgessBar from "../radialProgressBar/RadialProgressBar";
import RadialProgressBar from "../radialProgressBar/RadialProgressBar";
import {
sectionsState,
currentSectionIndexState,
runnerAnalyticsState,
routeAnalyticsState,
} from "../../model";

const Analytics = ({ className }) => {
const runnerAnalytics = useRecoilValue(runnerAnalyticsState);
const routeAnalytics = useRecoilValue(routeAnalyticsState);
const sections = useRecoilValue(sectionsState);
const currentSectionIndex = useRecoilValue(currentSectionIndexState);

const Analytics = ({
className,
runnerAnalytics,
routeAnalytics,
sections,
currentSectionIndex,
}) => {
const [data, setData] = useState();
const [distanceToNextCheckpoint, setDistanceToNextCheckpoint] = useState(0);

useEffect(() => {
if (currentSectionIndex < 0 || !runnerAnalytics || !sections) return;
if (
currentSectionIndex < 0 ||
runnerAnalytics.length === 0 ||
sections.length === 0
)
return;

const remaining = sections[currentSectionIndex].toKm - runnerAnalytics[0];
setDistanceToNextCheckpoint(remaining);
}, [currentSectionIndex, sections, runnerAnalytics]);

useEffect(() => {
if (!routeAnalytics || !runnerAnalytics) return;
if (
Object.keys(routeAnalytics).length === 0 ||
runnerAnalytics.length === 0
) {
return;
}

const updatedData = [
{
Expand All @@ -43,7 +59,7 @@ const Analytics = ({
},
{
label: "elevation loss",
color: "#DC0073",
color: "#bb3439",
total: routeAnalytics.elevation.negative,
runnerAnalytics: runnerAnalytics[2],
percent:
Expand All @@ -57,15 +73,17 @@ const Analytics = ({

return (
<div className={className}>
<RadialProgessBar data={data} />
<RadialProgressBar data={data} />
{currentSectionIndex >= 0 && (
<div className="analytics">
<div className="item checkpoint">{`${distanceToNextCheckpoint.toFixed(
2
)} km to ${sections[currentSectionIndex].arrivalLocation}`}</div>
<div className="item distance">{`${runnerAnalytics[0].toFixed(
2
)} km ran`}</div>
<div className="item checkpoint">{`${(
distanceToNextCheckpoint / 1000
).toFixed(2)} km to ${
sections[currentSectionIndex].arrivalLocation
}`}</div>
<div className="item distance">{`${(
runnerAnalytics[0] / 1000
).toFixed(2)} km ran`}</div>
<div className="item gain">{`${runnerAnalytics[1].toFixed(
0
)} m climbed`}</div>
Expand Down
2 changes: 1 addition & 1 deletion src/components/analytics/style.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export default (Component) => styled(Component)`
&.loss {
margin-left: ${(props) => props.theme.space[3] * 3}px;
::before {
background-color: #dc0073;
background-color: #bb3439;
}
}
&.checkpoint {
Expand Down
2 changes: 1 addition & 1 deletion src/components/fileUpload/FileUpload.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const Input = styled.input`
`;

const Container = styled.div`
display: relative;
position: relative;
display: flex;
align-items: center;
justify-content: center;
Expand Down
Loading