model name dialog

This commit is contained in:
wataru 2023-06-10 16:46:43 +09:00
parent c273a40f44
commit 012b6a76a9
7 changed files with 170 additions and 8 deletions

File diff suppressed because one or more lines are too long

View File

@ -19,6 +19,7 @@ export const OpenModelSlotManagerDialogCheckbox = "open-model-slot-manager-dialo
export const OpenMergeLabDialogCheckbox = "open-merge-lab-dialog-checkbox" export const OpenMergeLabDialogCheckbox = "open-merge-lab-dialog-checkbox"
export const OpenAdvancedSettingDialogCheckbox = "open-advanced-setting-dialog-checkbox" export const OpenAdvancedSettingDialogCheckbox = "open-advanced-setting-dialog-checkbox"
export const OpenTextInputDialogCheckbox = "open-text-input-dialog-checkbox"
type Props = { type Props = {
children: ReactNode; children: ReactNode;
}; };
@ -41,6 +42,7 @@ export type StateControls = {
showMergeLabCheckbox: StateControlCheckbox showMergeLabCheckbox: StateControlCheckbox
showAdvancedSettingCheckbox: StateControlCheckbox showAdvancedSettingCheckbox: StateControlCheckbox
showTextInputCheckbox: StateControlCheckbox
} }
type GuiStateAndMethod = { type GuiStateAndMethod = {
@ -68,6 +70,8 @@ type GuiStateAndMethod = {
modelSlotNum: number modelSlotNum: number
setModelSlotNum: (val: number) => void setModelSlotNum: (val: number) => void
textInputResolve: TextInputResolveType | null
setTextInputResolve: (val: TextInputResolveType | null) => void
} }
const GuiStateContext = React.createContext<GuiStateAndMethod | null>(null); const GuiStateContext = React.createContext<GuiStateAndMethod | null>(null);
@ -79,6 +83,10 @@ export const useGuiState = (): GuiStateAndMethod => {
return state; return state;
}; };
type TextInputResolveType = {
resolve: ((value: string | PromiseLike<string>) => void) | null
}
export const GuiStateProvider = ({ children }: Props) => { export const GuiStateProvider = ({ children }: Props) => {
const { clientType, appGuiSettingState } = useAppRoot() const { clientType, appGuiSettingState } = useAppRoot()
const [isConverting, setIsConverting] = useState<boolean>(false) const [isConverting, setIsConverting] = useState<boolean>(false)
@ -95,6 +103,8 @@ export const GuiStateProvider = ({ children }: Props) => {
const [fileInputEchoback, setFileInputEchoback] = useState<boolean>(false)//最初のmuteが有効になるように。undefined <-- ??? falseしておけばよさそう。undefinedだとwarningがでる。 const [fileInputEchoback, setFileInputEchoback] = useState<boolean>(false)//最初のmuteが有効になるように。undefined <-- ??? falseしておけばよさそう。undefinedだとwarningがでる。
const [audioOutputForAnalyzer, setAudioOutputForAnalyzer] = useState<string>("default") const [audioOutputForAnalyzer, setAudioOutputForAnalyzer] = useState<string>("default")
const [textInputResolve, setTextInputResolve] = useState<TextInputResolveType | null>(null)
const reloadDeviceInfo = async () => { const reloadDeviceInfo = async () => {
try { try {
const ms = await navigator.mediaDevices.getUserMedia({ video: false, audio: true }); const ms = await navigator.mediaDevices.getUserMedia({ video: false, audio: true });
@ -162,6 +172,10 @@ export const GuiStateProvider = ({ children }: Props) => {
const showMergeLabCheckbox = useStateControlCheckbox(OpenMergeLabDialogCheckbox); const showMergeLabCheckbox = useStateControlCheckbox(OpenMergeLabDialogCheckbox);
const showAdvancedSettingCheckbox = useStateControlCheckbox(OpenAdvancedSettingDialogCheckbox); const showAdvancedSettingCheckbox = useStateControlCheckbox(OpenAdvancedSettingDialogCheckbox);
const showTextInputCheckbox = useStateControlCheckbox(OpenTextInputDialogCheckbox);
useEffect(() => { useEffect(() => {
openServerControlCheckbox.updateState(true) openServerControlCheckbox.updateState(true)
openModelSettingCheckbox.updateState(false) openModelSettingCheckbox.updateState(false)
@ -182,6 +196,8 @@ export const GuiStateProvider = ({ children }: Props) => {
showMergeLabCheckbox.updateState(false) showMergeLabCheckbox.updateState(false)
showAdvancedSettingCheckbox.updateState(false) showAdvancedSettingCheckbox.updateState(false)
showTextInputCheckbox.updateState(false)
}, []) }, [])
useEffect(() => { useEffect(() => {
@ -195,6 +211,7 @@ export const GuiStateProvider = ({ children }: Props) => {
document.getElementById("dialog")?.classList.add("dialog-container-show") document.getElementById("dialog")?.classList.add("dialog-container-show")
showStartingNoticeCheckbox.updateState(true) showStartingNoticeCheckbox.updateState(true)
document.getElementById("dialog2")?.classList.add("dialog-container-show")
} }
setTimeout(show) setTimeout(show)
}, [appGuiSettingState.edition]) }, [appGuiSettingState.edition])
@ -222,7 +239,9 @@ export const GuiStateProvider = ({ children }: Props) => {
showModelSlotManagerCheckbox, showModelSlotManagerCheckbox,
showMergeLabCheckbox, showMergeLabCheckbox,
showAdvancedSettingCheckbox showAdvancedSettingCheckbox,
showTextInputCheckbox
}, },
isConverting, isConverting,
@ -250,6 +269,10 @@ export const GuiStateProvider = ({ children }: Props) => {
modelSlotNum, modelSlotNum,
setModelSlotNum, setModelSlotNum,
textInputResolve,
setTextInputResolve
}; };
return <GuiStateContext.Provider value={providerValue}>{children}</GuiStateContext.Provider>; return <GuiStateContext.Provider value={providerValue}>{children}</GuiStateContext.Provider>;
}; };

View File

@ -11,11 +11,13 @@ import { ConverterSetting } from "./700_ConverterSetting";
import { AdvancedSetting } from "./800_AdvancedSetting"; import { AdvancedSetting } from "./800_AdvancedSetting";
import { Lab } from "./a00_Lab"; import { Lab } from "./a00_Lab";
import { ModelSlotControl } from "./b00_ModelSlotControl"; import { ModelSlotControl } from "./b00_ModelSlotControl";
import { Dialogs2 } from "./910_Dialogs2";
export const Demo = () => { export const Demo = () => {
return ( return (
<GuiStateProvider> <GuiStateProvider>
<div className="main-body"> <div className="main-body">
<Dialogs2 />
<Dialogs /> <Dialogs />
<TitleArea /> <TitleArea />
<ModelSlotControl></ModelSlotControl> <ModelSlotControl></ModelSlotControl>

View File

@ -135,12 +135,16 @@ export const ModelSlotManagerDialog = () => {
const nameValueClass = isRegisterd ? "model-slot-detail-row-value-pointable" : "model-slot-detail-row-value" const nameValueClass = isRegisterd ? "model-slot-detail-row-value-pointable" : "model-slot-detail-row-value"
const nameValueAction = isRegisterd ? async (index: number) => { const nameValueAction = isRegisterd ? async (index: number) => {
const name = window.prompt("input new name", ""); const p = new Promise<string>((resolve) => {
if (!name) { guiState.setTextInputResolve({ resolve: resolve })
return })
guiState.stateControls.showTextInputCheckbox.updateState(true)
const text = await p;
if (text.length > 0) {
console.log("input text:", text)
await serverSetting.updateModelInfo(index, "name", text)
} }
await serverSetting.updateModelInfo(index, "name", name)
console.log(name)
} : async (_index: number) => { } } : async (_index: number) => { }
const iconClass = isRegisterd ? "model-slot-icon-pointable" : "model-slot-icon" const iconClass = isRegisterd ? "model-slot-icon-pointable" : "model-slot-icon"
const iconAction = isRegisterd ? async (index: number) => { const iconAction = isRegisterd ? async (index: number) => {

View File

@ -0,0 +1,19 @@
import React from "react";
import { useGuiState } from "./001_GuiStateProvider";
import { TextInputDialog } from "./911_TextInputDialog";
export const Dialogs2 = () => {
const guiState = useGuiState()
const dialogs = (
<div>
{guiState.stateControls.showTextInputCheckbox.trigger}
<div className="dialog-container2" id="dialog2">
{guiState.stateControls.showTextInputCheckbox.trigger}
<TextInputDialog></TextInputDialog>
</div>
</div>
);
return dialogs
}

View File

@ -0,0 +1,56 @@
import React, { useMemo } from "react";
import { useGuiState } from "./001_GuiStateProvider";
export const TextInputDialog = () => {
const guiState = useGuiState()
const dialog = useMemo(() => {
const buttonsRow = (
<div className="body-row split-3-4-3 left-padding-1">
<div className="body-item-text">
</div>
<div className="body-button-container body-button-container-space-around">
<div className="body-button" onClick={() => {
const inputText = document.getElementById("input-text") as HTMLInputElement
const text = inputText.value
inputText.value = ""
if (guiState.textInputResolve) {
guiState.textInputResolve.resolve!(text)
guiState.setTextInputResolve(null)
}
guiState.stateControls.showTextInputCheckbox.updateState(false)
}} >ok</div>
<div className="body-button" onClick={() => {
const inputText = document.getElementById("input-text") as HTMLInputElement
const text = inputText.value
inputText.value = ""
if (guiState.textInputResolve) {
guiState.textInputResolve.resolve!("")
guiState.setTextInputResolve(null)
}
guiState.stateControls.showTextInputCheckbox.updateState(false)
}} >cancel</div>
</div>
<div className="body-item-text"></div>
</div>
)
const textInput = (
<div className="input-text-container">
<div>Input Text: </div>
<input id="input-text" type="text" />
</div>
)
return (
<div className="dialog-frame">
<div className="dialog-title">Input Dialog</div>
<div className="dialog-content">
{textInput}
{buttonsRow}
</div>
</div>
);
}, [guiState.textInputResolve]);
return dialog;
};

View File

@ -682,7 +682,8 @@ body {
} }
/* Dialog */ /* Dialog */
.dialog-container { .dialog-container,
.dialog-container2 {
justify-content: center; justify-content: center;
align-items: center; align-items: center;
position: absolute; position: absolute;
@ -722,6 +723,11 @@ body {
margin-top: 1rem; margin-top: 1rem;
margin-bottom: 1rem; margin-bottom: 1rem;
} }
.input-text-container {
display: flex;
flex-direction: row;
margin: 20px;
}
} }
.dialog-fixed-size-content { .dialog-fixed-size-content {
width: 90%; width: 90%;
@ -902,6 +908,58 @@ body {
} }
} }
.state-control-checkbox:checked ~ .dialog-container2 {
background: rgba(200, 200, 200, 0.4);
animation-name: dialog-show2;
animation-duration: 0.4s;
animation-iteration-count: 1;
animation-fill-mode: forwards;
animation-direction: normal;
}
.state-control-checkbox ~ .dialog-container2 {
background: rgba(100, 100, 100, 0.4);
animation-name: dialog-hide2;
animation-duration: 0.4s;
animation-iteration-count: 1;
animation-fill-mode: forwards;
animation-direction: normal;
}
/* .state-control-checkbox:checked + .dialog-frame {
display: flex;
}
.state-control-checkbox + .dialog-frame {
display: none;
} */
@keyframes dialog-hide2 {
from {
opacity: 1;
z-index: 400;
}
90% {
opacity: 0;
z-index: -1;
}
to {
opacity: 0;
z-index: -1;
}
}
@keyframes dialog-show2 {
from {
opacity: 0;
z-index: -1;
}
10% {
z-index: 400;
}
to {
opacity: 1;
z-index: 400;
}
}
.tooltip-text { .tooltip-text {
display: none; display: none;
position: absolute; position: absolute;