123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145 |
- 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 (
- <MockContext.Provider value={{ state, dispatch }}>
- {children}
- </MockContext.Provider>
- );
- };
- export const useMockState = () => {
- const context = useContext(MockContext);
- if (context === undefined) {
- throw new Error(
- "useMockState must be used within a MockProvider"
- );
- }
- return context;
- }
|