mirror of
https://github.com/edufeed-org/educards.git
synced 2025-12-09 16:24:34 +00:00
Add markdown editor to card modal
This commit is contained in:
parent
77b1a5afe7
commit
218dfdd5c6
4 changed files with 58 additions and 11 deletions
|
|
@ -1,29 +1,32 @@
|
||||||
<script>
|
<script>
|
||||||
import { addCard } from '$lib/ndk';
|
import { addCard } from '$lib/ndk';
|
||||||
|
import MarkdownEditor from '$lib/components/MarkdownEditor.svelte';
|
||||||
|
|
||||||
export let modalRef;
|
export let modalRef;
|
||||||
|
|
||||||
let title;
|
let title = '';
|
||||||
|
let content = 'Write something awesome here 🌱';
|
||||||
function handleAddCard() {
|
function handleAddCard() {
|
||||||
const card = {
|
const card = {
|
||||||
title
|
title,
|
||||||
|
content
|
||||||
};
|
};
|
||||||
addCard(card);
|
addCard(card);
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<dialog id="add-card" class="modal" bind:this={modalRef}>
|
<dialog id="add-card" class="modal" bind:this={modalRef}>
|
||||||
<div class="modal-box">
|
<div class="modal-box flex w-3/4 max-w-5xl flex-col gap-1">
|
||||||
<h3 class="text-lg font-bold">Add Card</h3>
|
<h3 class="flex justify-center text-lg font-bold">Add Card</h3>
|
||||||
<label class="input input-bordered"
|
<label class="input input-bordered w-full"
|
||||||
>Titel
|
>Titel
|
||||||
<input type="text" bind:value={title} />
|
<input type="text" bind:value={title} />
|
||||||
</label>
|
</label>
|
||||||
<p class="py-4">Press ESC key or click the button below to close</p>
|
<MarkdownEditor bind:value={content} />
|
||||||
<div class="modal-action">
|
<div class="modal-action">
|
||||||
<form method="dialog">
|
<form method="dialog">
|
||||||
<button class="btn">Close</button>
|
<button class="btn btn-warning">Close</button>
|
||||||
<button on:click={handleAddCard}>Add card</button>
|
<button class="btn btn-success" on:click={handleAddCard}>Add card</button>
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
|
|
@ -111,8 +111,8 @@
|
||||||
<!-- {@debug column} -->
|
<!-- {@debug column} -->
|
||||||
{#each column.items as item (item?.id ?? item)}
|
{#each column.items as item (item?.id ?? item)}
|
||||||
<div class="card" animate:flip={{ duration: flipDurationMs }}>
|
<div class="card" animate:flip={{ duration: flipDurationMs }}>
|
||||||
|
{eventTitle(item)}
|
||||||
{item.content}
|
{item.content}
|
||||||
{item.dTag}
|
|
||||||
<button on:click={() => deleteCard(column, item.id)}>Delete</button>
|
<button on:click={() => deleteCard(column, item.id)}>Delete</button>
|
||||||
</div>
|
</div>
|
||||||
{/each}
|
{/each}
|
||||||
|
|
|
||||||
40
src/lib/components/MarkdownEditor.svelte
Normal file
40
src/lib/components/MarkdownEditor.svelte
Normal file
|
|
@ -0,0 +1,40 @@
|
||||||
|
<script>
|
||||||
|
import { Carta, MarkdownEditor } from 'carta-md';
|
||||||
|
// Component default theme
|
||||||
|
import 'carta-md/default.css';
|
||||||
|
|
||||||
|
const carta = new Carta();
|
||||||
|
|
||||||
|
export let value = '';
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<MarkdownEditor bind:value {carta} />
|
||||||
|
|
||||||
|
<style>
|
||||||
|
/* Or in global stylesheet */
|
||||||
|
/* Set your monospace font */
|
||||||
|
/* Required to have the editor working correctly! */
|
||||||
|
:global(.carta-font-code) {
|
||||||
|
font-family: '...', monospace;
|
||||||
|
font-size: 1.1rem;
|
||||||
|
line-height: 1.1rem;
|
||||||
|
letter-spacing: normal;
|
||||||
|
}
|
||||||
|
/* Editor dark mode */
|
||||||
|
/* Only if you are using the default theme */
|
||||||
|
html.dark .carta-theme__default {
|
||||||
|
--border-color: var(--border-color-dark);
|
||||||
|
--selection-color: var(--selection-color-dark);
|
||||||
|
--focus-outline: var(--focus-outline-dark);
|
||||||
|
--hover-color: var(--hover-color-dark);
|
||||||
|
--caret-color: var(--caret-color-dark);
|
||||||
|
--text-color: var(--text-color-dark);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Code dark mode */
|
||||||
|
/* Only if you didn't specify a custom code theme */
|
||||||
|
html.dark .shiki,
|
||||||
|
html.dark .shiki span {
|
||||||
|
color: var(--shiki-dark) !important;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
|
@ -66,7 +66,9 @@ export async function addColumn(column) {
|
||||||
|
|
||||||
export async function addCard(card) {
|
export async function addCard(card) {
|
||||||
const ndk = getNdk();
|
const ndk = getNdk();
|
||||||
const cardEvent = new NDKEvent(ndk, { kind: 30045, content: card.title });
|
const cardEvent = new NDKEvent(ndk, { kind: 30045, content: card.content });
|
||||||
|
cardEvent.tags.push(['title', card.title]);
|
||||||
|
console.log('card event', cardEvent);
|
||||||
await cardEvent.publish();
|
await cardEvent.publish();
|
||||||
|
|
||||||
const columnEvent = await ndk.fetchEvent({
|
const columnEvent = await ndk.fetchEvent({
|
||||||
|
|
@ -112,11 +114,13 @@ async function eventTagToColumn(eventTag) {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Gets the title tag of an event
|
||||||
* @param {NDKEvent} event
|
* @param {NDKEvent} event
|
||||||
|
* @returns {string}
|
||||||
*/
|
*/
|
||||||
export function eventTitle(event) {
|
export function eventTitle(event) {
|
||||||
if (event === undefined) return '';
|
if (event === undefined) return '';
|
||||||
const title = event.tags.find((e) => e[0] === 'title')[1] ?? '';
|
const title = event.tags?.find((e) => e[0] === 'title')?.[1] ?? '';
|
||||||
return title;
|
return title;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue