Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: 停止ボタンを連続再生中と通常再生中で共用にする #1534

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 18 additions & 27 deletions src/components/AudioDetail.vue
Original file line number Diff line number Diff line change
Expand Up @@ -22,25 +22,23 @@
</q-tabs>
</div>
<div class="play-button-wrapper">
<template v-if="!nowPlayingContinuously">
<q-btn
v-if="!nowPlaying && !nowGenerating"
fab
color="primary"
text-color="display-on-primary"
icon="play_arrow"
@click="play"
></q-btn>
<q-btn
v-else
fab
color="primary"
text-color="display-on-primary"
icon="stop"
:disable="nowGenerating"
@click="stop"
></q-btn>
</template>
<q-btn
v-if="!nowPlaying && !nowGenerating"
fab
color="primary"
text-color="display-on-primary"
icon="play_arrow"
@click="play"
></q-btn>
<q-btn
v-else
fab
color="primary"
text-color="display-on-primary"
icon="stop"
:disable="nowGenerating"
@click="stop"
></q-btn>
</div>
</div>

Expand Down Expand Up @@ -513,18 +511,11 @@ const stop = () => {
store.dispatch("STOP_AUDIO");
};

const nowPlaying = computed(
() => props.activeAudioKey === store.state.nowPlayingAudioKey
);
const nowPlaying = computed(() => store.getters.NOW_PLAYING);
const nowGenerating = computed(
() => store.state.audioStates[props.activeAudioKey]?.nowGenerating
);

// continuously play
const nowPlayingContinuously = computed(
() => store.state.nowPlayingContinuously
);

const audioDetail = ref<HTMLElement>();
let accentPhraseElems: HTMLElement[] = [];
const addAccentPhraseElem: VNodeRef = (elem) => {
Expand Down
8 changes: 4 additions & 4 deletions src/components/HeaderBar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ const hotkeyMap = new Map<HotkeyAction, () => HotkeyReturnType>([
() => {
if (!uiLocked.value) {
if (nowPlayingContinuously.value) {
stopContinuously();
stop();
} else {
playContinuously();
}
Expand Down Expand Up @@ -119,7 +119,7 @@ const playContinuously = async () => {
});
}
};
const stopContinuously = () => {
const stop = () => {
store.dispatch("STOP_AUDIO");
};
const generateAndSaveOneAudio = async () => {
Expand Down Expand Up @@ -159,8 +159,8 @@ const usableButtons: Record<
disable: uiLocked,
},
STOP: {
click: stopContinuously,
disable: computed(() => !nowPlayingContinuously.value),
click: stop,
disable: computed(() => !store.getters.NOW_PLAYING),
},
EXPORT_AUDIO_ONE: {
click: generateAndSaveOneAudio,
Expand Down
10 changes: 10 additions & 0 deletions src/store/audio.ts
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,16 @@ export const audioStore = createPartialStore<AudioStoreTypes>({
},
},

NOW_PLAYING: {
getter(state, getters) {
const activeAudioKey = getters.ACTIVE_AUDIO_KEY;
return (
activeAudioKey != undefined &&
activeAudioKey === state.nowPlayingAudioKey
);
},
},

ACTIVE_AUDIO_ELEM_CURRENT_TIME: {
getter: (state) => {
return state._activeAudioKey !== undefined
Expand Down
4 changes: 4 additions & 0 deletions src/store/type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,10 @@ export type AudioStoreTypes = {
getter(audioKey: AudioKey): boolean;
};

NOW_PLAYING: {
getter: boolean;
};
Comment on lines +155 to +157
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(すみません、レビューしたタイミングでちょうどgithubに障害が起きてレビューが反映できていませんでした・・・。)

ここはIS_PLAYINGよりNOW_PLAYINGのがあってそうに思いました!

isなんとかは動詞なのでメソッド名や関数名になることが多そうです。
実際この上にあるIS_ACTIVEは引数を受け取るメソッドライクになっていそうです。


ACTIVE_AUDIO_ELEM_CURRENT_TIME: {
getter: number | undefined;
};
Expand Down