[Refactor] Organize logics files. and change import path as well.
This commit is contained in:
82
src-ui/logics/common/useMessage.js
Normal file
82
src-ui/logics/common/useMessage.js
Normal file
@@ -0,0 +1,82 @@
|
||||
import {
|
||||
useStore_MessageLogs,
|
||||
} from "@store";
|
||||
|
||||
import { useStdoutToPython } from "@logics/useStdoutToPython";
|
||||
|
||||
export const useMessage = () => {
|
||||
const { currentMessageLogs, addMessageLogs, updateMessageLogs } = useStore_MessageLogs();
|
||||
const { asyncStdoutToPython } = useStdoutToPython();
|
||||
|
||||
const sendMessage = (message) => {
|
||||
const uuid = crypto.randomUUID();
|
||||
const send_message_object = {
|
||||
id: uuid,
|
||||
message: message,
|
||||
};
|
||||
asyncStdoutToPython("/run/send_message_box", send_message_object);
|
||||
|
||||
addMessageLogs({
|
||||
id: uuid,
|
||||
category: "sent",
|
||||
status: "pending",
|
||||
created_at: generateTimeData(),
|
||||
messages: {
|
||||
original: message,
|
||||
translated: [],
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
const updateSentMessageLogById = (payload) => {
|
||||
updateMessageLogs(updateItemById(payload.id, payload.translation));
|
||||
};
|
||||
const addSentMessageLog = (payload) => {
|
||||
const message_object = generateMessageObject(payload, "sent");
|
||||
addMessageLogs(message_object);
|
||||
};
|
||||
const addReceivedMessageLog = (payload) => {
|
||||
const message_object = generateMessageObject(payload, "received");
|
||||
addMessageLogs(message_object);
|
||||
};
|
||||
|
||||
return {
|
||||
currentMessageLogs,
|
||||
sendMessage,
|
||||
updateSentMessageLogById,
|
||||
addSentMessageLog,
|
||||
addReceivedMessageLog,
|
||||
};
|
||||
};
|
||||
|
||||
const generateTimeData = () => {
|
||||
const data = new Date().toLocaleTimeString(
|
||||
"ja-JP",
|
||||
{hour12: false, hour: "2-digit", minute: "2-digit"},
|
||||
);
|
||||
return data;
|
||||
};
|
||||
|
||||
const generateMessageObject = (data, category) => {
|
||||
return {
|
||||
id: crypto.randomUUID(),
|
||||
created_at: generateTimeData(),
|
||||
category: category,
|
||||
status: "ok",
|
||||
messages: {
|
||||
original: data.message,
|
||||
translated: data.translation,
|
||||
},
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
const updateItemById = (id, translated_data) => (prev_items) => {
|
||||
return prev_items.map(item => {
|
||||
if (item.id === id) {
|
||||
item.status = "ok";
|
||||
item.messages.translated = translated_data;
|
||||
}
|
||||
return item;
|
||||
});
|
||||
};
|
||||
55
src-ui/logics/common/useVolume.js
Normal file
55
src-ui/logics/common/useVolume.js
Normal file
@@ -0,0 +1,55 @@
|
||||
import {
|
||||
useStore_MicVolume,
|
||||
useStore_SpeakerVolume,
|
||||
useStore_MicThresholdCheckStatus,
|
||||
useStore_SpeakerThresholdCheckStatus,
|
||||
} from "@store";
|
||||
|
||||
import { useStdoutToPython } from "@logics/useStdoutToPython";
|
||||
|
||||
export const useVolume = () => {
|
||||
const { asyncStdoutToPython } = useStdoutToPython();
|
||||
const { updateMicVolume } = useStore_MicVolume();
|
||||
const { updateSpeakerVolume } = useStore_SpeakerVolume();
|
||||
const { currentMicThresholdCheckStatus, updateMicThresholdCheckStatus } = useStore_MicThresholdCheckStatus();
|
||||
const { currentSpeakerThresholdCheckStatus, updateSpeakerThresholdCheckStatus } = useStore_SpeakerThresholdCheckStatus();
|
||||
|
||||
const asyncPending = () => new Promise(() => {});
|
||||
return {
|
||||
volumeCheckStart_Mic: () => {
|
||||
updateMicThresholdCheckStatus(asyncPending);
|
||||
asyncStdoutToPython("/set/enable_check_mic_threshold");
|
||||
},
|
||||
volumeCheckStop_Mic: () => {
|
||||
updateMicThresholdCheckStatus(asyncPending);
|
||||
asyncStdoutToPython("/set/disable_check_mic_threshold");
|
||||
},
|
||||
updateVolumeVariable_Mic: (payload) => {
|
||||
updateMicVolume(payload);
|
||||
},
|
||||
currentMicThresholdCheckStatus: currentMicThresholdCheckStatus,
|
||||
updateMicThresholdCheckStatus: (payload) => {
|
||||
updateMicThresholdCheckStatus(payload);
|
||||
if (payload === false) updateMicVolume("0");
|
||||
},
|
||||
|
||||
volumeCheckStart_Speaker: () => {
|
||||
updateSpeakerVolume("0");
|
||||
updateSpeakerThresholdCheckStatus(asyncPending);
|
||||
asyncStdoutToPython("/set/enable_check_speaker_threshold");
|
||||
},
|
||||
volumeCheckStop_Speaker: () => {
|
||||
updateSpeakerThresholdCheckStatus(asyncPending);
|
||||
asyncStdoutToPython("/set/disable_check_speaker_threshold");
|
||||
},
|
||||
updateVolumeVariable_Speaker: (payload) => {
|
||||
updateSpeakerVolume(payload);
|
||||
},
|
||||
currentSpeakerThresholdCheckStatus: currentSpeakerThresholdCheckStatus,
|
||||
updateSpeakerThresholdCheckStatus: (payload) => {
|
||||
updateSpeakerThresholdCheckStatus(payload);
|
||||
if (payload === false) updateSpeakerVolume("0");
|
||||
}
|
||||
|
||||
};
|
||||
};
|
||||
Reference in New Issue
Block a user