From 4fd14058d9779c6f6552f24131eea80f9ea1f836 Mon Sep 17 00:00:00 2001 From: Vojtech Simetka Date: Sun, 2 Apr 2023 20:50:03 +0200 Subject: [PATCH] fix: create persona flow (#339) --- .../ui/src/lib/adapters/firebase/index.ts | 4 +- .../lib/adapters/in-memory-and-ipfs/index.ts | 4 +- packages/ui/src/lib/adapters/index.ts | 2 +- packages/ui/src/lib/adapters/zkitter/index.ts | 4 +- .../routes/persona/draft/[id]/+page.svelte | 61 +++++++++---------- .../ui/src/routes/persona/new/+page.svelte | 12 ++-- 6 files changed, 47 insertions(+), 40 deletions(-) diff --git a/packages/ui/src/lib/adapters/firebase/index.ts b/packages/ui/src/lib/adapters/firebase/index.ts index 64173a4..0f191c5 100644 --- a/packages/ui/src/lib/adapters/firebase/index.ts +++ b/packages/ui/src/lib/adapters/firebase/index.ts @@ -209,7 +209,7 @@ export class Firebase implements Adapter { ) } - async publishPersona(draftPersona: DraftPersona, signer: Signer): Promise { + async publishPersona(draftPersona: DraftPersona, signer: Signer): Promise { await signer.signMessage('This "transaction" publishes persona') const address = await signer.getAddress() const personasCollection = collection(db, 'personas') @@ -252,6 +252,8 @@ export class Firebase implements Adapter { return { ...state, draft: newDraft } }) + + return personaDoc.id } async signIn(): Promise { diff --git a/packages/ui/src/lib/adapters/in-memory-and-ipfs/index.ts b/packages/ui/src/lib/adapters/in-memory-and-ipfs/index.ts index 948a8a4..b704571 100644 --- a/packages/ui/src/lib/adapters/in-memory-and-ipfs/index.ts +++ b/packages/ui/src/lib/adapters/in-memory-and-ipfs/index.ts @@ -324,7 +324,7 @@ export class InMemoryAndIPFS implements Adapter { ) } - async publishPersona(draftPersona: DraftPersona, signer: Signer): Promise { + async publishPersona(draftPersona: DraftPersona, signer: Signer): Promise { await signer.signMessage('This "transaction" publishes persona') function getRandomNonExistingId(): Promise { @@ -376,6 +376,8 @@ export class InMemoryAndIPFS implements Adapter { }) return { transactions } }) + + return groupId } async signIn(): Promise { diff --git a/packages/ui/src/lib/adapters/index.ts b/packages/ui/src/lib/adapters/index.ts index 8b39d2d..e658784 100644 --- a/packages/ui/src/lib/adapters/index.ts +++ b/packages/ui/src/lib/adapters/index.ts @@ -21,7 +21,7 @@ export interface Adapter { addPersonaDraft: (draftPersona: DraftPersona) => Promise updatePersonaDraft: (index: number, draftPersona: DraftPersona) => Promise deleteDraftPersona: (index: number) => Promise - publishPersona(draftPersona: DraftPersona, signer: Signer): Promise + publishPersona(draftPersona: DraftPersona, signer: Signer): Promise uploadPicture(picture: string): Promise getPicture(cid: string): string diff --git a/packages/ui/src/lib/adapters/zkitter/index.ts b/packages/ui/src/lib/adapters/zkitter/index.ts index 6c294b5..c128f47 100644 --- a/packages/ui/src/lib/adapters/zkitter/index.ts +++ b/packages/ui/src/lib/adapters/zkitter/index.ts @@ -182,7 +182,7 @@ export class ZkitterAdapter implements Adapter { idCommitment: '', }) } - async publishPersona(draftPersona: DraftPersona, signer: Signer): Promise { + async publishPersona(draftPersona: DraftPersona, signer: Signer): Promise { if (!this.identity) throw new Error('must sign in first') const pending = await this.getPersonaSeedMessages() @@ -266,6 +266,8 @@ export class ZkitterAdapter implements Adapter { this.identity.zkIdentity.genIdentityCommitment().toString(), ) + return 'FIXME' + // return new Promise((resolve) => { // tokens.update(({ go, ...state }) => { // resolve() diff --git a/packages/ui/src/routes/persona/draft/[id]/+page.svelte b/packages/ui/src/routes/persona/draft/[id]/+page.svelte index 06f1fee..ebb5584 100644 --- a/packages/ui/src/routes/persona/draft/[id]/+page.svelte +++ b/packages/ui/src/routes/persona/draft/[id]/+page.svelte @@ -48,14 +48,9 @@ let postToEditText = '' let postToEditImages: string[] = [] let postToDelete: DraftPost | undefined = undefined + let publishedPersonaId: string | undefined = undefined - type State = - | 'persona_preview' - | 'edit_text' - | 'edit_rep' - | 'post_new' - | 'publish_warning' - | 'done' + type State = 'persona_preview' | 'edit_text' | 'edit_rep' | 'post_new' | 'publish_warning' let showWarningDiscardModal = false let showWarningDeletePersona = false @@ -82,8 +77,7 @@ async function publishPersona() { if (!$profile.signer) return - await adapter.publishPersona(persona, $profile.signer) - state = 'done' + publishedPersonaId = await adapter.publishPersona(persona, $profile.signer) } let y: number @@ -182,8 +176,7 @@ bind:images={postToEditImages} submit={(text, images) => { const psts = persona.posts.filter((p) => p !== postToEdit) - psts.push({ timestamp: Date.now(), text, images }) - persona.posts = psts + persona.posts = [{ timestamp: Date.now(), text, images }, ...psts] adapter.updatePersonaDraft(personaIndex, persona) postToEdit = undefined state = 'persona_preview' @@ -196,6 +189,30 @@ ? (showWarningDiscardModal = true) : (postToEdit = undefined)} /> +{:else if publishedPersonaId !== undefined} + +
+
+ +
+

This Persona is now public

+

+ Anyone can now submit posts with this Persona. All posts will be subject to community review + before being published. This Persona was added to your favorites. +

+ +
+ + +