Skip to content

Commit

Permalink
Fix dumb problem
Browse files Browse the repository at this point in the history
  • Loading branch information
invpt committed Jun 22, 2024
1 parent 3a3f362 commit aff3e9a
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 18 deletions.
36 changes: 20 additions & 16 deletions src/components/Asset.tsx
Original file line number Diff line number Diff line change
@@ -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";
Expand All @@ -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,
Expand All @@ -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<HTMLInputElement, InputEvent> = async (event) => {
const newQuery = event.currentTarget.value;
Expand Down
4 changes: 3 additions & 1 deletion src/components/Gallery.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down Expand Up @@ -41,6 +42,7 @@ export const Gallery: Component<{
<Index each={props.value}>
{(asset, i) => (
<Asset
assetIdentity={props.valueIdentity}
asset={asset()}
type="image"
onIdChange={handleAssetIdChange(i)}
Expand Down
2 changes: 1 addition & 1 deletion src/pages/project/TourEditorPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ const MainPanel: Component<{ show: boolean, setPanel: Setter<Panel> }> = (props)
</Field>
<Field label="Gallery">
{(id) => (
<Gallery id={id} value={tour()!.gallery} onChange={handleTourGalleryChange} />
<Gallery id={id} valueIdentity={tour()?.id} value={tour()!.gallery} onChange={handleTourGalleryChange} />
)}
</Field>
<header classList={{ [styles.PointsHeader]: true, [styles.Pois]: currentTab() === "pois" }}>
Expand Down

0 comments on commit aff3e9a

Please sign in to comment.