From 90c49fc931fd360397b5851b8c4c06716f431cc5 Mon Sep 17 00:00:00 2001 From: "@s.roertgen" Date: Wed, 23 Apr 2025 12:24:41 +0200 Subject: [PATCH] align colors and clean up modals a bit --- src/lib/components/AddBoardModal.svelte | 7 ++-- src/lib/components/AddColumnModal.svelte | 9 ++-- src/lib/components/Column.svelte | 18 +++++++- src/lib/ndk.js | 53 +++++++++++++----------- 4 files changed, 51 insertions(+), 36 deletions(-) diff --git a/src/lib/components/AddBoardModal.svelte b/src/lib/components/AddBoardModal.svelte index 60eee6e..ebdbe00 100644 --- a/src/lib/components/AddBoardModal.svelte +++ b/src/lib/components/AddBoardModal.svelte @@ -14,15 +14,14 @@ diff --git a/src/lib/components/AddColumnModal.svelte b/src/lib/components/AddColumnModal.svelte index 7cf96dc..f362ad8 100644 --- a/src/lib/components/AddColumnModal.svelte +++ b/src/lib/components/AddColumnModal.svelte @@ -3,7 +3,7 @@ export let modalRef; - let title; + let title = 'Titel'; function handleAddColumn() { const column = { title @@ -14,16 +14,15 @@ diff --git a/src/lib/components/Column.svelte b/src/lib/components/Column.svelte index b68f941..0f8b312 100644 --- a/src/lib/components/Column.svelte +++ b/src/lib/components/Column.svelte @@ -5,8 +5,16 @@ import Card from './Card.svelte'; import PlusCircleFill from '$lib/icons/PlusCircleFill.svelte'; import AddCardModal from './AddCardModal.svelte'; - import { selectedColumn, currentBoard, user, userAndBoardMatch, deleteColumn } from '$lib/db'; + import { + selectedColumn, + currentBoard, + user, + userAndBoardMatch, + deleteColumn, + ndkStore + } from '$lib/db'; import { eventTitle, publishCards } from '$lib/ndk'; + import { NDKEvent } from '@nostr-dev-kit/ndk'; export let column; export let flipDurationMs; @@ -27,7 +35,13 @@ const colIdx = items.findIndex((c) => c.id === cid); items[colIdx].items = e.detail.items; items = [...items]; - publishCards(items[colIdx]); + + const newColumn = new NDKEvent(ndkStore, items[colIdx]); + newColumn.tags = newColumn.tags.filter((e) => e[0] !== 'a'); + e.detail.items.forEach((card) => { + newColumn.tags.push(['a', card.tagAddress()]); + }); + publishCards(newColumn); } diff --git a/src/lib/ndk.js b/src/lib/ndk.js index 10ec193..288eeab 100644 --- a/src/lib/ndk.js +++ b/src/lib/ndk.js @@ -24,7 +24,6 @@ export async function login(method) { user = await nip07signer.user(); await user.fetchProfile(); userStore.set(user); - console.log('user', user); db.update((db) => { return { ...db, ndk, user }; }); @@ -53,12 +52,6 @@ export async function addColumn(column) { // add column to Board const boardD = get(currentBoard).dTag; - console.log('board dtag', boardD); - // const existingBoard = await ndk.fetchEvent({ - // kinds: [30043], - // authors: [user.pubkey], - // '#d': [get(currentBoard).dTag] - // }); const existingBoard = new NDKEvent(ndk, get(currentBoard)); existingBoard.tags.push(['a', `30044:${user.pubkey}:${columnEvent.dTag}`]); existingBoard.publishReplaceable(); @@ -178,27 +171,37 @@ async function addressedEvents(event) { } export async function publishBoard(board) { - const ndk = getNdk(); - console.log(get(currentBoardAddress)); - const existingBoard = get(currentBoard); - // const existingBoard = await ndk.fetchEvent({ - // kinds: [30043], - // authors: [board.pubkey], - // '#d': [board.dTag] // TODO does this work with address? guess it needs to be the tag - // }); - const columnIds = board.items.map((e) => e.dTag); - let tags = existingBoard.tags.filter((t) => t[0] !== 'a'); - columnIds.forEach((dTag) => { - // TODO use user pubkey here so that - // after a fork the correct column tags are assigned? - tags.push(['a', `30044:${board.pubkey}:${dTag}`]); - }); - existingBoard.tags = tags; - existingBoard.publishReplaceable(); + try { + const ndk = getNdk(); + const existingBoard = get(currentBoard); + // const existingBoard = await ndk.fetchEvent({ + // kinds: [30043], + // authors: [board.pubkey], + // '#d': [board.dTag] // TODO does this work with address? guess it needs to be the tag + // }); + const columnIds = board.items.map((e) => e.dTag); + let tags = existingBoard.tags.filter((t) => t[0] !== 'a'); + columnIds.forEach((dTag) => { + // TODO use user pubkey here so that + // after a fork the correct column tags are assigned? + tags.push(['a', `30044:${board.pubkey}:${dTag}`]); + }); + existingBoard.tags = tags; + await existingBoard.publishReplaceable(); + } catch (error) { + alert('Please log in before dragging'); + console.error(error); + } } export async function publishCards(column) { - column.publishReplaceable(); + try { + const event = new NDKEvent(get(ndkStore), column); + await event.publishReplaceable(); + } catch (error) { + alert('Please log in before dragging'); + console.error(error); + } } /** takes existing tags and replaces the pubkey in the Tag Addresses