import React, { createContext, useReducer, useContext } from "react"; import { v4 as uuidv4 } from 'uuid'; function mockReducer(state, action) { switch (action.type) { case "CHANGE_TABBAR_VISIBILITY": return { ...state, tabBarVisible: action.payload} case "LOGIN": return { ...state, loggedIn: true, }; case "LOGOUT": return { ...state, loggedIn: false, }; case "UPDATE_SELECTED_LANDMARK": return { ...state, selectedLandmark: action.payload, }; case "UPDATE_LANDMARKS": return { ...state, landmarks: action.payload, }; case "UPDATE_LOCATION_PERMISSION": return { ...state, locationPermission: action.payload, }; case "UPDATE_LOCATION": return { ...state, location: action.payload, }; default: throw new Error(); } } export const seedLandmarkData = () => { return [ { id: uuidv4(), rating: 5, postedBy: 'cdmoss', latitude: 53.51803, longitude: -113.46831, dateAdded: Date.now(), title: "Millcreek Dental pothole", desc: "A small pothole right in front of the doors to the Millcreek dental clinic.", icon: 'pothole', comments: [ { id: uuidv4(), dateAdded: new Date(), name: "Brian Bell", text: "This was very helpful! Thanks!" }, { id: uuidv4(), dateAdded: new Date(), name: "Martin Ferguson-Pell", text: "The pothole is in front of the left door, try use the right one!" }, { id: uuidv4(), name: "cdmoss", dateAdded: new Date(), text: "Potholes suck!" }, { id: uuidv4(), name: "Nathan Maeda", dateAdded: new Date(), text: "I've notified the city, they should be fixing this within the next week." }, ] }, { id: uuidv4(), rating: 4, postedBy: 'cdmoss', latitude: 53.51839016964649, longitude: -113.49473594001775, dateAdded: Date.now(), 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 mockState = { tabBarVisible: true, location: null, locationPermission: false, loggedIn: false, username: "cdmoss", email: "cdmoss@gmail.com", rank: 0, height: 170, weight: 91, landmarks: seedLandmarkData(), places: null, placeTips: null, selectedLandmark: { icon: 'barrier' }, } export const MockContext = createContext(mockState); export const MockProvider = ({ children }) => { const [state, dispatch] = useReducer(mockReducer, mockState); return ( {children} ); }; export const useMockState = () => { const context = useContext(MockContext); if (context === undefined) { throw new Error( "useMockState must be used within a MockProvider" ); } return context; }