@@ -864,6 +864,7 @@ export default {
864
864
filtersOpen: false ,
865
865
zipCode: " " ,
866
866
displayLocation: " " ,
867
+ manualZip: false ,
867
868
updatingCounts: false ,
868
869
selected: null ,
869
870
localStoreLinks: [],
@@ -1028,31 +1029,46 @@ export default {
1028
1029
async mounted () {
1029
1030
// Pick a random hero image after hydration to avoid SSR hydration mismatch
1030
1031
this .twoUpIndex = Math .floor (Math .random () * twoUpImageCredits .length );
1031
- this .displayLocation = localStorage .getItem (" displayLocation" )
1032
- this .zipCode = localStorage .getItem (" zipCode" )
1033
- this .filterValues [" States" ] = [localStorage .getItem (" state" )]
1034
- if (" geolocation" in navigator || this .zipCode == ' ' ) {
1035
- navigator .geolocation .getCurrentPosition (async (position ) => {
1036
- let data = {
1037
- latitude: position .coords .latitude ,
1038
- longitude: position .coords .longitude ,
1039
- };
1040
- // get zipcode by lng/lat
1041
- // get state by lng / lat
1042
- const response = await fetch (" /get-zip" , {
1043
- method: " POST" , // *GET, POST, PUT, DELETE, etc.
1044
- headers: {
1045
- " Content-Type" : " application/json" ,
1046
- },
1047
- body: JSON .stringify (data), // body data type must match "Content-Type" header
1048
- });
1049
- let json = await response .json ();
1050
- this .zipCode = json .code ;
1051
- this .filterValues [" States" ] = [json .state ];
1052
- this .taisplayLocation = ` ${ json .city } , ${ json .state } ` ;
1053
- });
1054
- } else {
1055
- console .log (" Location not supported" );
1032
+
1033
+ this .displayLocation = localStorage .getItem (" displayLocation" ) || " " ;
1034
+ this .zipCode = localStorage .getItem (" zipCode" ) || " " ;
1035
+ this .manualZip = localStorage .getItem (" manualZip" ) === " true" ;
1036
+ this .filterValues [" States" ] = [localStorage .getItem (" state" )];
1037
+
1038
+ if (! this .manualZip && " geolocation" in navigator ) {
1039
+ navigator .geolocation .getCurrentPosition (
1040
+ async (position ) => {
1041
+ const data = {
1042
+ latitude: position .coords .latitude ,
1043
+ longitude: position .coords .longitude ,
1044
+ };
1045
+
1046
+ const response = await fetch (" /get-zip" , {
1047
+ method: " POST" ,
1048
+ headers: {
1049
+ " Content-Type" : " application/json" ,
1050
+ },
1051
+ body: JSON .stringify (data),
1052
+ });
1053
+ let json = await response .json ();
1054
+ this .zipCode = json .code ;
1055
+ this .filterValues [" States" ] = [json .state ];
1056
+ this .displayLocation = ` ${ json .city } , ${ json .state } ` ;
1057
+
1058
+ localStorage .setItem (" zipCode" , this .zipCode );
1059
+ localStorage .setItem (" state" , json .state );
1060
+ localStorage .setItem (" displayLocation" , this .displayLocation );
1061
+ localStorage .removeItem (" manualZip" );
1062
+ },
1063
+ () => {
1064
+ if (! this .zipCode ) {
1065
+ this .zipCode = " 19355" ;
1066
+ }
1067
+ }
1068
+ );
1069
+ } else if (! this .zipCode ) {
1070
+ // Geolocation not available or user chose manual zip
1071
+ this .zipCode = " 19355" ;
1056
1072
}
1057
1073
1058
1074
await this .determineFilterCountsAndSubmit ();
@@ -1101,6 +1117,8 @@ export default {
1101
1117
localStorage .setItem (" displayLocation" , this .displayLocation )
1102
1118
localStorage .setItem (" zipCode" , this .zipCode )
1103
1119
localStorage .setItem (" state" , json .state )
1120
+ this .manualZip = true ;
1121
+ localStorage .setItem (" manualZip" , " true" )
1104
1122
},
1105
1123
async getVendors () {
1106
1124
if (! this .selected ) return [];
0 commit comments