import { createResource, createSignal, mergeProps, onMount, Show, } from "solid-js"; import List from "../components/list"; import CreateDeviceModal from "../modals/create-device-modal"; import DeviceService from "../services/device-service"; import ShowRegistrationCodeModal from "../modals/show-registration-code-modal"; import DeleteIntegrationModal from "../modals/delete-integration-modal"; function DevicesView(props) { props = mergeProps({ onIntegrationClicked: () => {} }, props); const DEVICES_LIST_TYPE = "devices"; const INTEGRATION_LIST_TYPE = "integrations"; const [listType, setListType] = createSignal(INTEGRATION_LIST_TYPE); const [devices, setDevices] = createSignal([]); const [integrations, { refetch: refetchIntegrations }] = createResource( DeviceService.getIntegrations ); CreateDeviceModal.onDeviceCreated(() => { handleRefreshDevices(); }); onMount(() => { handleRefreshDevices(); DeleteIntegrationModal.onIntegrationDeleted(() => { refetchIntegrations(); }); }); function handleNewDevice() { CreateDeviceModal.Handler.show(); } async function handleRefreshDevices() { let devices = await DeviceService.getDevices(); setDevices(devices); } function handleRegisterIntegration() { ShowRegistrationCodeModal.Handler.show(); } function handleDeleteIntegration(integration) { DeleteIntegrationModal.setIntegration(integration); DeleteIntegrationModal.Handler.show(); } function handleIntegrationItemClicked(item) { props.onIntegrationClicked(item.integration); } return (
{}} items={devices().map((device) => ({ id: { html: {device.getId()}, }, name: { text: device.getName(), }, description: { text: device.getDescription(), }, device, }))} class={"flex-fill"} columns={[ { id: "id", name: "id", width: 6, }, { id: "name", name: "Name", width: 10, }, { id: "description", name: "Description", }, ]} > ({ id: { html: {integration.getId()}, }, name: { text: integration.getName(), }, options: { html: ( <> ), }, integration: integration, }))} class={"flex-fill"} columns={[ { id: "id", name: "id", width: 6, }, { id: "name", name: "Name", }, { id: "options", name: "", width: 4, }, ]} >
); } export default DevicesView;