Skip to content

Commit

Permalink
Convert more components to TypeScript
Browse files Browse the repository at this point in the history
  • Loading branch information
steinbro committed Nov 22, 2024
1 parent 37c1a43 commit 237f64f
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 21 deletions.
2 changes: 1 addition & 1 deletion src/components/BeaconController.vue
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
</p>
</template>

<script setup>
<script setup lang="ts">
import { beacon } from '../state/beacon';
const toggleBeacon = () => {
Expand Down
27 changes: 15 additions & 12 deletions src/components/CalloutList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@
class="beacon-button"
@click="startBeacon"
:data-name="callout.text"
:data-latitude="callout.location.geometry.coordinates[1]"
:data-longitude="callout.location.geometry.coordinates[0]"
:data-latitude="callout.location!.geometry.coordinates[1]"
:data-longitude="callout.location!.geometry.coordinates[0]"
>
🔊
</button>
<RouterLink :to="{ name: 'Detail', params: {
name: callout.text,
lat: callout.location.geometry.coordinates[1],
lon: callout.location.geometry.coordinates[0],
lat: callout.location!.geometry.coordinates[1],
lon: callout.location!.geometry.coordinates[0],
} }">
{{ callout.text }}
</RouterLink>
Expand All @@ -26,19 +26,22 @@
</section>
</template>

<script setup>
<script setup lang="ts">
import BeaconController from './BeaconController.vue'
import { QueuedSpeech } from '../state/audio';
import { beacon } from '../state/beacon';
const props = defineProps({
callouts: Array,
})
interface CalloutListProps {
callouts: QueuedSpeech[];
}
const props = defineProps<CalloutListProps>();
const startBeacon = (e) => {
const startBeacon = (e: MouseEvent) => {
let target = e.target as HTMLButtonElement;
beacon.set({
name: e.target.getAttribute("data-name"),
latitude: e.target.getAttribute('data-latitude'),
longitude: e.target.getAttribute('data-longitude')
name: target.getAttribute("data-name")!,
latitude: +target.getAttribute('data-latitude')!,
longitude: +target.getAttribute('data-longitude')!
});
beacon.start();
};
Expand Down
14 changes: 8 additions & 6 deletions src/components/VoiceSelector.vue
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@
</select>
</template>

<script setup>
import { audioQueue } from '../state/audio';
<script setup lang="ts">
import { audioQueue, SpeechSynthesisVoiceWithIndex } from '../state/audio';
import { ref, onMounted, watch } from 'vue';
const voices = ref([]);
const selectedVoice = ref(null);
const voices = ref<SpeechSynthesisVoiceWithIndex[]>([]);
const selectedVoice = ref<number | null>(null);
onMounted(async () => {
if (window.speechSynthesis) {
Expand All @@ -34,12 +34,14 @@ onMounted(async () => {
const reloadVoices = async () => {
voices.value = await audioQueue.loadVoices();
selectedVoice.value = audioQueue.voice.voiceIndex;
if (audioQueue.voice) {
selectedVoice.value = audioQueue.voice.voiceIndex;
}
};
watch(selectedVoice, (newValue, oldValue) => {
if (newValue !== null) {
audioQueue.setVoice(selectedVoice.value);
audioQueue.setVoice(newValue);
}
});
</script>
5 changes: 5 additions & 0 deletions src/shims-vue.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
declare module '*.vue' {
import { DefineComponent } from 'vue';
const component: DefineComponent<{}, {}, any>;
export default component;
}
4 changes: 2 additions & 2 deletions src/state/audio.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,15 +98,15 @@ export async function playSpatialSpeech(text: string, voiceIndex: number, rate:
});
}

type SpeechSynthesisVoiceWithIndex = SpeechSynthesisVoice & {
export type SpeechSynthesisVoiceWithIndex = SpeechSynthesisVoice & {
voiceIndex: number;
}

interface QueuedEffect {
soundUrl: string;
location?: Feature<Point>;
}
interface QueuedSpeech {
export interface QueuedSpeech {
text: string;
location?: Feature<Point>;
includeDistance?: boolean;
Expand Down

0 comments on commit 237f64f

Please sign in to comment.