Link expansion of delete confirmation and color changer together
This commit is contained in:
parent
92fde448ff
commit
68ac26e991
|
@ -34,9 +34,9 @@
|
||||||
<article class="note-card" style:--note-color={NoteColor[note.color][$themeUpperCase]}>
|
<article class="note-card" style:--note-color={NoteColor[note.color][$themeUpperCase]}>
|
||||||
<header class="note-card__header" hidden={$editing}>
|
<header class="note-card__header" hidden={$editing}>
|
||||||
<div class="note-card__header-buttons">
|
<div class="note-card__header-buttons">
|
||||||
<NoteDeleteButton {note} />
|
<NoteDeleteButton {note} {noteEditorStore} />
|
||||||
<div class="note-card__spacer" />
|
<div class="note-card__spacer" />
|
||||||
<NoteColorPicker {note} />
|
<NoteColorPicker {note} {noteEditorStore} />
|
||||||
<NoteTagButton on:click={focusTags} />
|
<NoteTagButton on:click={focusTags} />
|
||||||
</div>
|
</div>
|
||||||
<div hidden={!showTags && $noteTags.length === 0}>
|
<div hidden={!showTags && $noteTags.length === 0}>
|
||||||
|
|
|
@ -4,10 +4,11 @@
|
||||||
import Button from '../button.svelte';
|
import Button from '../button.svelte';
|
||||||
import { notes, themeUpperCase } from '$lib/stores';
|
import { notes, themeUpperCase } from '$lib/stores';
|
||||||
import type { Note } from '$lib/stores/notes';
|
import type { Note } from '$lib/stores/notes';
|
||||||
|
import type { NoteEditorStore } from '$lib/stores/note-editor';
|
||||||
|
|
||||||
export let note: Note;
|
export let note: Note;
|
||||||
|
export let noteEditorStore: NoteEditorStore;
|
||||||
let selectingColor: boolean = false;
|
const { expanded, expand } = noteEditorStore;
|
||||||
|
|
||||||
const colors = Object.entries(NoteColor) as [
|
const colors = Object.entries(NoteColor) as [
|
||||||
[keyof typeof NoteColor, (typeof NoteColor)[keyof typeof NoteColor]]
|
[keyof typeof NoteColor, (typeof NoteColor)[keyof typeof NoteColor]]
|
||||||
|
@ -15,12 +16,12 @@
|
||||||
|
|
||||||
function changeColor(color: keyof typeof NoteColor) {
|
function changeColor(color: keyof typeof NoteColor) {
|
||||||
notes.update(note.id, { color });
|
notes.update(note.id, { color });
|
||||||
selectingColor = false;
|
expand(null);
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
{#if !selectingColor}
|
{#if $expanded !== 'colors'}
|
||||||
<Button plain icon label="Change color" on:click={() => (selectingColor = true)}>
|
<Button plain icon label="Change color" on:click={() => expand('colors')}>
|
||||||
<FaPalette />
|
<FaPalette />
|
||||||
</Button>
|
</Button>
|
||||||
{:else}
|
{:else}
|
||||||
|
|
|
@ -5,7 +5,6 @@
|
||||||
|
|
||||||
export let note: Note;
|
export let note: Note;
|
||||||
export let noteEditorStore: NoteEditorStore;
|
export let noteEditorStore: NoteEditorStore;
|
||||||
|
|
||||||
const { editing, draftContent, draftChange } = noteEditorStore;
|
const { editing, draftContent, draftChange } = noteEditorStore;
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|
|
@ -5,14 +5,15 @@
|
||||||
import type { Note } from '$lib/stores/notes';
|
import type { Note } from '$lib/stores/notes';
|
||||||
import FaCircleXmark from '$icon/fa-circle-xmark.svelte';
|
import FaCircleXmark from '$icon/fa-circle-xmark.svelte';
|
||||||
import FaCircleCheck from '$icon/fa-circle-check.svelte';
|
import FaCircleCheck from '$icon/fa-circle-check.svelte';
|
||||||
|
import type { NoteEditorStore } from '$lib/stores/note-editor';
|
||||||
|
|
||||||
export let note: Note;
|
export let note: Note;
|
||||||
|
export let noteEditorStore: NoteEditorStore;
|
||||||
let confirming: boolean = false;
|
const { expanded, expand } = noteEditorStore;
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
{#if !confirming}
|
{#if $expanded !== 'delete'}
|
||||||
<Button plain icon label="Delete note" on:click={() => (confirming = true)}>
|
<Button plain icon label="Delete note" on:click={() => expand('delete')}>
|
||||||
<FaTrash />
|
<FaTrash />
|
||||||
</Button>
|
</Button>
|
||||||
{:else}
|
{:else}
|
||||||
|
@ -21,7 +22,7 @@
|
||||||
<Button plain icon label="Confirm deletion" on:click={() => notes.remove(note.id)}>
|
<Button plain icon label="Confirm deletion" on:click={() => notes.remove(note.id)}>
|
||||||
<FaCircleCheck />
|
<FaCircleCheck />
|
||||||
</Button>
|
</Button>
|
||||||
<Button plain icon label="Cancel deletion" on:click={() => (confirming = false)}>
|
<Button plain icon label="Cancel deletion" on:click={() => expand(null)}>
|
||||||
<FaCircleXmark />
|
<FaCircleXmark />
|
||||||
</Button>
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -1,12 +1,16 @@
|
||||||
import { get, readonly, writable } from 'svelte/store';
|
import { get, readonly, writable } from 'svelte/store';
|
||||||
import type { Note, NotesStore } from './notes';
|
import type { Note, NotesStore } from './notes';
|
||||||
|
|
||||||
|
type ExpandState = 'delete' | 'colors' | null;
|
||||||
|
|
||||||
export class NoteEditorStore {
|
export class NoteEditorStore {
|
||||||
private _editing = writable<boolean>(false);
|
private _editing = writable<boolean>(false);
|
||||||
private _draftContent = writable<string>('');
|
private _draftContent = writable<string>('');
|
||||||
|
private _expanded = writable<ExpandState>(null);
|
||||||
|
|
||||||
readonly editing = readonly(this._editing);
|
readonly editing = readonly(this._editing);
|
||||||
readonly draftContent = readonly(this._draftContent);
|
readonly draftContent = readonly(this._draftContent);
|
||||||
|
readonly expanded = readonly(this._expanded);
|
||||||
|
|
||||||
constructor(private noteId: Note['id'], private notes: NotesStore) {}
|
constructor(private noteId: Note['id'], private notes: NotesStore) {}
|
||||||
|
|
||||||
|
@ -29,4 +33,8 @@ export class NoteEditorStore {
|
||||||
discard = () => {
|
discard = () => {
|
||||||
this._editing.set(false);
|
this._editing.set(false);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
expand = (expanded: ExpandState) => {
|
||||||
|
this._expanded.set(expanded);
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue