-
Notifications
You must be signed in to change notification settings - Fork 1
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
1 parent
30c8649
commit fe231c5
Showing
14 changed files
with
112 additions
and
30 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 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
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,22 @@ | ||
<script setup lang="ts"> | ||
import { useRadioMutation } from "../hooks"; | ||
import Preset from "./Preset.vue"; | ||
defineProps({ | ||
radio: { | ||
type: Object as () => Radio, | ||
required: true, | ||
}, | ||
}); | ||
const { mutate, isLoading } = useRadioMutation() | ||
</script> | ||
|
||
<template> | ||
<preset :key="p.number" v-for="p of radio.presets" :selected="radio.preset_number == p.number" :preset="p" | ||
:loading="isLoading" @click="() => mutate({ uuid: radio.uuid, preset: p.number })" /> | ||
</template> | ||
|
||
<style> | ||
</style> |
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
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,18 @@ | ||
<script setup lang="ts"> | ||
import { useRadiosDiscoverMutation } from "../hooks"; | ||
import DButton from "./DaisyUI/DButton.vue"; | ||
const { mutate, isLoading } = useRadiosDiscoverMutation() | ||
</script> | ||
|
||
<template> | ||
<div class="tooltip" data-tip="Discover"> | ||
<d-button v-bind="$attrs" aria-label="Discover" :loading="isLoading" @click="() => mutate({})"> | ||
<v-icon name="fa-search" /> | ||
</d-button> | ||
</div> | ||
</template> | ||
|
||
<style> | ||
</style> |
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,3 +1,3 @@ | ||
export { useWS } from "./ws" | ||
export { useRadiosQuery } from "./query" | ||
export { useRadioMutation } from "./mutation" | ||
export { useRadioMutation, useRadiosDiscoverMutation } from "./mutation" |
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 @@ | ||
export const KEY_RADIOS = "radios" |
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,13 +1,33 @@ | ||
import { useMutation } from "vue-query"; | ||
import { useMutation, useQueryClient } from "vue-query"; | ||
|
||
import { API_URL } from "../constants" | ||
import { KEY_RADIOS } from "./key"; | ||
|
||
export function useRadioMutation(uuid: string) { | ||
return useMutation((req: RadioMutation) => fetch(API_URL + "/api/radio/" + uuid, { body: JSON.stringify(req), method: "PATCH" }) | ||
export function useRadioMutation() { | ||
return useMutation((req: RadioMutation) => { | ||
const { uuid, ...jreq } = req | ||
return fetch(API_URL + "/api/radio/" + uuid, { body: JSON.stringify(jreq), method: "PATCH" }) | ||
.then((res) => res.json()) | ||
.then((json: APIResponse<void>) => { | ||
if (!json.ok) { | ||
throw new Error(json.error.message); | ||
} | ||
}) | ||
}) | ||
}; | ||
|
||
export function useRadiosDiscoverMutation() { | ||
const queryClient = useQueryClient() | ||
return useMutation((_: RadiosDiscoverMutation) => fetch(API_URL + "/api/radios", { method: "POST" }) | ||
.then((res) => res.json()) | ||
.then((json: APIResponse<void>) => { | ||
.then((json: APIResponse<number>) => { | ||
if (!json.ok) { | ||
throw new Error(json.error.message); | ||
} | ||
})) | ||
return json.data | ||
}), { | ||
onSuccess: (_: number) => { | ||
queryClient.invalidateQueries(KEY_RADIOS) | ||
} | ||
}) | ||
}; |
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
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