feat: on group preview, prefer objects with previews

feat/type-attributes
Tomáš Mládek 2022-10-21 18:49:08 +02:00
parent b5a46d928f
commit f45adc2880
2 changed files with 26 additions and 6 deletions

View File

@ -7,7 +7,8 @@
import HashBadge from "./HashBadge.svelte"; import HashBadge from "./HashBadge.svelte";
import { API_URL } from "../../lib/api"; import { API_URL } from "../../lib/api";
import { GROUP_TYPE_ADDR } from "upend/constants"; import { GROUP_TYPE_ADDR } from "upend/constants";
import AddModal from "../AddModal.svelte"; import { createEventDispatcher } from "svelte";
const dispatch = createEventDispatcher();
export let address: string; export let address: string;
export let recurse = 3; export let recurse = 3;
@ -24,7 +25,6 @@
$entity?.identify().some((l) => l.endsWith(".avi")); $entity?.identify().some((l) => l.endsWith(".avi"));
$: image = mimeType.startsWith("image"); $: image = mimeType.startsWith("image");
$: text = mimeType.startsWith("text"); $: text = mimeType.startsWith("text");
$: pdf = mimeType.startsWith("application/pdf");
$: model = $: model =
mimeType?.startsWith("model") || mimeType?.startsWith("model") ||
$entity?.identify().some((l) => l.endsWith(".stl")); $entity?.identify().some((l) => l.endsWith(".stl"));
@ -34,16 +34,29 @@
$: group = $entity?.get("IS") == GROUP_TYPE_ADDR; $: group = $entity?.get("IS") == GROUP_TYPE_ADDR;
$: handled = $: handled =
!$entity ||
audio || audio ||
video || video ||
image || image ||
text || text ||
pdf ||
model || model ||
web || web ||
fragment || fragment ||
(group && recurse > 0); (group && recurse > 0);
$: dispatch("handled", handled);
let failedChildren: string[] = [];
$: groupChildren = ($entity?.attr["HAS"] || [])
.map((e) => String(e.value.c))
.filter(
(addr) =>
!failedChildren
.slice(0, ($entity?.attr["HAS"] || []).length - 4)
.includes(addr)
)
.slice(0, 4);
let imageLoaded = null; let imageLoaded = null;
</script> </script>
@ -51,9 +64,15 @@
<div class="preview"> <div class="preview">
{#if group} {#if group}
<ul class="group"> <ul class="group">
{#each $entity.attr["HAS"].slice(0, 4) as child} {#each groupChildren as address (address)}
<li> <li>
<svelte:self address={child.value.c} recurse={recurse - 1} /> <svelte:self
{address}
recurse={recurse - 1}
on:handled={(ev) => {
if (!ev.detail) failedChildren = [...failedChildren, address];
}}
/>
</li> </li>
{/each} {/each}
</ul> </ul>
@ -104,7 +123,7 @@
align-items: center; align-items: center;
flex-direction: column; flex-direction: column;
max-height: 100%; max-height: 100%;
flex-grow: 1; flex-grow: 1;
min-height: 0; min-height: 0;
} }

View File

@ -121,6 +121,7 @@
border-radius: 4px; border-radius: 4px;
padding: 0.25em; padding: 0.25em;
max-height: 420px; max-height: 420px;
overflow: hidden;
} }
.items { .items {