-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
186 additions
and
163 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
// https://nuxt.com/docs/api/configuration/nuxt-config | ||
export default defineNuxtConfig({ | ||
ssr: false, | ||
modules: ['@unocss/nuxt'], | ||
modules: ['@unocss/nuxt', '@vueuse/nuxt'], | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
<template> | ||
<div v-if="quakes?.length > 0" class="grid"> | ||
<QuakeItem :has-time-zone="true" v-for="quake in sortedQuakes" :key="quake.id" :quake="quake" /> | ||
<Loading v-if="loading" /> | ||
</div> | ||
</template> | ||
|
||
<script setup lang="ts"> | ||
import { invoke } from "@tauri-apps/api" | ||
import type { IQuake } from "@/types" | ||
const router = useRouter(); | ||
const quakes = ref<IQuake[]>([]) | ||
const loading = ref<boolean>(false); | ||
const refreshFrequency = useState<number>('refreshFrequency') | ||
const notifyQuakeSize = useState<number>('notifyQuakeSize') | ||
// @ts-ignore | ||
const sortedQuakes = computed(() => quakes.value.sort((a: IQuake, b: IQuake) => a.eventDate < b.eventDate)) | ||
const fetchLatestQuakesFromAfad = async () => { | ||
if (router.currentRoute.value.name === 'index') { | ||
loading.value = true; | ||
const result = await invoke<string>("get_last_five_events") | ||
const parsed: IQuake[] = JSON.parse(result) as IQuake[] | ||
if (quakes.value.length >= 100) { | ||
quakes.value = []; | ||
} | ||
if (quakes.value.length > 0) { | ||
parsed.map(async (quake) => { | ||
const filtered = quakes.value.find(x => x.id === quake.id) | ||
if (!filtered) { | ||
if (quake.magnitude >= notifyQuakeSize.value) { | ||
await pushMessage({ title: `Afad Deprem Merkezi`, body: `${quake.location}: ${quake.magnitude} [${quake.depth}km]` }); | ||
} | ||
quakes.value.push(quake) | ||
} | ||
}) | ||
} else { | ||
quakes.value = parsed; | ||
} | ||
setTimeout(() => loading.value = false, 1800) | ||
} | ||
} | ||
const { resume, pause } = useIntervalFn(() => { | ||
fetchLatestQuakesFromAfad() | ||
}, () => refreshFrequency.value * 1000) | ||
onMounted(async () => { | ||
quakes.value = await fecthLatestFiftyEvents(); | ||
resume(); | ||
}) | ||
watchEffect(() => resume()) | ||
onUnmounted(() => pause()) | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
<template> | ||
<div class="grid"> | ||
<template v-if="quakes?.length > 0"> | ||
<QuakeItem :has-time-zone="false" v-for="quake in sortedQuakes" :key="quake.id" :quake="quake" /> | ||
</template> | ||
<Loading v-if="loading" /> | ||
</div> | ||
</template> | ||
|
||
<script setup lang="ts"> | ||
import { invoke } from "@tauri-apps/api" | ||
import { useIntervalFn } from '@vueuse/core' | ||
import type { PIQuake } from "@/types" | ||
const quakes = ref<PIQuake[]>([]) | ||
const loading = ref<boolean>(false); | ||
const refreshFrequency = useState<number>('refreshFrequency') | ||
const notifyQuakeSize = useState<number>('notifyQuakeSize') | ||
const router = useRouter(); | ||
// @ts-ignore | ||
const sortedQuakes = computed(() => quakes.value.sort((a: PIQuake, b: PIQuake) => a.eventDate < b.eventDate)) | ||
const fetchLatestQuakesFromKandilli = async () => { | ||
if (router.currentRoute.value.name === 'kandilli') { | ||
loading.value = true; | ||
const result = await invoke<string>("fetch_quakes") | ||
const parsed: PIQuake[] = JSON.parse(result) as PIQuake[] | ||
const mapped: PIQuake[] = parsed.map((quake: PIQuake) => { | ||
return { | ||
id: quake.id, | ||
eventDate: quake.eventDate, | ||
magnitude: parseFloat(String(quake.magnitude)), | ||
location: quake.location, | ||
depth: parseInt(String(quake.depth)) | ||
} | ||
}) | ||
if (quakes.value.length > 0) { | ||
mapped.map(async (quake) => { | ||
const filtered = quakes.value.find((x: PIQuake) => x.id === quake.id) | ||
if (!filtered) { | ||
if (quake.magnitude >= notifyQuakeSize.value) { | ||
await pushMessage({ title: `Kandilli Rasathanesi`, body: `${quake.location}: ${quake.magnitude} [${quake.depth}km]` }); | ||
} | ||
quakes.value.push(quake) | ||
} | ||
}) | ||
} else { | ||
quakes.value = mapped; | ||
} | ||
setTimeout(() => loading.value = false, 1700) | ||
} | ||
} | ||
const { resume, pause } = useIntervalFn(() => { | ||
fetchLatestQuakesFromKandilli() | ||
}, () => refreshFrequency.value * 1000) | ||
onMounted(() => { | ||
fetchLatestQuakesFromKandilli() | ||
resume() | ||
}) | ||
onUnmounted(() => pause()) | ||
</script> |
Oops, something went wrong.