From aff3e9ac80134a8c5f0c5be8063fb28ecb549e65 Mon Sep 17 00:00:00 2001 From: invpt <57822954+invpt@users.noreply.github.com> Date: Sat, 22 Jun 2024 19:09:32 -0400 Subject: [PATCH] Fix dumb problem --- src/components/Asset.tsx | 36 +++++++++++++++------------ src/components/Gallery.tsx | 4 ++- src/pages/project/TourEditorPanel.tsx | 2 +- 3 files changed, 24 insertions(+), 18 deletions(-) diff --git a/src/components/Asset.tsx b/src/components/Asset.tsx index 61a7538..e701865 100644 --- a/src/components/Asset.tsx +++ b/src/components/Asset.tsx @@ -1,5 +1,5 @@ import { FiArrowDown, FiArrowUp, FiImage, FiMap, FiMic, FiTrash, FiUpload } from "solid-icons/fi"; -import { type Component, createSignal, createUniqueId, For, type JSX, Show } from "solid-js"; +import { type Component, createSignal, createUniqueId, For, type JSX, Show, createEffect } from "solid-js"; import { useDB } from "../db"; import { useProject } from "../hooks/Project"; @@ -11,6 +11,7 @@ import styles from "./Asset.module.css"; export const Asset: Component<{ id?: string, type: AssetType, + assetIdentity?: string, asset: string | undefined, onIdChange: (newId: string) => void, onDeleteClick?: () => void, @@ -28,23 +29,26 @@ export const Asset: Component<{ const assets = () => Object.keys(project()?.assets ?? {}).filter(a => project()?.assets[a]?.type === props.type); - let initialQuery: string; - if (project() != null && props.asset != null) { - // If the project is accessible when the component is constructed, - // we can make sure the initial query only contains props.asset if - // props.asset is actually a valid asset. This is useful behavior - // in the case that an asset is deleted, because it makes the asset - // field blank when it references an invalid (deleted) asset. - if (assets().includes(props.asset)) { - initialQuery = props.asset; + const [query, setQuery] = createSignal(""); + + createEffect(() => { + ((_) => {})(props.assetIdentity); + + if (project() != null && props.asset != null) { + // If the project is accessible when the component is constructed, + // we can make sure the initial query only contains props.asset if + // props.asset is actually a valid asset. This is useful behavior + // in the case that an asset is deleted, because it makes the asset + // field blank when it references an invalid (deleted) asset. + if (assets().includes(props.asset)) { + setQuery(props.asset); + } else { + setQuery(""); + } } else { - initialQuery = ""; + setQuery(props.asset ?? ""); } - } else { - initialQuery = props.asset ?? ""; - } - - const [query, setQuery] = createSignal(initialQuery); + }); const handleQueryInput: JSX.EventHandlerUnion = async (event) => { const newQuery = event.currentTarget.value; diff --git a/src/components/Gallery.tsx b/src/components/Gallery.tsx index 4e9e9c0..69e6a1d 100644 --- a/src/components/Gallery.tsx +++ b/src/components/Gallery.tsx @@ -6,7 +6,8 @@ import { Asset } from "./Asset"; import styles from "./Gallery.module.css"; export const Gallery: Component<{ - id?: string | undefined, + id?: string, + valueIdentity?: string, value: GalleryModel, onChange: (newValue: GalleryModel) => void, }> = (props) => { @@ -41,6 +42,7 @@ export const Gallery: Component<{ {(asset, i) => ( }> = (props) {(id) => ( - + )}