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

複数選択:複数削除を追加 #1656

Merged
merged 7 commits into from
Nov 23, 2023
Merged
Show file tree
Hide file tree
Changes from 6 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
61 changes: 47 additions & 14 deletions src/components/AudioCell.vue
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@
文章が長いと正常に動作しない可能性があります。
句読点の位置で文章を分割してください。
</template>
<template v-if="deleteButtonEnable" #after>
<template v-if="enableDeleteButton" #after>
<q-btn
round
flat
Expand Down Expand Up @@ -436,33 +436,66 @@ const moveDownCell = moveCell(1);
// 消去
const willRemove = ref(false);
const removeCell = async () => {
// 1つだけの時は削除せず
if (audioKeys.value.length > 1) {
let audioKeysToDelete: AudioKey[];
if (
isMultiSelectEnabled.value &&
store.getters.SELECTED_AUDIO_KEYS.includes(props.audioKey)
) {
audioKeysToDelete = store.getters.SELECTED_AUDIO_KEYS;
} else {
audioKeysToDelete = [props.audioKey];
}
// 全て消える場合はなにもしない
if (audioKeys.value.length > audioKeysToDelete.length) {
// フォーカスを外したりREMOVEしたりすると、
// テキストフィールドのchangeイベントが非同期に飛んでundefinedエラーになる
// エラー防止のためにまずwillRemoveフラグを建てる
willRemove.value = true;

const index = audioKeys.value.indexOf(props.audioKey);
if (index > 0) {
emit("focusCell", {
audioKey: audioKeys.value[index - 1],
});
} else {
if (audioKeysToDelete.includes(props.audioKey)) {
// 選択するAudioKeyを決定する。
// - 削除ボタンが押されたAudioCellから開始
// - 残るAudioCellを上方向に探す
// - 上方向になかったら下方向に探す
// - なかったらエラー(Unreachable)
const audioKeyIndex = audioKeys.value.indexOf(props.audioKey);
let willNextFocusIndex = -1;
for (let i = audioKeyIndex; i >= 0; i--) {
if (!audioKeysToDelete.includes(audioKeys.value[i])) {
willNextFocusIndex = i;
break;
}
}
if (willNextFocusIndex === -1) {
for (let i = audioKeyIndex; i < audioKeys.value.length; i++) {
if (!audioKeysToDelete.includes(audioKeys.value[i])) {
willNextFocusIndex = i;
break;
}
}
}
if (willNextFocusIndex === -1) {
throw new Error(
"次に選択するaudioKeyが見付かりませんでした(unreachable)"
);
}
emit("focusCell", {
audioKey: audioKeys.value[index + 1],
audioKey: audioKeys.value[willNextFocusIndex],
});
}

store.dispatch("COMMAND_REMOVE_AUDIO_ITEM", {
audioKey: props.audioKey,
store.dispatch("COMMAND_MULTI_REMOVE_AUDIO_ITEM", {
audioKeys: audioKeysToDelete,
});
}
};

// 削除ボタンの有効/無効判定
const deleteButtonEnable = computed(() => {
return 1 < audioKeys.value.length;
const enableDeleteButton = computed(() => {
return (
store.state.audioKeys.length >
(isMultiSelectEnabled.value ? store.getters.SELECTED_AUDIO_KEYS.length : 1)
);
});

// テキスト編集エリアの右クリック
Expand Down
14 changes: 8 additions & 6 deletions src/store/audio.ts
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ export const audioStoreState: AudioStoreState = {
export const audioStore = createPartialStore<AudioStoreTypes>({
ACTIVE_AUDIO_KEY: {
getter(state) {
return state._activeAudioKey !== undefined &&
return state._activeAudioKey != undefined &&
state.audioKeys.includes(state._activeAudioKey)
? state._activeAudioKey
: undefined;
Expand Down Expand Up @@ -1883,12 +1883,14 @@ export const audioCommandStore = transformCommandStore(
},
},

COMMAND_REMOVE_AUDIO_ITEM: {
mutation(draft, payload: { audioKey: AudioKey }) {
audioStore.mutations.REMOVE_AUDIO_ITEM(draft, payload);
COMMAND_MULTI_REMOVE_AUDIO_ITEM: {
mutation(draft, { audioKeys }: { audioKeys: AudioKey[] }) {
for (const audioKey of audioKeys) {
audioStore.mutations.REMOVE_AUDIO_ITEM(draft, { audioKey });
}
},
action({ commit }, payload: { audioKey: AudioKey }) {
commit("COMMAND_REMOVE_AUDIO_ITEM", payload);
action({ commit }, payload: { audioKeys: AudioKey[] }) {
commit("COMMAND_MULTI_REMOVE_AUDIO_ITEM", payload);
},
},

Expand Down
6 changes: 3 additions & 3 deletions src/store/type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -478,9 +478,9 @@ export type AudioCommandStoreTypes = {
}): Promise<AudioKey>;
};

COMMAND_REMOVE_AUDIO_ITEM: {
mutation: { audioKey: AudioKey };
action(payload: { audioKey: AudioKey }): void;
COMMAND_MULTI_REMOVE_AUDIO_ITEM: {
mutation: { audioKeys: AudioKey[] };
action(payload: { audioKeys: AudioKey[] }): void;
};

COMMAND_SET_AUDIO_KEYS: {
Expand Down