Skip to content

Commit

Permalink
fix(map): Fix custom style not showing
Browse files Browse the repository at this point in the history
Cached 404 responses were causing the custom map to continue to not show even after the file was added to the phone. This moves logic to the api module and uses the no-cache header.
  • Loading branch information
gmaclennan committed May 3, 2019
1 parent d5a467d commit bf55b1b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
4 changes: 4 additions & 0 deletions src/frontend/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ export function getMapStyleUrl(id: string): string {
return `${BASE_URL}styles/${id}/style.json`;
}

export function checkMapStyle(id: string): Promise<any> {
return api.get(`styles/${id}/style.json`);
}

export function savePhoto({
fullUri,
thumbnailUri
Expand Down
7 changes: 3 additions & 4 deletions src/frontend/screens/MapScreen.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@
import * as React from "react";
import { View } from "react-native";
import MapboxGL from "@react-native-mapbox/maps";
import ky from "ky";

import MapView from "../sharedComponents/MapView";
import ObservationsContext from "../context/ObservationsContext";
import { getMapStyleUrl } from "../api";
import { getMapStyleUrl, checkMapStyle } from "../api";

type Props = {
onAddPress: () => void
Expand All @@ -23,8 +22,8 @@ class MapStyleProvider extends React.Component<
async componentDidMount() {
try {
const offlineStyleURL = getMapStyleUrl("default");
await ky(offlineStyleURL);
console.log("UpdatedStyleURL", offlineStyleURL);
// Check if the mapStyle exists on the server
await checkMapStyle("default");
this.setState({ styleURL: offlineStyleURL });
} catch (e) {
// If we don't have a default offline style, don't do anything
Expand Down

0 comments on commit bf55b1b

Please sign in to comment.