Skip to content

Commit

Permalink
feat: improved relation component
Browse files Browse the repository at this point in the history
  • Loading branch information
bbtgnn committed Feb 29, 2024
1 parent a3d4a75 commit 92d91ae
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 6 deletions.
12 changes: 8 additions & 4 deletions src/_modules/components/Relation.svelte
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
<script lang="ts">
import { db } from '$modules';
import Document from './Document.svelte';
import type { RelationField } from '$modules/fields';
import type { CollectionName } from '$modules/database';
//
type C = $$Generic<CollectionName>;
export let relation: RelationField<C> | undefined;
export let to: RelationField<C> | undefined;
</script>

{#if relation}
<slot relation={db.get_document(relation?.collection, relation.document)} />
{#if to}
<Document collection={to.collection} name={to.document} let:doc>
<slot {doc} />
</Document>
{/if}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<script lang="ts" context="module">
import { db } from '$modules/index';
import { Document } from '$modules/components';
import Relation from '$modules/components/Relation.svelte';
export const props = db.create('work_experiences', {
date_start: '2022-10',
Expand All @@ -19,3 +20,9 @@
<pre>{JSON.stringify(doc, null, 2)}</pre>
<!-- <img src={entry.logo} alt="" /> -->
</Document>

<!-- OR -->

<Relation to={props.organization} let:doc>
<pre>{JSON.stringify(doc, null, 2)}</pre>
</Relation>
6 changes: 4 additions & 2 deletions src/routes/+page.svelte
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<script lang="ts">
import { Collection, Document, Relation } from '$modules/components';
import DocumentContent from '$modules/components/DocumentContent.svelte';
import { db } from '$modules/index';
const links = db.get_paths();
Expand Down Expand Up @@ -32,8 +33,9 @@
<div class="rounded-lg border border-gray-300 p-4">
<pre>{JSON.stringify(experience, null, 2)}</pre>

<Relation relation={experience.props?.organization} let:relation>
<pre>{JSON.stringify(relation, null, 2)}</pre>
<Relation to={experience.props?.organization} let:doc>
<pre>{JSON.stringify(doc, null, 2)}</pre>
<DocumentContent />
</Relation>
</div>
{/each}
Expand Down

0 comments on commit 92d91ae

Please sign in to comment.