MockContext.js 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300
  1. import React, { createContext, useReducer, useContext } from "react";
  2. import { v4 as uuidv4 } from 'uuid';
  3. function mockReducer(state, action) {
  4. switch (action.type) {
  5. case "CHANGE_TABBAR_VISIBILITY":
  6. return { ...state, tabBarVisible: action.payload}
  7. case "LOGIN":
  8. return { ...state, loggedIn: true, };
  9. case "LOGOUT":
  10. return { ...state, loggedIn: false, };
  11. case "UPDATE_SELECTED_LANDMARK":
  12. return { ...state, selectedLandmark: action.payload, };
  13. case "UPDATE_LANDMARKS":
  14. return { ...state, landmarks: action.payload, };
  15. case "UPDATE_PLACES":
  16. return { ...state, places: action.payload, };
  17. case "UPDATE_SELECTED_PLACES":
  18. return { ...state, selectedPlaces: action.payload, };
  19. case "UPDATE_SELECTED_PLACE":
  20. return { ...state, selectedPlace: action.payload, };
  21. case "UPDATE_LOCATION_PERMISSION":
  22. return { ...state, locationPermission: action.payload, };
  23. case "UPDATE_LOCATION":
  24. return { ...state, location: action.payload, };
  25. default:
  26. throw new Error();
  27. }
  28. }
  29. export const seedLandmarkData = () => {
  30. return [
  31. {
  32. id: uuidv4(),
  33. rating: 5,
  34. postedBy: 'cdmoss',
  35. latitude: 53.48914616441755,
  36. longitude: -113.49762260454305,
  37. dateAdded: new Date(),
  38. title: "Allard way pothole",
  39. desc: "A massive pothole on the Allard Way sidewalk.",
  40. icon: 'pothole',
  41. },
  42. {
  43. id: uuidv4(),
  44. rating: 4,
  45. postedBy: 'cdmoss',
  46. latitude: 53.51839016964649,
  47. longitude: -113.49473594001775,
  48. dateAdded: new Date(),
  49. title: "Accessible bathroom on Whyte",
  50. desc: "A conveniently placed accessible bathroom.",
  51. icon: 'washroom',
  52. comments: [
  53. ]
  54. },
  55. {
  56. id: uuidv4(),
  57. rating: 0,
  58. postedBy: 'cendersby',
  59. latitude: 53.48963,
  60. longitude: -113.49401,
  61. dateAdded: new Date(),
  62. title: "Peter's Drive-in Construction",
  63. desc: "The sidewalk in front of Peter's is being rebuilt.",
  64. icon: 'roadblock',
  65. comments: [
  66. {
  67. id: uuidv4(),
  68. name: "shampshire",
  69. dateAdded: new Date(),
  70. text: "No! Not peters!"
  71. },
  72. {
  73. id: uuidv4(),
  74. name: "nmaeda",
  75. dateAdded: new Date(),
  76. text: "Good, Peter's is gross!"
  77. },
  78. ]
  79. },
  80. ];
  81. };
  82. const seedPlaces = () => {
  83. return [{
  84. id: uuidv4(),
  85. color: 'green',
  86. postedBy: 'cdmoss',
  87. coordinates: [
  88. [
  89. [
  90. -113.53052616119385,
  91. 53.53087032262937
  92. ],
  93. [
  94. -113.53065490722656,
  95. 53.523038509337624
  96. ],
  97. [
  98. -113.53241443634032,
  99. 53.52298748300469
  100. ],
  101. [
  102. -113.53250026702881,
  103. 53.518701051607486
  104. ],
  105. [
  106. -113.53310108184813,
  107. 53.51783350677023
  108. ],
  109. [
  110. -113.5234022140503,
  111. 53.51640457066658
  112. ],
  113. [
  114. -113.52087020874023,
  115. 53.51811418498503
  116. ],
  117. [
  118. -113.52095603942871,
  119. 53.52298748300469
  120. ],
  121. [
  122. -113.51490497589111,
  123. 53.52291094339006
  124. ],
  125. [
  126. -113.51499080657958,
  127. 53.525895885886285
  128. ],
  129. [
  130. -113.51833820343018,
  131. 53.526941841607
  132. ],
  133. [
  134. -113.52099895477295,
  135. 53.52854899152384
  136. ],
  137. [
  138. -113.52481842041016,
  139. 53.529773445765805
  140. ],
  141. [
  142. -113.53052616119385,
  143. 53.53087032262937
  144. ]
  145. ]
  146. ],
  147. dateAdded: new Date(),
  148. name: "UofA",
  149. desc: "The University of Alberta.",
  150. tips: [
  151. {
  152. id: uuidv4(),
  153. name: "shampshire",
  154. dateAdded: new Date(),
  155. text: "There are lots of great accessibility features at the University.",
  156. rating: 3,
  157. liked: false,
  158. },
  159. ]
  160. },
  161. {
  162. id: uuidv4(),
  163. postedBy: 'cdmoss',
  164. coordinates: [
  165. [
  166. [
  167. -113.52713584899902,
  168. 53.52285991690344
  169. ],
  170. [
  171. -113.52730751037598,
  172. 53.52074226350543
  173. ],
  174. [
  175. -113.52591276168823,
  176. 53.52081880703848
  177. ],
  178. [
  179. -113.52580547332764,
  180. 53.522847160272185
  181. ],
  182. [
  183. -113.52713584899902,
  184. 53.52285991690344
  185. ]
  186. ]
  187. ],
  188. dateAdded: new Date(),
  189. name: "ECHA",
  190. color: 'red',
  191. desc: "The Edmonton Clinic Health Academy building.",
  192. tips: [
  193. {
  194. id: uuidv4(),
  195. name: "shampshire",
  196. dateAdded: new Date(),
  197. text: "There are lots of great accessibility features at ECHA.",
  198. rating: 3,
  199. liked: false
  200. },
  201. ]
  202. },
  203. {
  204. id: uuidv4(),
  205. rating: 4,
  206. postedBy: 'cdmoss',
  207. color: 'blue',
  208. dateAdded: new Date(),
  209. name: "SUB",
  210. desc: "The Student Union Building.",
  211. tips: [
  212. {
  213. id: uuidv4(),
  214. name: "shampshire",
  215. dateAdded: new Date(),
  216. text: "There are lots of great accessibility features at SUB.",
  217. rating: 3,
  218. liked: false
  219. },
  220. ],
  221. coordinates: [
  222. [
  223. [
  224. -113.52796196937561,
  225. 53.525691793953534
  226. ],
  227. [
  228. -113.52800488471983,
  229. 53.5249710864483
  230. ],
  231. [
  232. -113.5263204574585,
  233. 53.5249710864483
  234. ],
  235. [
  236. -113.52630972862244,
  237. 53.525398410077315
  238. ],
  239. [
  240. -113.52684617042542,
  241. 53.52544943350612
  242. ],
  243. [
  244. -113.5268783569336,
  245. 53.52566628239279
  246. ],
  247. [
  248. -113.52796196937561,
  249. 53.525691793953534
  250. ]
  251. ]
  252. ]
  253. }]
  254. }
  255. const mockState = {
  256. tabBarVisible: true,
  257. location: null,
  258. locationPermission: false,
  259. loggedIn: false,
  260. username: "cdmoss",
  261. email: "cdmoss@gmail.com",
  262. rank: 0,
  263. height: 170,
  264. weight: 91,
  265. landmarks: seedLandmarkData(),
  266. selectedLandmark: {
  267. icon: 'barrier'
  268. },
  269. places: seedPlaces(),
  270. selectedPlaces: [],
  271. selectedPlace: {name: ''},
  272. }
  273. export const MockContext = createContext(mockState);
  274. export const MockProvider = ({ children }) => {
  275. const [state, dispatch] = useReducer(mockReducer, mockState);
  276. return (
  277. <MockContext.Provider value={{ state, dispatch }}>
  278. {children}
  279. </MockContext.Provider>
  280. );
  281. };
  282. export const useMockState = () => {
  283. const context = useContext(MockContext);
  284. if (context === undefined) {
  285. throw new Error(
  286. "useMockState must be used within a MockProvider"
  287. );
  288. }
  289. return context;
  290. }