Skip to content

Commit

Permalink
vuexのstoreの呼び出しをリテラル引数からDot記法へ: components/Talk (#2266)
Browse files Browse the repository at this point in the history
* Dialog.ts and ui.ts and ToolBar.vue

* update App.vue

* update TolTip.vue

* update EngineStartupOverlay.vue

* update AccentPhrase.vue

* update AudioCell.vue

* update AudioDetail.vue

* update menuBarData.ts

* update TalkEditor.vue
  • Loading branch information
Segu-g committed Sep 11, 2024
1 parent 051c6f9 commit dbbfa34
Show file tree
Hide file tree
Showing 11 changed files with 117 additions and 122 deletions.
18 changes: 9 additions & 9 deletions src/components/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -92,13 +92,13 @@ onMounted(async () => {
const queryString = window.location.search;
const urlParams = new URLSearchParams(queryString);
await store.dispatch("INIT_VUEX");
await store.actions.INIT_VUEX();
// プロジェクトファイルのパスを取得
const projectFilePath = urlParams.get("projectFilePath");
// どちらのエディタを開くか設定
await store.dispatch("SET_OPENED_EDITOR", { editor: "talk" });
await store.actions.SET_OPENED_EDITOR({ editor: "talk" });
// ショートカットキーの設定を登録
const hotkeySettings = store.state.hotkeySettings;
Expand All @@ -107,11 +107,11 @@ onMounted(async () => {
// エンジンの初期化開始
// エンジン情報取得
await store.dispatch("GET_ENGINE_INFOS");
await store.actions.GET_ENGINE_INFOS();
// URLパラメータに従ってマルチエンジンをオフにする
const isMultiEngineOffMode = urlParams.get("isMultiEngineOffMode") === "true";
void store.dispatch("SET_IS_MULTI_ENGINE_OFF_MODE", isMultiEngineOffMode);
void store.actions.SET_IS_MULTI_ENGINE_OFF_MODE(isMultiEngineOffMode);
// マルチエンジンオフモードのときはデフォルトエンジンだけにする
let engineIds: EngineId[];
Expand All @@ -126,18 +126,18 @@ onMounted(async () => {
} else {
engineIds = store.state.engineIds;
}
await store.dispatch("LOAD_USER_CHARACTER_ORDER");
await store.dispatch("POST_ENGINE_START", {
await store.actions.LOAD_USER_CHARACTER_ORDER();
await store.actions.POST_ENGINE_START({
engineIds,
});
// 辞書を同期
await store.dispatch("SYNC_ALL_USER_DICT");
await store.actions.SYNC_ALL_USER_DICT();
isEnginesReady.value = true;
// エンジン起動後にダイアログを開く
void store.dispatch("SET_DIALOG_OPEN", {
void store.actions.SET_DIALOG_OPEN({
isAcceptRetrieveTelemetryDialogOpen:
store.state.acceptRetrieveTelemetry === "Unconfirmed",
isAcceptTermsDialogOpen:
Expand All @@ -147,7 +147,7 @@ onMounted(async () => {
// プロジェクトファイルが指定されていればロード
if (typeof projectFilePath === "string" && projectFilePath !== "") {
isProjectFileLoaded.value = await store.dispatch("LOAD_PROJECT_FILE", {
isProjectFileLoaded.value = await store.actions.LOAD_PROJECT_FILE({
filePath: projectFilePath,
});
} else {
Expand Down
72 changes: 36 additions & 36 deletions src/components/Dialog/Dialog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import {
SaveResult,
ErrorTypeForSaveAllResultDialog,
} from "@/store/type";
import { Dispatch } from "@/store/vuex";
import { withProgress } from "@/store/ui";
import { DotNotationDispatch } from "@/store/vuex";
import { withProgressDotNotation as withProgress } from "@/store/ui";

type MediaType = "audio" | "text";

Expand Down Expand Up @@ -143,21 +143,21 @@ const setCommonDialogCallback = (

export async function generateAndSaveOneAudioWithDialog({
audioKey,
dispatch,
actions,
filePath,
disableNotifyOnGenerate,
}: {
audioKey: AudioKey;
dispatch: Dispatch<AllActions>;
actions: DotNotationDispatch<AllActions>;
filePath?: string;
disableNotifyOnGenerate: boolean;
}): Promise<void> {
const result: SaveResultObject = await withProgress(
dispatch("GENERATE_AND_SAVE_AUDIO", {
actions.GENERATE_AND_SAVE_AUDIO({
audioKey,
filePath,
}),
dispatch,
actions,
);

if (result.result === "CANCELED") return;
Expand All @@ -167,35 +167,35 @@ export async function generateAndSaveOneAudioWithDialog({
// 書き出し成功時に通知をする
showWriteSuccessNotify({
mediaType: "audio",
dispatch,
actions,
});
} else {
showWriteErrorDialog({ mediaType: "audio", result, dispatch });
showWriteErrorDialog({ mediaType: "audio", result, actions });
}
}

export async function multiGenerateAndSaveAudioWithDialog({
audioKeys,
dispatch,
actions,
dirPath,
disableNotifyOnGenerate,
}: {
audioKeys: AudioKey[];
dispatch: Dispatch<AllActions>;
actions: DotNotationDispatch<AllActions>;
dirPath?: string;
disableNotifyOnGenerate: boolean;
}): Promise<void> {
const result = await withProgress(
dispatch("MULTI_GENERATE_AND_SAVE_AUDIO", {
actions.MULTI_GENERATE_AND_SAVE_AUDIO({
audioKeys,
dirPath,
callback: (finishedCount) =>
dispatch("SET_PROGRESS_FROM_COUNT", {
actions.SET_PROGRESS_FROM_COUNT({
finishedCount,
totalCount: audioKeys.length,
}),
}),
dispatch,
actions,
);

if (result == undefined) return;
Expand Down Expand Up @@ -226,7 +226,7 @@ export async function multiGenerateAndSaveAudioWithDialog({
// 書き出し成功時に通知をする
showWriteSuccessNotify({
mediaType: "audio",
dispatch,
actions,
});
}

Expand All @@ -243,21 +243,21 @@ export async function multiGenerateAndSaveAudioWithDialog({
}

export async function generateAndConnectAndSaveAudioWithDialog({
dispatch,
actions,
filePath,
disableNotifyOnGenerate,
}: {
dispatch: Dispatch<AllActions>;
actions: DotNotationDispatch<AllActions>;
filePath?: string;
disableNotifyOnGenerate: boolean;
}): Promise<void> {
const result = await withProgress(
dispatch("GENERATE_AND_CONNECT_AND_SAVE_AUDIO", {
actions.GENERATE_AND_CONNECT_AND_SAVE_AUDIO({
filePath,
callback: (finishedCount, totalCount) =>
dispatch("SET_PROGRESS_FROM_COUNT", { finishedCount, totalCount }),
actions.SET_PROGRESS_FROM_COUNT({ finishedCount, totalCount }),
}),
dispatch,
actions,
);

if (result == undefined || result.result === "CANCELED") return;
Expand All @@ -266,23 +266,23 @@ export async function generateAndConnectAndSaveAudioWithDialog({
if (disableNotifyOnGenerate) return;
showWriteSuccessNotify({
mediaType: "audio",
dispatch,
actions,
});
} else {
showWriteErrorDialog({ mediaType: "audio", result, dispatch });
showWriteErrorDialog({ mediaType: "audio", result, actions });
}
}

export async function connectAndExportTextWithDialog({
dispatch,
actions,
filePath,
disableNotifyOnGenerate,
}: {
dispatch: Dispatch<AllActions>;
actions: DotNotationDispatch<AllActions>;
filePath?: string;
disableNotifyOnGenerate: boolean;
}): Promise<void> {
const result = await dispatch("CONNECT_AND_EXPORT_TEXT", {
const result = await actions.CONNECT_AND_EXPORT_TEXT({
filePath,
});

Expand All @@ -292,26 +292,26 @@ export async function connectAndExportTextWithDialog({
if (disableNotifyOnGenerate) return;
showWriteSuccessNotify({
mediaType: "text",
dispatch,
actions,
});
} else {
showWriteErrorDialog({ mediaType: "text", result, dispatch });
showWriteErrorDialog({ mediaType: "text", result, actions });
}
}

// 書き出し成功時の通知を表示
const showWriteSuccessNotify = ({
mediaType,
dispatch,
actions,
}: {
mediaType: MediaType;
dispatch: Dispatch<AllActions>;
actions: DotNotationDispatch<AllActions>;
}): void => {
const mediaTypeNames: Record<MediaType, string> = {
audio: "音声",
text: "テキスト",
};
void dispatch("SHOW_NOTIFY_AND_NOT_SHOW_AGAIN_BUTTON", {
void actions.SHOW_NOTIFY_AND_NOT_SHOW_AGAIN_BUTTON({
message: `${mediaTypeNames[mediaType]}を書き出しました`,
tipName: "notifyOnGenerate",
});
Expand All @@ -321,15 +321,15 @@ const showWriteSuccessNotify = ({
const showWriteErrorDialog = ({
mediaType,
result,
dispatch,
actions,
}: {
mediaType: MediaType;
result: SaveResultObject;
dispatch: Dispatch<AllActions>;
actions: DotNotationDispatch<AllActions>;
}) => {
if (mediaType === "text") {
// テキスト書き出し時のエラーを出力
void dispatch("SHOW_ALERT_DIALOG", {
void actions.SHOW_ALERT_DIALOG({
title: "テキストの書き出しに失敗しました。",
message:
"書き込みエラーによって失敗しました。空き容量があることや、書き込み権限があることをご確認ください。",
Expand All @@ -345,7 +345,7 @@ const showWriteErrorDialog = ({
};

// 音声書き出し時のエラーを出力
void dispatch("SHOW_ALERT_DIALOG", {
void actions.SHOW_ALERT_DIALOG({
title: "書き出しに失敗しました。",
message: result.errorMessage ?? defaultErrorMessages[result.result] ?? "",
});
Expand All @@ -356,9 +356,9 @@ const NOTIFY_TIMEOUT = 7000;

export const showNotifyAndNotShowAgainButton = (
{
dispatch,
actions,
}: {
dispatch: Dispatch<AllActions>;
actions: DotNotationDispatch<AllActions>;
},
options: NotifyAndNotShowAgainButtonOption,
) => {
Expand All @@ -376,7 +376,7 @@ export const showNotifyAndNotShowAgainButton = (
label: "今後このメッセージを表示しない",
textColor: "toast-button-display" + suffix,
handler: () => {
void dispatch("SET_CONFIRMED_TIP", {
void actions.SET_CONFIRMED_TIP({
confirmedTip: {
[options.tipName]: true,
},
Expand Down
2 changes: 1 addition & 1 deletion src/components/EngineStartupOverlay.vue
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ watch(allEngineState, (newEngineState) => {
});
const reloadAppWithMultiEngineOffMode = () => {
void store.dispatch("CHECK_EDITED_AND_NOT_SAVE", {
void store.actions.CHECK_EDITED_AND_NOT_SAVE({
closeOrReload: "reload",
isMultiEngineOffMode: true,
});
Expand Down
12 changes: 6 additions & 6 deletions src/components/Talk/AccentPhrase.vue
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ const contextMenudata = ref<[MenuItemButton]>([
type: "button",
label: "削除",
onClick: () => {
void store.dispatch("COMMAND_DELETE_ACCENT_PHRASE", {
void store.actions.COMMAND_DELETE_ACCENT_PHRASE({
audioKey: props.audioKey,
accentPhraseIndex: props.index,
});
Expand Down Expand Up @@ -278,7 +278,7 @@ const handleChangePronounce = (newPronunciation: string) => {
popUntilPause = true;
}
}
void store.dispatch("COMMAND_CHANGE_SINGLE_ACCENT_PHRASE", {
void store.actions.COMMAND_CHANGE_SINGLE_ACCENT_PHRASE({
audioKey: props.audioKey,
newPronunciation,
accentPhraseIndex: props.index,
Expand Down Expand Up @@ -345,13 +345,13 @@ const getHoveredText = (mora: Mora, moraIndex: number) => {
};
const changeAccent = (accentPhraseIndex: number, accent: number) =>
store.dispatch("COMMAND_CHANGE_ACCENT", {
store.actions.COMMAND_CHANGE_ACCENT({
audioKey: props.audioKey,
accentPhraseIndex,
accent,
});
const toggleAccentPhraseSplit = (isPause: boolean, moraIndex?: number) => {
void store.dispatch("COMMAND_CHANGE_ACCENT_PHRASE_SPLIT", {
void store.actions.COMMAND_CHANGE_ACCENT_PHRASE_SPLIT({
audioKey: props.audioKey,
accentPhraseIndex: props.index,
...(!isPause ? { isPause, moraIndex: moraIndex as number } : { isPause }),
Expand All @@ -376,15 +376,15 @@ const changeMoraData = (
if (type == "pitch") {
lastPitches.value[moraIndex] = data;
}
return store.dispatch("COMMAND_SET_AUDIO_MORA_DATA", {
return store.actions.COMMAND_SET_AUDIO_MORA_DATA({
audioKey: props.audioKey,
accentPhraseIndex,
moraIndex,
data,
type,
});
} else {
return store.dispatch("COMMAND_SET_AUDIO_MORA_DATA_ACCENT_PHRASE", {
return store.actions.COMMAND_SET_AUDIO_MORA_DATA_ACCENT_PHRASE({
audioKey: props.audioKey,
accentPhraseIndex,
moraIndex,
Expand Down
Loading

0 comments on commit dbbfa34

Please sign in to comment.