Skip to content

Commit

Permalink
Merge pull request #187 from bcgov/wayf-168-serviceworker-refinement
Browse files Browse the repository at this point in the history
[WAYF-168] FEATURE** Serviceworker Refinement
  • Loading branch information
TylerMaloney authored Jul 28, 2023
2 parents 08dd36a + 2e42b63 commit 0d2b3ed
Show file tree
Hide file tree
Showing 16 changed files with 398 additions and 67 deletions.
42 changes: 25 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,30 +5,38 @@ Citizen Services Capstone Project Team B (Wayfinder)
## Project Information
[![Lifecycle:Experimental](https://img.shields.io/badge/Lifecycle-Experimental-339999)](<Redirect-URL>)
## Project Description
The "Wayfinder" application is a mobile application that directs citizens and employees to government services. The Wayfinder proof of concept provides an extensible platform that allows new services and locations to be added as they become available. Another use case for the Wayfinder app is the ability to process application generated analytics data allowing the product team to analyze valuable usage data that will inform the creation of new services that can be delivered using the Wayfinder app.
The "Wayfinder" application is a Progressive Web Application that directs citizens to government services. The Wayfinder proof-of-concept provides an extensible platform that allows new services and locations to be added as they become available. Another use case for the Wayfinder app is the ability to process application generated analytics data allowing the product team to analyze valuable usage data that will inform the creation of new services that can be delivered using the Wayfinder app.



## Introduction
This repository is a mono-repo containing all relevant documentation, code, and infrastructure that is required for the Wayfinder application and container(s).
There will be additional supplementary README's for the back-end and front-end.
This repository is a mono-repo containing all relevant documentation, code, and infrastructure that is required for the Wayfinder application.

## Project Status
Project is currently under development via the Capstone team.
Project was completed by the Capstone Team.

### Frontend:
* [Node.js](https://nodejs.org/en)
* [Vite](https://vitejs.dev/)
* [React](https://react.dev/)
* [TypeScript](https://devdocs.io/typescript/)
* [emotion.js](https://emotion.sh/docs/introduction)
* [leaflet.js](https://leafletjs.com/) + [react-leaflet](https://react-leaflet.js.org/)
* [Cypress](https://www.cypress.io/)

### Backend:
* [Node.js](https://nodejs.org/en)
* [Express.js](https://expressjs.com/)
* [TypeScript](https://devdocs.io/typescript/)
* [Mongoose](https://mongoosejs.com/docs/)
* [Jest](https://jestjs.io/)

### Database:
* [MongoDB](https://www.mongodb.com/docs/)

### Data Visualization:
* [PowerBI](https://learn.microsoft.com/en-us/power-bi/)

## Stack

### Front-End
* React PWA
* Typescript
* Node

### Back-End
* Express
* MongoDB
* Typescript
* Node
* Swagger

### Mongo Dev Key Examples

Expand Down
2 changes: 1 addition & 1 deletion src/frontend-pwa/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "testing-vite",
"private": true,
"version": "0.9.0",
"version": "1.0.0",
"type": "module",
"scripts": {
"dev": "vite",
Expand Down
2 changes: 1 addition & 1 deletion src/frontend-pwa/src/components/common/Button/Button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

import StyledButton from './button.styles';

export type ButtonVariants = 'default' | 'primary' | 'secondary';
export type ButtonVariants = 'default' | 'primary' | 'secondary' | 'tertiary';
export type ButtonSizes = 'sm' | 'md' | 'lg';

export type ButtonProps = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ const StyledButton = styled.button<ButtonProps>`
font-weight: 500;
letter-spacing: 1px;
cursor: pointer;
background-color: ${(props) => (props.variant === 'primary' ? '#003366' : props.variant === 'secondary' ? '#FFFFFF' : '#000000')};
background-color: ${(props) => (props.variant === 'primary' ? '#003366' : props.variant === 'secondary' ? '#DC3545' : '#000000')};
background-color: ${(props) => (props.variant === 'primary' ? '#003366' : props.variant === 'secondary' ? '#DC3545' : props.variant === 'tertiary' ? '#198754' : '#000000')};
color: #FFFFFF;
&:hover {
transform: scale(0.98);
Expand Down
11 changes: 11 additions & 0 deletions src/frontend-pwa/src/components/utility/Mapping/Mapping.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import {
StyledPopup,
StyledMapContainer,
PopupInfo,
MapTilesNotFoundDiv,
} from './mapping.styles';
import SingleLocation from '../../../Type/SingleLocation';
import LocationsArray from '../../../Type/LocationsArray';
Expand Down Expand Up @@ -86,6 +87,16 @@ export default function Mapping({ locations, currentLocation }: MappingProps) {
? 'https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png'
: '/mapTiles/{z}/{x}/{y}.png';

if (!onlineMode && !state.mapsCached) {
return (
<MapTilesNotFoundDiv>
<p>
{mappingContent.offlineMapTilesNotFoundMessage[lang]}
</p>
</MapTilesNotFoundDiv>
);
}

return (
<MapWrapperDiv>
{ !isNaN(lat)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,10 @@ export const StyledPopupDiv = styled.div`
max-height: 10em;
overflow-y: auto;
`;

export const MapTilesNotFoundDiv = styled.div`
color: darkred;
align-items: center;
justify-content: center;
padding: 3em;
`;
1 change: 1 addition & 0 deletions src/frontend-pwa/src/constants/Constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const constants = {
REPORTS_KEY: 'reports',
UNSENT_REPORTS_KEY: 'unsentReports',
APP_INSTALL_KEY: 'appInstalled',
MAPS_CACHED_KEY: 'mapsCached',
UPDATE_ARRAY_KEY: 'updateArr',
};

Expand Down
10 changes: 10 additions & 0 deletions src/frontend-pwa/src/content/changelogContent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,16 @@ export interface ContentMap {
}

const ChangeLog: ContentMap = {
'1.0.0': {
eng: [
'Added ability to delete and recache map tiles at will',
'Changed the secondary button color to a softer shade of red',
],
fr: [
'Ajout de la possibilité de supprimer et de remettre en cache des tuiles de carte à volonté',
'Modification de la couleur du bouton secondaire en une nuance de rouge plus douce',
],
},
'0.9.0': {
eng: [
'Settings view revamped to new modern design',
Expand Down
60 changes: 60 additions & 0 deletions src/frontend-pwa/src/content/content.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,62 @@ export const SettingsContent: ContentMap = {
eng: 'Pull in new location data from the server',
fr: 'Récupérer de nouvelles données de localisation à partir du serveur',
},
refreshDataButtonTextRefresh: {
eng: 'Refresh',
fr: 'Rafraîchir',
},
refreshDataButtonTextOffline: {
eng: 'Offline',
fr: 'Hors ligne',
},
refreshDataTextConfirm: {
eng: 'App data updated',
fr: 'Données d\'application mises à jour',
},
refreshDataModalButton: {
eng: 'OK',
fr: 'D\'ACCORD',
},
offlineMapTilesTitle: {
eng: 'Offline Map Tiles',
fr: 'Tuiles de carte hors ligne',
},
offlineMapTilesToolTip: {
eng: 'To decrease app size, you can delete the saved tiles. This will prevent offline map functionality.',
fr: 'Pour réduire la taille de l\'application, vous pouvez supprimer les vignettes enregistrées. Cela empêchera la fonctionnalité de carte hors ligne.',
},
installMapTilesButtonTextOffline: {
eng: 'Offline',
fr: 'Hors ligne',
},
installMapTilesButtonTextOnline: {
eng: 'Download',
fr: 'Télécharger',
},
installMapTilesModalWarning: {
eng: 'The size of the mapTile package is ~35MB. do you wish to proceed with the download?',
fr: 'La taille du package mapTile est d\'environ 35 Mo. Souhaitez-vous poursuivre le téléchargement ?',
},
clearCache: {
eng: 'Delete Data',
fr: 'Suprimmer les données',
},
clearCacheToolTip: {
eng: 'Deletes the cached map data.',
fr: 'Supprime les données de site mises en cache.',
},
clearCacheConfirmText: {
eng: 'Are you sure you want to clear the cache data? Offline map will be unavailable.',
fr: 'Voulez-vous vraiment effacer les données du cache ? La carte hors ligne ne sera pas disponible.',
},
clearCacheButtonConfirm: {
eng: 'Confirm',
fr: 'Confirmer',
},
clearCacheButtonCancel: {
eng: 'Cancel',
fr: 'Annuler',
},
languages: {
eng: [
'English',
Expand Down Expand Up @@ -512,6 +568,10 @@ export const mappingContent: ContentMap = {
eng: 'Phone Number: ',
fr: 'Numéro de téléphone: ',
},
offlineMapTilesNotFoundMessage: {
eng: 'The map data was not found and the device appears to be offline. The offline map is unable to be rendered.',
fr: 'Les données cartographiques sont introuvables et l\'appareil semble être hors ligne. La carte hors ligne ne peut pas être rendue.',
},
};

export const reportHistoryContent: ContentMap = {
Expand Down
1 change: 1 addition & 0 deletions src/frontend-pwa/src/services/app/AppActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ enum AppActionType {
SET_REPORTS = 'SET_REPORTS',
SET_TOOL_TIP_TEXT = 'SET_TOOL_TIP_TEXT',
SET_ONLINE = 'SET_ONLINE',
SET_MAP_CACHED = 'SET_MAP_CACHED',
}

export default AppActionType;
4 changes: 4 additions & 0 deletions src/frontend-pwa/src/services/app/AppReducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const {
SET_REPORTS,
SET_TOOL_TIP_TEXT,
SET_ONLINE,
SET_MAP_CACHED,
} = AppActionType;

export type AppAction = {
Expand All @@ -26,6 +27,7 @@ export const initialState = {
reports: {},
toolTipText: '',
isOnline: false,
mapsCached: true,
};

/**
Expand Down Expand Up @@ -53,6 +55,8 @@ export const reducer = (state: object, action: AppAction): object => {
return { ...state, toolTipText: action.payload };
case SET_ONLINE:
return { ...state, isOnline: action.payload };
case SET_MAP_CACHED:
return { ...state, mapsCached: action.payload };
default:
throw new Error();
}
Expand Down
13 changes: 13 additions & 0 deletions src/frontend-pwa/src/services/app/useAppService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ const {
SET_REPORTS,
SET_TOOL_TIP_TEXT,
SET_ONLINE,
SET_MAP_CACHED,
} = AppActionType;

/**
Expand Down Expand Up @@ -288,6 +289,17 @@ const useAppService = () => {
});
};

/**
* @summary Sets the state for determining whether the map tiles are present or not
* @param cached is a boolean that indicates whether the app has cached map tiles or not
* @type {( cached: boolean )}
* @author Dallas Richmond
*/
const setMapsCache = (cached: boolean) => {
saveDataToLocalStorage(constants.MAPS_CACHED_KEY, cached);
dispatch({ type: SET_MAP_CACHED, payload: cached });
};

return {
setAppData,
setCurrentLocation,
Expand All @@ -302,6 +314,7 @@ const useAppService = () => {
setOfflineReports,
setOnline,
setAppInstall,
setMapsCache,
state,
};
}, [state, dispatch]);
Expand Down
8 changes: 7 additions & 1 deletion src/frontend-pwa/src/views/Eula/Eula.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,12 @@ import OnlineCheck from '../../utils/OnlineCheck';

export default function Eula() {
const [termAgreement, setTermAgreement] = useState(false);
const { state, setEulaState, setAnalytics } = useAppService();
const {
state,
setEulaState,
setAnalytics,
setMapsCache,
} = useAppService();
const { lang } = state.settings;
const geolocationKnown = localStorageKeyExists(constants.CURRENT_LOCATION_KEY);
const latitude = state.currentLocation ? state.currentLocation.lat : 49.2827;
Expand All @@ -27,6 +32,7 @@ export default function Eula() {
};

const handleButtonClick = () => {
setMapsCache(true);
setEulaState();
if (geolocationKnown) {
const analytics = {
Expand Down
Loading

0 comments on commit 0d2b3ed

Please sign in to comment.