Skip to content

Commit 604a8d4

Browse files
committed
fix: gallery color
1 parent b992eca commit 604a8d4

File tree

2 files changed

+26
-3
lines changed

2 files changed

+26
-3
lines changed

apps/frontend/src/lib/components/blocks/gallery-view/gallery-view-card.svelte

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,19 @@
33
import * as Tooltip from "$lib/components/ui/tooltip"
44
import { ImagesIcon } from "lucide-svelte"
55
6-
import { FieldIdVo, type RecordDO, type AttachmentField, AttachmentFieldValue, type Field } from "@undb/table"
6+
import {
7+
FieldIdVo,
8+
type RecordDO,
9+
type AttachmentField,
10+
AttachmentFieldValue,
11+
type Field,
12+
ViewColor,
13+
} from "@undb/table"
714
import { queryParam } from "sveltekit-search-params"
815
import { getTable } from "$lib/store/table.store"
916
import FieldValue from "../field-value/field-value.svelte"
17+
import { getBgColor } from "../grid-view/grid-view.util"
18+
import { cn } from "$lib/utils"
1019
1120
const table = getTable()
1221
export let record: RecordDO
@@ -21,6 +30,11 @@
2130
let field = $table.schema.getFieldById(new FieldIdVo(fieldId)).into(undefined) as AttachmentField | undefined
2231
$: fieldValues = record.getValue(new FieldIdVo(fieldId)).into(undefined) as AttachmentFieldValue | undefined
2332
$: images = fieldValues?.getImages() ?? []
33+
34+
export let color: ViewColor | undefined
35+
$: colorSpec = color?.getSpec($table.schema).into(undefined)
36+
$: isMatch = colorSpec ? record.match(colorSpec) : false
37+
$: condition = isMatch ? color?.getMatchedFieldConditions($table, record)[0] : undefined
2438
</script>
2539

2640
<div class="group col-span-1 flex flex-col rounded-md border shadow-sm transition-all hover:shadow-lg">
@@ -41,7 +55,13 @@
4155
<ImagesIcon class="text-muted-foreground/50 h-10 w-10" />
4256
</div>
4357
{/if}
44-
<button on:click={() => ($r = record.id.value)} class="flex flex-1 flex-col space-y-2 px-2 py-3">
58+
<button
59+
on:click={() => ($r = record.id.value)}
60+
class={cn("relative flex flex-1 flex-col space-y-2 px-2 py-3", isMatch && "pl-3")}
61+
>
62+
{#if isMatch}
63+
<div class={cn("absolute left-0 top-0 h-full w-1", condition && getBgColor(condition.option.color))}></div>
64+
{/if}
4565
{#each fields.filter((f) => f.id.value !== fieldId) as field}
4666
<div class="flex w-full">
4767
<FieldValue

apps/frontend/src/lib/components/blocks/gallery-view/gallery-view-cards.svelte

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010
export let fieldId: string
1111
const recordsStore = getRecordsStore()
1212
13+
$: view = $table.views.getViewById($viewId)
14+
$: color = view.color.into(undefined)
15+
1316
$: fields = $table.getOrderedVisibleFields($viewId) ?? []
1417
1518
let records = recordsStore.records
@@ -20,7 +23,7 @@
2023
{:else}
2124
<div class="grid w-full flex-1 gap-4 overflow-y-auto sm:grid-cols-2 md:grid-cols-3 xl:grid-cols-5">
2225
{#each $records as record (record.id.value)}
23-
<GalleryViewCard {record} {fieldId} {fields} />
26+
<GalleryViewCard {record} {fieldId} {fields} {color} />
2427
{/each}
2528
</div>
2629
{/if}

0 commit comments

Comments
 (0)