feat: change objects to instances passed to remotes service

This commit is contained in:
Fritz Heiden 2025-04-10 20:02:10 +02:00
parent 7a20ae1536
commit 318185bd4a
4 changed files with 32 additions and 26 deletions

View File

@ -2,7 +2,13 @@ import { createSignal, mergeProps } from "solid-js";
function ValidatedTextInput(props) {
props = mergeProps(
{ type: "text", valid: true, onInput: () => {}, errorText: "" },
{
type: "text",
valid: true,
onInput: () => {},
errorText: "",
placeholder: "",
},
props
);
let [isActive, setActive] = createSignal(false);
@ -15,6 +21,7 @@ function ValidatedTextInput(props) {
}
id={props.id}
value={props.value}
placeholder={props.placeholder}
onInput={props.onInput}
onFocusOut={() => setActive(true)}
/>

View File

@ -26,14 +26,6 @@ function CreateCommandModal(props) {
const isCommandTypeValid = createMemo(() => commandType() !== "");
const isTitleValid = createMemo(() => title().length >= MIN_TITLE_LENGTH);
createEffect(() => {
let commandString = commandType()
? Command.CommandTypes[commandType()]
: "";
let protocolString = protocol() ? Command.Protocols[protocol()] : "";
setTitle(commandString + " " + protocolString);
});
const isFormValid = createMemo(
() =>
isProtocolValid() &&
@ -46,13 +38,15 @@ function CreateCommandModal(props) {
async function handleCreateCommand() {
let command;
try {
command = await RemotesService.createCommand({
protocol: protocol(),
commandNumber: commandNumber(),
device: device(),
commandType: commandType(),
title: title(),
});
command = await RemotesService.createCommand(
new Command({
protocol: protocol(),
commandNumber: commandNumber(),
device: device(),
commandType: commandType(),
title: title(),
})
);
} catch (e) {
setError(e.message);
return;
@ -93,7 +87,9 @@ function CreateCommandModal(props) {
class="form-select"
onChange={(e) => setProtocol(e.target.value)}
>
<option value="" selected>Please select</option>
<option value="" selected>
Please select
</option>
{Object.keys(Command.Protocols).map((protocol) => (
<option value={protocol}>{Command.Protocols[protocol]}</option>
))}
@ -138,7 +134,9 @@ function CreateCommandModal(props) {
class="form-select"
onChange={(e) => setCommandType(e.target.value)}
>
<option value="" selected>Please select</option>
<option value="" selected>
Please select
</option>
{Object.keys(Command.CommandTypes).map((commandType) => (
<option value={commandType}>
{Command.CommandTypes[commandType]}

View File

@ -5,6 +5,7 @@ import EventEmitter from "../tools/event-emitter.js";
import ModalHandler from "./modal-handler.js";
import Modal from "./modal.jsx";
import ListManager from "../components/list-manager.jsx";
import Remote from "../data/remote.js";
const eventEmitter = new EventEmitter();
const REMOTE_CREATED_EVENT = "success";
@ -28,10 +29,12 @@ function CreateRemoteModal(props) {
async function handleCreateRemote() {
let remote;
try {
remote = await RemotesService.createRemote({
title: title(),
commands: commands(),
});
remote = await RemotesService.createRemote(
new Remote({
title: title(),
commands: commands(),
})
);
} catch (e) {
setError(e.message);
return;

View File

@ -34,8 +34,7 @@ function RemotesService() {
return [].concat(remotes);
}
async function createRemote(remoteObject) {
let remote = Serializer.deserializeRemote(remoteObject);
async function createRemote(remote) {
let id = Math.random().toString(36).substr(2, 9);
remote.setId(id);
remotes.push(remote);
@ -53,8 +52,7 @@ function RemotesService() {
return [].concat(_commands);
}
async function createCommand(commandObject) {
let command = Serializer.deserializeCommand(commandObject);
async function createCommand(command) {
let id = Math.random().toString(36).substr(2, 9);
command.setId(id);
_commands.push(command);