Navbar and some fix to weather
This commit is contained in:
@@ -1,18 +1,17 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import MainDashboard from "@/components/MainDashboard.vue";
|
import MainDashboard from "@/components/MainDashboard.vue";
|
||||||
|
import NavBar from "@/components/NavBar.vue";
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<header>
|
<header>
|
||||||
<img alt="Vue logo" class="logo" src="./assets/logo.svg" width="125" height="125"/>
|
<NavBar/>
|
||||||
<p><b>HEADER</b></p>
|
|
||||||
<!-- TODO: A text input for users to enter the name of a city. -->
|
<!-- TODO: A text input for users to enter the name of a city. -->
|
||||||
<!-- TODO: A search button to trigger the data fetching process. -->
|
<!-- TODO: A search button to trigger the data fetching process. -->
|
||||||
<!-- TODO: an homepage to show instead of the dashboard if no city selected -->
|
<!-- TODO: an homepage to show instead of the dashboard if no city selected -->
|
||||||
|
|
||||||
</header>
|
</header>
|
||||||
|
|
||||||
<main>
|
<main class="mt-10 mx-1">
|
||||||
<MainDashboard/>
|
<MainDashboard/>
|
||||||
</main>
|
</main>
|
||||||
</template>
|
</template>
|
||||||
|
|||||||
@@ -40,15 +40,16 @@ function timestampToISO(timestamp: number): string {
|
|||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<p><b>MAIN BODY</b></p>
|
|
||||||
<div>
|
<div>
|
||||||
<div>
|
<div>
|
||||||
<p><b>Search</b></p>
|
<form @submit.prevent="searchClicked">
|
||||||
<n-input v-model:value="city" type="text" placeholder="City"/>
|
<p><b>Search</b></p>
|
||||||
<n-input v-model:value="country" type="text" placeholder="Country"/>
|
<n-input v-model:value="city" type="text" placeholder="City"/>
|
||||||
<n-button type="primary" @click="searchClicked" :loading="searchLoading">
|
<n-input v-model:value="country" type="text" placeholder="Country"/>
|
||||||
Search
|
<n-button attr-type="submit" type="primary" :loading="searchLoading">
|
||||||
</n-button>
|
Search
|
||||||
|
</n-button>
|
||||||
|
</form>
|
||||||
</div>
|
</div>
|
||||||
<div v-show="weather.placeFound.length > 0">
|
<div v-show="weather.placeFound.length > 0">
|
||||||
<p><b>Found</b></p>
|
<p><b>Found</b></p>
|
||||||
@@ -67,6 +68,7 @@ function timestampToISO(timestamp: number): string {
|
|||||||
<p><b>Weather: {{ weather.nowWeather.weather[0].main }}
|
<p><b>Weather: {{ weather.nowWeather.weather[0].main }}
|
||||||
<img v-if="weather.nowIcons !== null"
|
<img v-if="weather.nowIcons !== null"
|
||||||
:src="weather.nowIcons['4x']"
|
:src="weather.nowIcons['4x']"
|
||||||
|
class="bg-gray-300"
|
||||||
alt="Weather Icon"/>
|
alt="Weather Icon"/>
|
||||||
</b></p>
|
</b></p>
|
||||||
<p>Temperature: {{ weather.nowWeather.main.temp }} K</p>
|
<p>Temperature: {{ weather.nowWeather.main.temp }} K</p>
|
||||||
@@ -76,6 +78,7 @@ function timestampToISO(timestamp: number): string {
|
|||||||
<n-button type="error" @click="weather.resetGeo()">Clear</n-button>
|
<n-button type="error" @click="weather.resetGeo()">Clear</n-button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<p v-for="i in 50" :key="i">TEST {{i}}</p>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<style scoped>
|
<style scoped>
|
||||||
|
|||||||
25
src/components/NavBar.vue
Normal file
25
src/components/NavBar.vue
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
import {computed} from "vue";
|
||||||
|
import { useWeatherStore } from "@/stores/weather.ts";
|
||||||
|
|
||||||
|
const weather = useWeatherStore();
|
||||||
|
|
||||||
|
const cityName = computed(() => {
|
||||||
|
if(weather.geo == null) return 'None';
|
||||||
|
return `${weather.geo.name}, ${weather.geo.country}`
|
||||||
|
})
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<div class="bg-blue-400 border-gray-200 w-full flex flex-wrap items-center justify-between px-2 mx-auto fixed z-30 start-0 top-0 h-10">
|
||||||
|
<div class="flex items-center">
|
||||||
|
<img alt="Vue logo" class="logo" src="@/assets/logo.svg" width="32" height="32"/>
|
||||||
|
<span class="font-bold">Meteo Vue</span>
|
||||||
|
</div>
|
||||||
|
<span>Nome Citta: {{cityName}}</span>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<style scoped>
|
||||||
|
|
||||||
|
</style>
|
||||||
@@ -29,16 +29,17 @@ export const useWeatherStore = defineStore('weather', () => {
|
|||||||
placeFound.value = res.data;
|
placeFound.value = res.data;
|
||||||
}
|
}
|
||||||
|
|
||||||
async function updateGeo(geo: Geo) {
|
async function updateGeo(inGeo: Geo) {
|
||||||
weatherLoading.value = true;
|
weatherLoading.value = true;
|
||||||
try {
|
try {
|
||||||
[
|
[
|
||||||
nowWeather.value,
|
nowWeather.value,
|
||||||
forecast.value
|
forecast.value
|
||||||
] = await Promise.all([
|
] = await Promise.all([
|
||||||
fetchNow(geo),
|
fetchNow(inGeo),
|
||||||
fetchForecast(geo),
|
fetchForecast(inGeo),
|
||||||
]);
|
]);
|
||||||
|
geo.value = inGeo;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error(e);
|
console.error(e);
|
||||||
} finally {
|
} finally {
|
||||||
@@ -49,6 +50,7 @@ export const useWeatherStore = defineStore('weather', () => {
|
|||||||
async function resetGeo() {
|
async function resetGeo() {
|
||||||
nowWeather.value = null;
|
nowWeather.value = null;
|
||||||
forecast.value = [];
|
forecast.value = [];
|
||||||
|
geo.value = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
async function fetchNow(geo: Geo) {
|
async function fetchNow(geo: Geo) {
|
||||||
|
|||||||
Reference in New Issue
Block a user