123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289 |
- import React, { createContext, useReducer, useContext } from "react";
- import { v4 as uuidv4 } from 'uuid';
- function reducer(state, action) {
- switch (action.type) {
- case "UPDATE_SELECTED_LANDMARK":
- return { ...state, selectedLandmark: action.payload, };
- case "UPDATE_LANDMARKS":
- return { ...state, landmarks: action.payload, };
- case "UPDATE_PLACES":
- return { ...state, places: action.payload, };
- case "UPDATE_SELECTED_PLACES":
- return { ...state, selectedPlaces: action.payload, };
- case "UPDATE_SELECTED_PLACE":
- return { ...state, selectedPlace: action.payload, };
- case "UPDATE_LOCATION_PERMISSION":
- return { ...state, locationPermission: action.payload, };
- case "UPDATE_LOCATION":
- return { ...state, location: action.payload, };
- default:
- console.log(state);
- console.log(action);
- throw new Error();
- }
- }
- // export const seedLandmarkData = () => {
- // return [
- // {
- // id: uuidv4(),
- // rating: 5,
- // postedBy: 'cdmoss',
- // latitude: 53.48914616441755,
- // longitude: -113.49762260454305,
- // dateAdded: new Date(),
- // title: "Allard way pothole",
- // desc: "A massive pothole on the Allard Way sidewalk.",
- // icon: 'pothole',
- // },
- // {
- // id: uuidv4(),
- // rating: 4,
- // postedBy: 'cdmoss',
- // latitude: 53.51839016964649,
- // longitude: -113.49473594001775,
- // dateAdded: new Date(),
- // title: "Accessible bathroom on Whyte",
- // desc: "A conveniently placed accessible bathroom.",
- // icon: 'washroom',
- // comments: [
- // ]
- // },
- // {
- // id: uuidv4(),
- // rating: 0,
- // postedBy: 'cendersby',
- // latitude: 53.48963,
- // longitude: -113.49401,
- // dateAdded: new Date(),
- // title: "Peter's Drive-in Construction",
- // desc: "The sidewalk in front of Peter's is being rebuilt.",
- // icon: 'roadblock',
- // comments: [
- // {
- // id: uuidv4(),
- // name: "shampshire",
- // dateAdded: new Date(),
- // text: "No! Not peters!"
- // },
- // {
- // id: uuidv4(),
- // name: "nmaeda",
- // dateAdded: new Date(),
- // text: "Good, Peter's is gross!"
- // },
- // ]
- // },
- // ];
- // };
- // const seedPlaces = () => {
- // return [{
- // id: uuidv4(),
- // color: 'green',
- // postedBy: 'cdmoss',
- // coordinates: [
- // [
- // [
- // -113.53052616119385,
- // 53.53087032262937
- // ],
- // [
- // -113.53065490722656,
- // 53.523038509337624
- // ],
- // [
- // -113.53241443634032,
- // 53.52298748300469
- // ],
- // [
- // -113.53250026702881,
- // 53.518701051607486
- // ],
- // [
- // -113.53310108184813,
- // 53.51783350677023
- // ],
- // [
- // -113.5234022140503,
- // 53.51640457066658
- // ],
- // [
- // -113.52087020874023,
- // 53.51811418498503
- // ],
- // [
- // -113.52095603942871,
- // 53.52298748300469
- // ],
- // [
- // -113.51490497589111,
- // 53.52291094339006
- // ],
- // [
- // -113.51499080657958,
- // 53.525895885886285
- // ],
- // [
- // -113.51833820343018,
- // 53.526941841607
- // ],
- // [
- // -113.52099895477295,
- // 53.52854899152384
- // ],
- // [
- // -113.52481842041016,
- // 53.529773445765805
- // ],
- // [
- // -113.53052616119385,
- // 53.53087032262937
- // ]
- // ]
- // ],
- // dateAdded: new Date(),
- // name: "UofA",
- // desc: "The University of Alberta.",
- // tips: [
- // {
- // id: uuidv4(),
- // name: "shampshire",
- // dateAdded: new Date(),
- // text: "There are lots of great accessibility features at the University.",
- // rating: 3,
- // liked: false,
- // },
- // ]
- // },
- // {
- // id: uuidv4(),
- // postedBy: 'cdmoss',
- // coordinates: [
- // [
- // [
- // -113.52713584899902,
- // 53.52285991690344
- // ],
- // [
- // -113.52730751037598,
- // 53.52074226350543
- // ],
- // [
- // -113.52591276168823,
- // 53.52081880703848
- // ],
- // [
- // -113.52580547332764,
- // 53.522847160272185
- // ],
- // [
- // -113.52713584899902,
- // 53.52285991690344
- // ]
- // ]
- // ],
- // dateAdded: new Date(),
- // name: "ECHA",
- // color: 'red',
- // desc: "The Edmonton Clinic Health Academy building.",
- // tips: [
- // {
- // id: uuidv4(),
- // name: "shampshire",
- // dateAdded: new Date(),
- // text: "There are lots of great accessibility features at ECHA.",
- // rating: 3,
- // liked: false
- // },
- // ]
- // },
- // {
- // id: uuidv4(),
- // rating: 4,
- // postedBy: 'cdmoss',
- // color: 'blue',
- // dateAdded: new Date(),
- // name: "SUB",
- // desc: "The Student Union Building.",
- // tips: [
- // {
- // id: uuidv4(),
- // name: "shampshire",
- // dateAdded: new Date(),
- // text: "There are lots of great accessibility features at SUB.",
- // rating: 3,
- // liked: false
- // },
- // ],
- // coordinates: [
- // [
- // [
- // -113.52796196937561,
- // 53.525691793953534
- // ],
- // [
- // -113.52800488471983,
- // 53.5249710864483
- // ],
- // [
- // -113.5263204574585,
- // 53.5249710864483
- // ],
- // [
- // -113.52630972862244,
- // 53.525398410077315
- // ],
- // [
- // -113.52684617042542,
- // 53.52544943350612
- // ],
- // [
- // -113.5268783569336,
- // 53.52566628239279
- // ],
- // [
- // -113.52796196937561,
- // 53.525691793953534
- // ]
- // ]
- // ]
- // }]
- // }
- const state = {
- location: null,
- locationPermission: false,
- landmarks: [],
- selectedLandmark: {
- icon: 'barrier'
- },
- places: [],
- selectedPlaces: [],
- selectedPlace: {name: ''},
- }
- export const MapContext = createContext(state);
- export const MapProvider = ({ children }) => {
- const [mapState, mapDispatch] = useReducer(reducer, state);
- return (
- <MapContext.Provider value={{ mapState, mapDispatch }}>
- {children}
- </MapContext.Provider>
- );
- };
- export const useMapState = () => {
- const context = useContext(MapContext);
- if (context === undefined) {
- throw new Error(
- "useMapState must be used within a MapProvider"
- );
- }
- return context;
- }
|