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

Testing #105

Closed
wants to merge 80 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
80 commits
Select commit Hold shift + click to select a range
1e5c2f9
add SearchRange type values
maruk0chan Dec 16, 2023
07eb943
add params in getSelectedRoutes
maruk0chan Dec 16, 2023
d7b0dbb
add searchRange in AppContext and DataImport
maruk0chan Dec 16, 2023
a106999
move SearchRange type to AppContext
maruk0chan Dec 16, 2023
d506b99
get and use searchRange value from AppContext
maruk0chan Dec 16, 2023
abd4fb1
add a prototype range options on top
maruk0chan Dec 16, 2023
69025db
add key attr in range option chips
maruk0chan Dec 16, 2023
aa677c9
add searchRange setter in AppContext
maruk0chan Dec 16, 2023
960396e
enable set searchRange with tags
maruk0chan Dec 16, 2023
5ceee3b
add draft style to range tags
maruk0chan Dec 16, 2023
1e014b7
avoid null selectedRoutes value in dependencies
maruk0chan Dec 16, 2023
f4cd4eb
extract get unit logic
maruk0chan Dec 16, 2023
df904f8
refactor isKm logic to ternary operator
maruk0chan Dec 16, 2023
1b8e6db
refactor param back to distanceInMetre
maruk0chan Dec 16, 2023
b8c46e4
Merge branch 'refactor/getDistanceWithUnit-fn' into feature/geolocati…
maruk0chan Dec 16, 2023
e614984
add unit to range options
maruk0chan Dec 16, 2023
fcd7dff
add range option 2000
maruk0chan Dec 16, 2023
fd7f4cc
add ListItem component to wrap option
maruk0chan Dec 16, 2023
80affe1
adjust option spacing
maruk0chan Dec 16, 2023
df2cf49
adjust range options style
maruk0chan Dec 16, 2023
1c5e523
leave only 100 and 500 preset range value
maruk0chan Dec 16, 2023
049c618
require searchRange in getSelectedRoutes
maruk0chan Dec 16, 2023
346775e
define defaultSearchRange as 100
maruk0chan Dec 16, 2023
de75770
change defaultSearchRange to 500
maruk0chan Dec 16, 2023
f56d971
add translation for Custom
maruk0chan Dec 16, 2023
34fc903
add translation for search range
maruk0chan Dec 16, 2023
599fcf5
add search range description
maruk0chan Dec 16, 2023
80e994d
align range option item center
maruk0chan Dec 16, 2023
6b7c0ff
remove padding in range options
maruk0chan Dec 16, 2023
5368b4a
style range option tags and text
maruk0chan Dec 16, 2023
17ecd8f
adjust tag and text color
maruk0chan Dec 16, 2023
84eab27
add ToggleButtonGroup
maruk0chan Dec 16, 2023
937d115
make toggle buttons smaller
maruk0chan Dec 16, 2023
654d7a2
change aria attribute for ToggleButton
maruk0chan Dec 16, 2023
6f52ffa
make toggleButton rounded
maruk0chan Dec 16, 2023
bdef815
color the selected toggleButton
maruk0chan Dec 16, 2023
c2285e1
finish most attributes in toggleButtonGroup
maruk0chan Dec 16, 2023
ff7b4b5
add toggle button color
maruk0chan Dec 16, 2023
89b802d
remove unused Chip array
maruk0chan Dec 16, 2023
9ce74b8
refactor searchRangeOptions type and value
maruk0chan Dec 16, 2023
ad1e1af
add range option 50
maruk0chan Dec 16, 2023
868ade1
adjust button style
maruk0chan Dec 16, 2023
512deda
change searchRangeOptions
maruk0chan Dec 16, 2023
6cdd478
change attr value
maruk0chan Dec 16, 2023
15955d7
remove unused toggleButtonGroup style
maruk0chan Dec 16, 2023
74bbd4f
remove range 1000 option
maruk0chan Dec 16, 2023
c009f4e
use last range option as default range
maruk0chan Dec 16, 2023
0f98cb3
prettier
maruk0chan Dec 16, 2023
c639930
remove toggleButton font size
maruk0chan Dec 16, 2023
de6ec05
refactor paperSx to accept prop
maruk0chan Dec 16, 2023
9ef9bf9
prevent custom range default
maruk0chan Dec 16, 2023
f2bc68f
add default value in toggle button group
maruk0chan Dec 16, 2023
a409b99
add dialog box
maruk0chan Dec 16, 2023
d709acb
change range option to numerical string
maruk0chan Dec 16, 2023
85cd2b2
enable custom range
maruk0chan Dec 16, 2023
bd0bbf6
convert range option value back to number
maruk0chan Dec 16, 2023
2c70f2d
enable custom range search
maruk0chan Dec 16, 2023
5be44c2
fix dialog not closing bug
maruk0chan Dec 16, 2023
2da87c9
add value beside custom option
maruk0chan Dec 16, 2023
b063c8d
add range unit and revise key value
maruk0chan Dec 16, 2023
3178b2f
remove unit in option tag
maruk0chan Dec 16, 2023
834f484
revise custom option text
maruk0chan Dec 16, 2023
c26cc97
shorter range button padding-x
maruk0chan Dec 16, 2023
b39d44f
narrow the gap btwn options and unit
maruk0chan Dec 16, 2023
9a60326
enable min and max input range
maruk0chan Dec 16, 2023
9eae6ee
make range option font size same to 14
maruk0chan Dec 16, 2023
18f66fc
show custom value when available
maruk0chan Dec 16, 2023
d5498f5
apply existing input range value on first click
maruk0chan Dec 16, 2023
e5ddbe8
save custom range value
maruk0chan Dec 16, 2023
a17afe7
refactor to lastSearchRange
maruk0chan Dec 16, 2023
3f3a5be
memorize custom range value
maruk0chan Dec 16, 2023
1a88095
show message when no nearby data
maruk0chan Dec 16, 2023
0929732
add no nearby routes translation
maruk0chan Dec 16, 2023
d966e45
remove unused code
maruk0chan Dec 16, 2023
06363f2
refactor hasNoNearbyRoutes logic
maruk0chan Dec 16, 2023
f92df69
add custom range search translation
maruk0chan Dec 16, 2023
0182248
add firebase support
maruk0chan Dec 16, 2023
4ce3970
Merge branch 'feature/geolocation-range-option'
maruk0chan Dec 16, 2023
85f487b
testing for firebase
maruk0chan Dec 16, 2023
ed3c304
Prettified Code!
maruk0chan Dec 16, 2023
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
5 changes: 5 additions & 0 deletions .firebaserc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"projects": {
"default": "hk-bus-app"
}
}
20 changes: 20 additions & 0 deletions .github/workflows/firebase-hosting-merge.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# This file was auto-generated by the Firebase CLI
# https://github.com/firebase/firebase-tools

name: Deploy to Firebase Hosting on merge
'on':
push:
branches:
- master
jobs:
build_and_deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- run: npm ci && npm run build
- uses: FirebaseExtended/action-hosting-deploy@v0
with:
repoToken: '${{ secrets.GITHUB_TOKEN }}'
firebaseServiceAccount: '${{ secrets.FIREBASE_SERVICE_ACCOUNT_HK_BUS_APP }}'
channelId: live
projectId: hk-bus-app
17 changes: 17 additions & 0 deletions .github/workflows/firebase-hosting-pull-request.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# This file was auto-generated by the Firebase CLI
# https://github.com/firebase/firebase-tools

name: Deploy to Firebase Hosting on PR
'on': pull_request
jobs:
build_and_preview:
if: '${{ github.event.pull_request.head.repo.full_name == github.repository }}'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- run: npm ci && npm run build
- uses: FirebaseExtended/action-hosting-deploy@v0
with:
repoToken: '${{ secrets.GITHUB_TOKEN }}'
firebaseServiceAccount: '${{ secrets.FIREBASE_SERVICE_ACCOUNT_HK_BUS_APP }}'
projectId: hk-bus-app
10 changes: 10 additions & 0 deletions firebase.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"hosting": {
"public": "public",
"ignore": [
"firebase.json",
"**/.*",
"**/node_modules/**"
]
}
}
56 changes: 24 additions & 32 deletions public/404.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,40 +2,32 @@
<html>
<head>
<meta charset="utf-8">
<link rel="icon" href="/favicon.ico" />
<title>巴士到站預報 App</title>
<script type="text/javascript">
// Single Page Apps for GitHub Pages
// MIT License
// https://github.com/rafgraph/spa-github-pages
// This script takes the current url and converts the path and query
// string into just a query string, and then redirects the browser
// to the new url with only a query string and hash fragment,
// e.g. https://www.foo.tld/one/two?a=b&c=d#qwe, becomes
// https://www.foo.tld/?/one/two&a=b~and~c=d#qwe
// Note: this 404.html file must be at least 512 bytes for it to work
// with Internet Explorer (it is currently > 512 bytes)
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Page Not Found</title>

// If you're creating a Project Pages site and NOT using a custom domain,
// then set pathSegmentsToKeep to 1 (enterprise users may need to set it to > 1).
// This way the code will only replace the route part of the path, and not
// the real directory in which the app resides, for example:
// https://username.github.io/repo-name/one/two?a=b&c=d#qwe becomes
// https://username.github.io/repo-name/?/one/two&a=b~and~c=d#qwe
// Otherwise, leave pathSegmentsToKeep as 0.
var pathSegmentsToKeep = 0;

var l = window.location;
l.replace(
l.protocol + '//' + l.hostname + (l.port ? ':' + l.port : '') +
l.pathname.split('/').slice(0, 1 + pathSegmentsToKeep).join('/') + '/?/' +
l.pathname.slice(1).split('/').slice(pathSegmentsToKeep).join('/').replace(/&/g, '~and~') +
(l.search ? '&' + l.search.slice(1).replace(/&/g, '~and~') : '') +
l.hash
);

</script>
<style media="screen">
body { background: #ECEFF1; color: rgba(0,0,0,0.87); font-family: Roboto, Helvetica, Arial, sans-serif; margin: 0; padding: 0; }
#message { background: white; max-width: 360px; margin: 100px auto 16px; padding: 32px 24px 16px; border-radius: 3px; }
#message h3 { color: #888; font-weight: normal; font-size: 16px; margin: 16px 0 12px; }
#message h2 { color: #ffa100; font-weight: bold; font-size: 16px; margin: 0 0 8px; }
#message h1 { font-size: 22px; font-weight: 300; color: rgba(0,0,0,0.6); margin: 0 0 16px;}
#message p { line-height: 140%; margin: 16px 0 24px; font-size: 14px; }
#message a { display: block; text-align: center; background: #039be5; text-transform: uppercase; text-decoration: none; color: white; padding: 16px; border-radius: 4px; }
#message, #message a { box-shadow: 0 1px 3px rgba(0,0,0,0.12), 0 1px 2px rgba(0,0,0,0.24); }
#load { color: rgba(0,0,0,0.4); text-align: center; font-size: 13px; }
@media (max-width: 600px) {
body, #message { margin-top: 0; background: white; box-shadow: none; }
body { border-top: 16px solid #ffa100; }
}
</style>
</head>
<body>
<div id="message">
<h2>404</h2>
<h1>Page Not Found</h1>
<p>The specified file was not found on this website. Please check the URL for mistakes and try again.</p>
<h3>Why am I seeing this?</h3>
<p>This page was generated by the Firebase Command-Line Interface. To modify it, edit the <code>404.html</code> file in your project's configured <code>public</code> directory.</p>
</div>
</body>
</html>
1 change: 1 addition & 0 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ const getThemeTokens = (mode: PaletteMode, fontSize: number) => ({
},
primary: {
main: "#fedb00", // yellow
contrastText: "#000",
},
warning: {
main: "#fedb00",
Expand Down
56 changes: 56 additions & 0 deletions src/AppContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import {
NumPadOrder,
} from "./data";
import { DeviceOrientationPermission } from "react-world-compass";
import { searchRangeOptions } from "./components/home/SwipeableList";

type GeoPermission = "opening" | "granted" | "denied" | "closed" | null;

Expand Down Expand Up @@ -86,6 +87,14 @@ export interface AppState {
* Font size
*/
fontSize: number;
/**
* Range for geolocation search
*/
lastSearchRange: number;
/**
* Custom Range for geolocation search
*/
customSearchRange: number;
}

interface AppContextValue
Expand Down Expand Up @@ -122,6 +131,10 @@ interface AppContextValue
setFontSize: (fontSize: number) => void;
importAppState: (appState: AppState) => void;
workbox?: Workbox;
lastSearchRange: number;
setLastSearchRange: (lastSearchRange: number) => void;
customSearchRange: number;
setCustomSearchRange: (customSearchRange: number) => void;

// for React Native Context
setGeoPermission: (geoPermission: AppState["geoPermission"]) => void;
Expand Down Expand Up @@ -174,6 +187,10 @@ const isColorMode = (input: unknown): input is ColorMode => {
return input === "dark" || input === "light" || input === "system";
};

// use the largest search range option as default
export const defaultSearchRange =
searchRangeOptions[searchRangeOptions.length - 1];

export const AppContextProvider = ({
workbox,
children,
Expand Down Expand Up @@ -236,6 +253,11 @@ export const AppContextProvider = ({
annotateScheduled:
JSON.parse(localStorage.getItem("annotateScheduled")) ?? false,
fontSize: JSON.parse(localStorage.getItem("fontSize")) ?? 14,
lastSearchRange:
JSON.parse(localStorage.getItem("lastSearchRange")) ??
defaultSearchRange,
customSearchRange:
JSON.parse(localStorage.getItem("customSearchRange")) ?? "",
};
};
const { i18n } = useTranslation();
Expand Down Expand Up @@ -546,6 +568,22 @@ export const AppContextProvider = ({
);
}, []);

const setLastSearchRange = useCallback((lastSearchRange: number) => {
setStateRaw(
produce((state: State) => {
state.lastSearchRange = lastSearchRange;
})
);
}, []);

const setCustomSearchRange = useCallback((customSearchRange: number) => {
setStateRaw(
produce((state: State) => {
state.customSearchRange = customSearchRange;
})
);
}, []);

const colorMode = useMemo(() => {
if (state._colorMode === "light" || state._colorMode === "dark") {
return state._colorMode;
Expand Down Expand Up @@ -650,6 +688,20 @@ export const AppContextProvider = ({
localStorage.setItem("fontSize", JSON.stringify(state.fontSize));
}, [state.fontSize]);

useEffect(() => {
localStorage.setItem(
"lastSearchRange",
JSON.stringify(state.lastSearchRange)
);
}, [state.lastSearchRange]);

useEffect(() => {
localStorage.setItem(
"customSearchRange",
JSON.stringify(state.customSearchRange)
);
}, [state.customSearchRange]);

const contextValue = useMemo(() => {
return {
...dbContext,
Expand Down Expand Up @@ -681,6 +733,8 @@ export const AppContextProvider = ({
importAppState,
workbox,
setGeoPermission,
setLastSearchRange,
setCustomSearchRange,
};
}, [
dbContext,
Expand Down Expand Up @@ -712,6 +766,8 @@ export const AppContextProvider = ({
importAppState,
workbox,
setGeoPermission,
setLastSearchRange,
setCustomSearchRange,
]);
return (
<AppContext.Provider value={contextValue}>{children}</AppContext.Provider>
Expand Down
8 changes: 4 additions & 4 deletions src/components/home/SuccinctTimeReport.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ import {
Typography,
} from "@mui/material";
import { Link, useNavigate } from "react-router-dom";
import { vibrate } from "../../utils";
import { getDistance, getDistanceWithUnit, vibrate } from "../../utils";
import AppContext from "../../AppContext";
import { useTranslation } from "react-i18next";
import SuccinctEtas from "./SuccinctEtas";
import { getDistanceWithUnit, toProperCase } from "../../utils";
import { toProperCase } from "../../utils";
import RouteNo from "../route-board/RouteNo";
import { Eta, Location } from "hk-bus-eta";
import { ManageMode } from "../../data";
Expand Down Expand Up @@ -48,9 +48,9 @@ const DistAndFare = ({
.join(", ");

const { distance, unit, decimalPlace } = getDistanceWithUnit(
location,
geolocation
getDistance(location, geolocation)
);

if (geoPermission !== "granted" || location.lat === 0) {
return <>{name + " " + (fareString ? "(" + fareString + ")" : "")}</>;
}
Expand Down
Loading