Browse Source

Add /new/review page route

master
buttercat1791 1 year ago
parent
commit
34d272d8d1
  1. 19
      src/lib/components/Preview.svelte
  2. 21
      src/lib/parser.ts
  3. 32
      src/routes/new/edit/+page.svelte
  4. 0
      src/routes/new/edit/+page.ts
  5. 14
      src/routes/new/review/+page.svelte

19
src/lib/components/Preview.svelte

@ -1,17 +1,18 @@
<script lang="ts"> <script lang="ts">
import Pharos from "$lib/parser"; import { parser } from "$lib/parser";
import { Heading, P } from "flowbite-svelte"; import { Heading, P } from "flowbite-svelte";
export let sectionClass: string = ''; export let sectionClass: string = '';
export let parser: Pharos;
export let rootIndexId: string; export let rootIndexId: string;
export let depth: number = 0; export let depth: number = 0;
export let allowEditing: boolean = false;
// TODO: Add editing functionality.
const title = parser.getIndexTitle(rootIndexId); const title = $parser.getIndexTitle(rootIndexId);
const orderedChildren = parser.getOrderedChildIds(rootIndexId); const orderedChildren = $parser.getOrderedChildIds(rootIndexId);
const childIndices = parser.getChildIndexIds(rootIndexId); const childIndices = $parser.getChildIndexIds(rootIndexId);
const childZettels = parser.getChildZettelIds(rootIndexId); const childZettels = $parser.getChildZettelIds(rootIndexId);
const getHeadingTag = (depth: number) => { const getHeadingTag = (depth: number) => {
switch (depth) { switch (depth) {
@ -34,16 +35,16 @@
<Heading tag={getHeadingTag(depth)} class='h-leather'>{title}</Heading> <Heading tag={getHeadingTag(depth)} class='h-leather'>{title}</Heading>
{#each orderedChildren as id, index} {#each orderedChildren as id, index}
{#if childIndices.includes(id)} {#if childIndices.includes(id)}
<svelte:self {parser} rootIndexId={id} depth={depth + 1} /> <svelte:self {$parser} rootIndexId={id} depth={depth + 1} />
{:else if (childZettels.includes(id))} {:else if (childZettels.includes(id))}
<P class='note-leather' firstupper={index === 0}> <P class='note-leather' firstupper={index === 0}>
{@html parser.getContent(id)} {@html $parser.getContent(id)}
</P> </P>
{/if} {/if}
{/each} {/each}
{:else} {:else}
<P class='note-leather' firstupper> <P class='note-leather' firstupper>
{@html parser.getContent(rootIndexId)} {@html $parser.getContent(rootIndexId)}
</P> </P>
{/if} {/if}
</section> </section>

21
src/lib/parser.ts

@ -1,4 +1,5 @@
import NDK, { NDKEvent } from '@nostr-dev-kit/ndk'; import NDK, { NDKEvent } from '@nostr-dev-kit/ndk';
import { getNdkInstance } from './ndk';
import asciidoctor, { import asciidoctor, {
AbstractBlock, AbstractBlock,
AbstractNode, AbstractNode,
@ -10,6 +11,7 @@ import asciidoctor, {
type ProcessorOptions type ProcessorOptions
} from 'asciidoctor'; } from 'asciidoctor';
import he from 'he'; import he from 'he';
import { writable, type Writable } from 'svelte/store';
interface IndexMetadata { interface IndexMetadata {
authors?: string[]; authors?: string[];
@ -192,6 +194,21 @@ export default class Pharos {
return block.convert(); return block.convert();
} }
/**
* Resets the parser to its initial state, removing any parsed data.
*/
reset(): void {
this.blockCounter = 0;
this.html = undefined;
this.rootNodeId = undefined;
this.rootIndexId = undefined;
this.rootIndexMetadata = {};
this.nodes.clear();
this.eventToKindMap.clear();
this.indexToChildEventsMap.clear();
this.eventIds.clear();
}
// #endregion // #endregion
// #region Tree Processor Extensions // #region Tree Processor Extensions
@ -499,4 +516,6 @@ export default class Pharos {
// TODO: Add search-based wikilink resolution. // TODO: Add search-based wikilink resolution.
// #endregion // #endregion
} }
export const parser: Writable<Pharos> = writable(new Pharos(getNdkInstance()));

32
src/routes/new/edit/+page.svelte

@ -1,30 +1,40 @@
<script lang="ts"> <script lang="ts">
import { Button, Heading, Textarea, Toolbar, ToolbarButton, Tooltip } from "flowbite-svelte"; import { Button, Heading, Textarea, Toolbar, ToolbarButton, Tooltip } from "flowbite-svelte";
import { CodeOutline, EyeSolid } from "flowbite-svelte-icons"; import { CodeOutline, EyeSolid, PaperPlaneOutline } from "flowbite-svelte-icons";
import { editorText } from "$lib/stores"; import { editorText } from "$lib/stores";
import Preview from "$lib/components/Preview.svelte"; import Preview from "$lib/components/Preview.svelte";
import Pharos from "$lib/parser"; import Pharos, { parser } from "$lib/parser";
import { ndk } from "$lib/ndk"; import { ndk } from "$lib/ndk";
import { goto } from "$app/navigation";
// TODO: Prompt user to sign in before editing.
let parser: Pharos;
let isEditing: boolean = true; let isEditing: boolean = true;
$: rootIndexId = parser?.getRootIndexId(); $parser = new Pharos($ndk);
$: rootIndexId = $parser?.getRootIndexId();
const showPreview = () => { const showPreview = () => {
parser = new Pharos($ndk); $parser.reset();
parser.parse($editorText); $parser.parse($editorText);
isEditing = false; isEditing = false;
}; };
const hidePreview = () => { const hidePreview = () => {
isEditing = true; isEditing = true;
}; };
const prepareReview = () => {
$parser.reset();
$parser.parse($editorText);
goto('/new/review');
}
</script> </script>
<div class='w-full flex justify-center'> <div class='w-full flex justify-center'>
<main class='main-leather flex flex-col space-y-4 max-w-2xl w-full mt-4 mb-4'> <main class='main-leather flex flex-col space-y-4 max-w-2xl w-full mt-4 mb-4'>
<Heading tag='h1' class='h-leather mb-2'>New Article</Heading> <Heading tag='h1' class='h-leather mb-2'>Edit</Heading>
{#if isEditing} {#if isEditing}
<form> <form>
<Textarea <Textarea
@ -38,6 +48,9 @@
<ToolbarButton name='Preview' on:click={showPreview}> <ToolbarButton name='Preview' on:click={showPreview}>
<EyeSolid class='w-6 h-6' /> <EyeSolid class='w-6 h-6' />
</ToolbarButton> </ToolbarButton>
<ToolbarButton name='Review' slot='end'>
<PaperPlaneOutline class='w=6 h-6 rotate-90' on:click={prepareReview} />
</ToolbarButton>
</Toolbar> </Toolbar>
</Textarea> </Textarea>
</form> </form>
@ -47,9 +60,12 @@
<ToolbarButton name='Edit' on:click={hidePreview}> <ToolbarButton name='Edit' on:click={hidePreview}>
<CodeOutline class='w-6 h-6' /> <CodeOutline class='w-6 h-6' />
</ToolbarButton> </ToolbarButton>
<ToolbarButton name='Review' slot='end'>
<PaperPlaneOutline class='w=6 h-6 rotate-90' on:click={prepareReview} />
</ToolbarButton>
</Toolbar> </Toolbar>
{#if rootIndexId} {#if rootIndexId}
<Preview sectionClass='m-2' {parser} {rootIndexId} /> <Preview sectionClass='m-2' {rootIndexId} />
{/if} {/if}
</form> </form>
{/if} {/if}

0
src/routes/new/edit/+page.ts

14
src/routes/new/review/+page.svelte

@ -0,0 +1,14 @@
<script lang='ts'>
import Preview from "$lib/components/Preview.svelte";
import { parser } from "$lib/parser";
import { Heading } from "flowbite-svelte";
</script>
<div class='w-full flex justify-center'>
<main class='main-leather flex flex-col space-y-4 max-w-2xl w-full mt-4 mb-4'>
<Heading tag='h1' class='h-leather mb-2'>Review</Heading>
<Preview rootIndexId={$parser.getRootIndexId()} allowEditing={true} />
</main>
</div>
Loading…
Cancel
Save