Skip to content

Commit

Permalink
Merge pull request #168 from Type-Style/167-refactor-context
Browse files Browse the repository at this point in the history
167 refactor context
  • Loading branch information
Type-Style committed Sep 20, 2024
2 parents b7ce940 + bf2886d commit c8e8522
Show file tree
Hide file tree
Showing 20 changed files with 234 additions and 98 deletions.
2 changes: 1 addition & 1 deletion .env_example
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
NODE_ENV=development
ROOT=https://your-produciton-server.com
KEY=
USER_JOHNDOE=
USER_XX=
USER_TEST=
MAPBOX=
5 changes: 1 addition & 4 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,8 @@
},
"plugins": ["jest", "@typescript-eslint"],
"rules": {
//"no-console": "off",
//"import/prefer-default-export": "off",
//"@typescript-eslint/no-unused-vars": "warn"
"jest/no-conditional-expect": "off"
},
"ignorePatterns": ["dist", "jest.config.js", "httpdocs", "webpack.config.js", "src/client", "init"]
"ignorePatterns": ["dist", "jest.config.js", "httpdocs", "webpack.config.js", "src/client", "init", "jest.testData.config.js"]

}
1 change: 1 addition & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ jobs:
run: npm run test:login
- name: Run unit tests
run: npm run test:unit
- run: echo "--- base tests complete ---"
- name: Run integration tests
run: npm run test:integration

Expand Down
26 changes: 0 additions & 26 deletions .github/workflows/stale.yml

This file was deleted.

2 changes: 1 addition & 1 deletion .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@
"problemMatcher": "$tsc"
}
]
}
}
Binary file modified demo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
138 changes: 137 additions & 1 deletion httpdocs/color-table.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion init/generateKey.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ rl.question('Enter the string to be encoded: ', (input) => {
const base64String = Buffer.from(escapedString).toString('base64');

// print the result
console.log('Base64 Encoded String:', base64String);
console.log('encoded String:', base64String);

rl.close();
});
2 changes: 1 addition & 1 deletion jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ module.exports = {
'^@src/(.*)$': '<rootDir>/src/$1',
},
bail: true
};
};
1 change: 1 addition & 0 deletions jest.testData.config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/** @type {import('ts-jest').JestConfigWithTsJest} */

module.exports = {
preset: 'ts-jest',
testEnvironment: 'node',
Expand Down
24 changes: 20 additions & 4 deletions package-lock.json

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

4 changes: 3 additions & 1 deletion src/client/components/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ const App = () => {
const prefersDarkMode = useMediaQuery('(prefers-color-scheme: dark)');
const [mapToken, setMapToken] = useState<string | null>(null);

const contextObj = {isLoggedIn, setLogin, userInfo, setUserInfo, mode, setMode, prefersDarkMode, mapToken}

useEffect(() => {
setMode(prefersDarkMode ? "dark" : "light");
}, [prefersDarkMode, setMode]);
Expand All @@ -73,7 +75,7 @@ const App = () => {
}, [isLoggedIn]);

return (
<Context.Provider value={[isLoggedIn, setLogin, userInfo, setUserInfo, mode, setMode, prefersDarkMode, mapToken]}>
<Context.Provider value={[contextObj]}>
<RouterProvider router={router} />
</Context.Provider>
);
Expand Down
8 changes: 4 additions & 4 deletions src/client/components/Map.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@ function Map({ entries }: { entries: Models.IEntry[] }) {
if (!entries?.length) {
return <span className="noData cut">No Data to be displayed</span>
}
const [, , , , mode, , , mapToken] = useContext(Context);
const [mapStyle, setMapStyle] = useState(mode);
const [contextObj] = useContext(Context);
const [mapStyle, setMapStyle] = useState(contextObj.mode);

const lastEntry = entries.at(-1);
const cleanEntries = entries.filter((entry) => !entry.ignore);
Expand Down Expand Up @@ -169,12 +169,12 @@ function Map({ entries }: { entries: Models.IEntry[] }) {
return (
<LayersControl.BaseLayer
key={index}
checked={layer.default == mode}
checked={layer.default == contextObj.mode}
name={layer.name}
>
<TileLayer
attribution={layer.attribution}
url={layer.url.includes(replaceKeyword) ? layer.url.replace(replaceKeyword, mapToken) : layer.url}
url={layer.url.includes(replaceKeyword) ? layer.url.replace(replaceKeyword, contextObj.mapToken) : layer.url}
tileSize={layer.size || 256}
zoomOffset={layer.zoomOffset || 0}
maxZoom={19}
Expand Down
4 changes: 2 additions & 2 deletions src/client/components/MiniMap.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { Context } from "./App";

export default function MiniMap({ layer, lastEntry, index }: client.MiniMapProps) {

const [, , , , , , , mapToken] = useContext(Context);
const [contextObj] = useContext(Context);

const replaceKeyword = "XXXREPLACEXXX";

Expand All @@ -30,7 +30,7 @@ export default function MiniMap({ layer, lastEntry, index }: client.MiniMapProps
<MapRecenter lat={lastEntry.lat} lon={lastEntry.lon} zoom={15} fly={false} />
<TileLayer
attribution={layer.attribution}
url={layer.url.includes(replaceKeyword) ? layer.url.replace(replaceKeyword, mapToken) : layer.url}
url={layer.url.includes(replaceKeyword) ? layer.url.replace(replaceKeyword, contextObj.mapToken) : layer.url}
tileSize={layer.size || 256}
zoomOffset={layer.zoomOffset || 0}
/>
Expand Down
Loading

0 comments on commit c8e8522

Please sign in to comment.