diff --git a/package-lock.json b/package-lock.json index 6448071f..defec8e5 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1953,6 +1953,11 @@ "integrity": "sha1-R+Y/evVa+m+S4VAOaQ64uFKcCZo=", "dev": true }, + "jotai": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/jotai/-/jotai-1.0.0.tgz", + "integrity": "sha512-6hZGy3hqIlBlLSKppTrxDc1Vb7mi3I8eEQOIu7Kj6ceX1PSzjxdsEVC9TjAqaio8gZJEz+2ufNUf4afvbs0RXg==" + }, "js-tokens": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/js-tokens/-/js-tokens-4.0.0.tgz", @@ -2802,11 +2807,6 @@ "util-deprecate": "^1.0.1" } }, - "recoil": { - "version": "0.0.13", - "resolved": "https://registry.npmjs.org/recoil/-/recoil-0.0.13.tgz", - "integrity": "sha512-2OToaQ8GR//KsdKdaEhMi04QKStLGRpk3qjC58iBpZpUtsByZ4dUy2UJtRcYuhnVlltGZ8HNwcEQRdFOS864SQ==" - }, "reference-spec-reader": { "version": "0.1.1", "resolved": "https://registry.npmjs.org/reference-spec-reader/-/reference-spec-reader-0.1.1.tgz", diff --git a/package.json b/package.json index f314f8fe..75f96604 100644 --- a/package.json +++ b/package.json @@ -7,10 +7,10 @@ "@material-ui/icons": "^4.9.1", "deck.gl": "^8.4.3", "imjoy-rpc": "^0.2.23", + "jotai": "^1.0.0", "p-map": "^4.0.0", "react": "^17.0.1", "react-dom": "^17.0.1", - "recoil": "0.0.13", "reference-spec-reader": "^0.1.1", "zarr": "^0.4.0" }, diff --git a/snowpack.config.js b/snowpack.config.js index 8ae2528a..29b8cf3e 100644 --- a/snowpack.config.js +++ b/snowpack.config.js @@ -1,9 +1,9 @@ -/** @type {import("snowpack").SnowpackUserConfig } */ const pkg = require('./package.json'); // pkg version avaiable in app via import.meta.env.SNOWPACK_PUBLIC_PACKAGE_VERSION process.env.SNOWPACK_PUBLIC_PACKAGE_VERSION = pkg.version; +/** @type {import("snowpack").SnowpackUserConfig } */ module.exports = { mount: { public: '/', diff --git a/src/components/LayerController/AcquisitionController.tsx b/src/components/LayerController/AcquisitionController.tsx index ce11f282..ee7eb8a0 100644 --- a/src/components/LayerController/AcquisitionController.tsx +++ b/src/components/LayerController/AcquisitionController.tsx @@ -1,13 +1,12 @@ import React from 'react'; import { Grid, NativeSelect } from '@material-ui/core'; -import { useRecoilValue } from 'recoil'; +import { useAtomValue } from 'jotai/utils'; import type { ChangeEvent } from 'react'; +import type { ControllerProps } from '../../state'; -import { sourceInfoState } from '../../state'; - -function AcquisitionController({ layerId }: { layerId: string }): JSX.Element | null { - const sourceInfo = useRecoilValue(sourceInfoState); - const { acquisitionId, acquisitions } = sourceInfo[layerId]; +function AcquisitionController({ sourceAtom }: ControllerProps) { + const sourceData = useAtomValue(sourceAtom); + const { acquisitionId, acquisitions } = sourceData; if (!acquisitions) { return null; diff --git a/src/components/LayerController/AddChannelButton.tsx b/src/components/LayerController/AddChannelButton.tsx index 22502bf9..2d1018bb 100644 --- a/src/components/LayerController/AddChannelButton.tsx +++ b/src/components/LayerController/AddChannelButton.tsx @@ -1,17 +1,17 @@ import React, { useState } from 'react'; import type { MouseEvent, ChangeEvent } from 'react'; -import { useRecoilState, useRecoilValue } from 'recoil'; +import { useAtom } from 'jotai'; +import { useAtomValue } from 'jotai/utils'; import { IconButton, Popover, Paper, Typography, Divider, NativeSelect } from '@material-ui/core'; import { Add } from '@material-ui/icons'; -import { layerStateFamily, sourceInfoState } from '../../state'; import { hexToRGB, MAX_CHANNELS } from '../../utils'; +import type { ControllerProps } from '../../state'; -function AddChannelButton({ layerId }: { layerId: string }): JSX.Element { - const sourceInfo = useRecoilValue(sourceInfoState); - const [layer, setLayer] = useRecoilState(layerStateFamily(layerId)); +function AddChannelButton({ sourceAtom, layerAtom }: ControllerProps) { + const sourceData = useAtomValue(sourceAtom); + const [layer, setLayer] = useAtom(layerAtom); const [anchorEl, setAnchorEl] = useState(null); - const layerInfo = sourceInfo[layerId]; const handleClick = (event: MouseEvent) => { setAnchorEl(event.currentTarget); @@ -27,7 +27,7 @@ function AddChannelButton({ layerId }: { layerId: string }): JSX.Element { channel_axis, colors, contrast_limits, - } = layerInfo; + } = sourceData; handleClose(); const channelIndex = +event.target.value; const channelSelection = [...selection]; @@ -55,9 +55,9 @@ function AddChannelButton({ layerId }: { layerId: string }): JSX.Element { }); }; - const { names } = sourceInfo[layerId]; + const { names } = sourceData; const open = Boolean(anchorEl); - const id = open ? `layer-${layerId}-add-channel` : undefined; + const id = open ? `layer-${sourceData.id}-add-channel` : undefined; return ( <>