Basic app functions are working
definitely on the "minimal" side but this *mostly* covers my own usage of the old mobile.weather.gov app
This commit is contained in:
parent
397b7b02e5
commit
5a584982e4
28 changed files with 2020 additions and 473 deletions
|
@ -1,12 +0,0 @@
|
|||
import { ref, computed } from 'vue'
|
||||
import { defineStore } from 'pinia'
|
||||
|
||||
export const useCounterStore = defineStore('counter', () => {
|
||||
const count = ref(0)
|
||||
const doubleCount = computed(() => count.value * 2)
|
||||
function increment() {
|
||||
count.value++
|
||||
}
|
||||
|
||||
return { count, doubleCount, increment }
|
||||
})
|
39
src/stores/location.js
Normal file
39
src/stores/location.js
Normal file
|
@ -0,0 +1,39 @@
|
|||
import { defineStore } from 'pinia'
|
||||
|
||||
|
||||
const getDefaults = () => {
|
||||
|
||||
const locations = JSON.parse(localStorage.getItem('location.locations') || '[]')
|
||||
|
||||
return {
|
||||
locations,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
export const useLocationStore = defineStore('location', {
|
||||
|
||||
state: () => {
|
||||
return getDefaults()
|
||||
},
|
||||
|
||||
actions: {
|
||||
|
||||
addLocation(coordinates, cityState) {
|
||||
for (let loc of this.locations) {
|
||||
if (loc.coordinates == coordinates) {
|
||||
return
|
||||
}
|
||||
}
|
||||
this.locations.push({coordinates, cityState})
|
||||
localStorage.setItem('location.locations', JSON.stringify(this.locations))
|
||||
},
|
||||
|
||||
removeLocation(location) {
|
||||
this.locations = this.locations.filter((loc) => {
|
||||
return loc.coordinates != location.coordinates
|
||||
})
|
||||
localStorage.setItem('location.locations', JSON.stringify(this.locations))
|
||||
},
|
||||
},
|
||||
})
|
90
src/stores/weather.js
Normal file
90
src/stores/weather.js
Normal file
|
@ -0,0 +1,90 @@
|
|||
import { defineStore } from 'pinia'
|
||||
|
||||
|
||||
const getDefaults = () => {
|
||||
|
||||
const coordinates = localStorage.getItem('weather.coordinates')
|
||||
const cityState = localStorage.getItem('weather.cityState')
|
||||
|
||||
return {
|
||||
coordinates,
|
||||
cityState,
|
||||
weather: null,
|
||||
forecast: null,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
export const useWeatherStore = defineStore('weather', {
|
||||
|
||||
state: () => {
|
||||
return getDefaults()
|
||||
},
|
||||
|
||||
actions: {
|
||||
|
||||
clearWeather() {
|
||||
this.setCoordinates(null)
|
||||
this.setCityState(null)
|
||||
this.setWeather(null)
|
||||
this.setForecast(null)
|
||||
},
|
||||
|
||||
async getWeather() {
|
||||
|
||||
if (!this.weather) {
|
||||
|
||||
const url = `https://api.weather.gov/points/${this.coordinates}`
|
||||
const response = await fetch(url)
|
||||
const weather = await response.json()
|
||||
if (weather.status == 404) {
|
||||
throw new Error(`Data not found for ${this.coordinates}`)
|
||||
}
|
||||
|
||||
const city = weather.properties.relativeLocation.properties.city
|
||||
const state = weather.properties.relativeLocation.properties.state
|
||||
const cityState = `${city}, ${state}`
|
||||
if (this.cityState != cityState) {
|
||||
this.setCityState(cityState)
|
||||
}
|
||||
|
||||
this.setWeather(weather)
|
||||
}
|
||||
|
||||
return this.weather
|
||||
},
|
||||
|
||||
async getForecast() {
|
||||
|
||||
if (!this.forecast) {
|
||||
|
||||
const weather = await this.getWeather(this.coordinates)
|
||||
|
||||
const url = weather.properties.forecast
|
||||
const response = await fetch(url)
|
||||
const forecast = await response.json()
|
||||
this.setForecast(forecast)
|
||||
}
|
||||
|
||||
return this.forecast
|
||||
},
|
||||
|
||||
setCoordinates(value) {
|
||||
this.coordinates = value
|
||||
localStorage.setItem('weather.coordinates', value)
|
||||
},
|
||||
|
||||
setCityState(value) {
|
||||
this.cityState = value
|
||||
localStorage.setItem('weather.cityState', value)
|
||||
},
|
||||
|
||||
setWeather(value) {
|
||||
this.weather = value
|
||||
},
|
||||
|
||||
setForecast(value) {
|
||||
this.forecast = value
|
||||
},
|
||||
},
|
||||
})
|
Loading…
Add table
Add a link
Reference in a new issue