[Perf/bugfix] Separate custom hooks and prevent re-render issues.

Config Page: Device Tab. threshold component. fix problem that the input component focused out when input something each time.
Set threshold data when started python.
This commit is contained in:
Sakamoto Shiina
2024-09-10 17:21:03 +09:00
parent 37989d5f7a
commit ac6b898a46
23 changed files with 514 additions and 443 deletions

View File

@@ -7,7 +7,7 @@ import {
useForegroundStatus,
} from "@store";
import { useStdoutToPython } from "./useStdoutToPython";
import { useStdoutToPython } from "@logics/useStdoutToPython";
export const useMainFunction = () => {
const {
@@ -33,53 +33,56 @@ export const useMainFunction = () => {
const { asyncStdoutToPython } = useStdoutToPython();
const asyncPending = () => new Promise(() => {});
const toggleTranslation = () => {
asyncUpdateTranslationStatus(asyncPending);
if (currentTranslationStatus.data) {
asyncStdoutToPython("/controller/callback_disable_translation");
} else {
asyncStdoutToPython("/controller/callback_enable_translation");
}
};
const toggleTranscriptionSend = () => {
asyncUpdateTranscriptionSendStatus(asyncPending);
if (currentTranscriptionSendStatus.data) {
asyncStdoutToPython("/controller/callback_disable_transcription_send");
} else {
asyncStdoutToPython("/controller/callback_enable_transcription_send");
}
};
const toggleTranscriptionReceive = () => {
asyncUpdateTranscriptionReceiveStatus(asyncPending);
if (currentTranscriptionReceiveStatus.data) {
asyncStdoutToPython("/controller/callback_disable_transcription_receive");
} else {
asyncStdoutToPython("/controller/callback_enable_transcription_receive");
}
};
const toggleForeground = () => {
const main_page = getCurrent();
const is_foreground_enabled = !currentForegroundStatus.data;
main_page.setAlwaysOnTop(is_foreground_enabled);
updateForegroundStatus(is_foreground_enabled);
};
return {
toggleTranslation: () => {
asyncUpdateTranslationStatus(asyncPending);
if (currentTranslationStatus.data) {
asyncStdoutToPython("/controller/callback_disable_translation");
} else {
asyncStdoutToPython("/controller/callback_enable_translation");
}
},
currentTranslationStatus: currentTranslationStatus,
updateTranslationStatus: (payload) => {
updateTranslationStatus(payload.data);
},
currentTranslationStatus,
toggleTranslation,
updateTranslationStatus,
toggleTranscriptionSend: () => {
asyncUpdateTranscriptionSendStatus(asyncPending);
if (currentTranscriptionSendStatus.data) {
asyncStdoutToPython("/controller/callback_disable_transcription_send");
} else {
asyncStdoutToPython("/controller/callback_enable_transcription_send");
}
},
currentTranscriptionSendStatus: currentTranscriptionSendStatus,
updateTranscriptionSendStatus: (payload) => {
updateTranscriptionSendStatus(payload.data);
},
currentTranscriptionSendStatus,
toggleTranscriptionSend,
updateTranscriptionSendStatus,
toggleTranscriptionReceive: () => {
asyncUpdateTranscriptionReceiveStatus(asyncPending);
if (currentTranscriptionReceiveStatus.data) {
asyncStdoutToPython("/controller/callback_disable_transcription_receive");
} else {
asyncStdoutToPython("/controller/callback_enable_transcription_receive");
}
},
currentTranscriptionReceiveStatus: currentTranscriptionReceiveStatus,
updateTranscriptionReceiveStatus: (payload) => {
updateTranscriptionReceiveStatus(payload.data);
},
currentTranscriptionReceiveStatus,
toggleTranscriptionReceive,
updateTranscriptionReceiveStatus,
toggleForeground: () => {
const main_page = getCurrent();
const is_foreground_enabled = !currentForegroundStatus.data;
main_page.setAlwaysOnTop(is_foreground_enabled);
updateForegroundStatus(is_foreground_enabled);
currentForegroundStatus,
toggleForeground,
updateForegroundStatus,
},
currentForegroundStatus: currentForegroundStatus,
};
};