From 9581ca88847d1175586a289d3b50ed7fc83512d8 Mon Sep 17 00:00:00 2001 From: Christophe Le Bars Date: Tue, 7 Nov 2023 16:02:29 +0100 Subject: [PATCH] draft application hub --- src/components/form/HubApplication.svelte | 455 +++--------------- .../(app)/project/[address]/+page.svelte | 24 +- 2 files changed, 68 insertions(+), 411 deletions(-) diff --git a/src/components/form/HubApplication.svelte b/src/components/form/HubApplication.svelte index 0eac8d8..74f8b71 100644 --- a/src/components/form/HubApplication.svelte +++ b/src/components/form/HubApplication.svelte @@ -7,16 +7,13 @@ import { categories, visuals } from '$lib/visuals.js' - import { ipfs } from '$lib/actions/ipfs.js' - - import Calendar from '$components/Calendar/index.svelte' + import Modal from '$components/Modal.svelte' import Waiting from '$components/Waiting.svelte' - import Upload from '$components/Upload.svelte' - const mobile = getContext('mobile') + let modal export let data = {} - export let edit = false + export let active = false export const control = { isWaiting: false, @@ -24,25 +21,12 @@ warned: {} } - const uploadSuccess = (event) => { - console.log('uploadSuccess', event) - // TDOO remove croppedVisual - delete control.croppedVisual - delete control.error.visual - - data.visual = event.detail.src - } + export const cancel = async () => { + control.error = {} + active = false - const uploadFailure = (event) => { - console.log('uploadFailure', event) } - let mark = 1 - - $: defaultVisuals = mark - ? (categories[data.category] || []).map((h) => `ipfs://${visuals[h].cid}`) - : [] - export const validate = async () => { control.error = {} @@ -50,392 +34,79 @@ control.error.name = 'This field is required' } - if ($mobile) { - data.when = [data.when1, data.when2] - } - - if (!data.visual && !control.croppedVisual) { - control.error.visual = 'A main visual is required' - } - - if (!data.when[0] || !data.when[1]) { - control.error.when = - 'Event starting and ending date and time are all required' - } else { - const from = dayjs(data.when[0]) - const to = dayjs(data.when[1]) - - if (to.isBefore(from)) { - control.error.when = 'Event ending date and time must be after start' - return false - } - - if (!edit && from.isBefore(dayjs()) && !control.warned.date) { - control.error.when = - 'Your event start in the past. If you are sure, click again...' - control.warned.date = true - return false - } - } - - if (!data.online) { - if (!data.address) { - control.error.address = 'This field is required' - } - if (!data.postalCode) { - control.error.postalCode = 'This field is required' - } - if (!data.city) { - control.error.city = 'This field is required' - } - if (!data.country) { - control.error.country = 'This field is required' - } - } - - if (data.url && !/^(https?|ipfs):/.test(data.url)) { - data.url = 'http://' + data.url + if (!data.email) { + control.error.email = 'This field is required' } if (Object.keys(control.error).length > 0) return false - if (control.croppedVisual) data.visual = control.croppedVisual - if (/^data:image/.test(data.visual)) { - control.isWaiting = true - control.loadText = edit - ? 'Updating your draft event...' - : 'Creating your draft event...' + /* send request */ - const upload = await backend.uploadFile(data.visual) - if (upload && upload.success) { - if (data._isDraft) { - data.visual = `ipfs://${upload.cids[0].cid}` - return true - } else { - // todo - } - } - control.error.visual = 'Server error, please retry later' - control.isWaiting = false - return false - } - - return true } -

When?

- -
- {#if $mobile} -
-
- -

- { - control.warned.date = false - }} - bind:value={data.when1} /> -

-
-
-
-
- -

- { - control.warned.date = false - }} - bind:value={data.when2} /> -

- {#if control.error.when}

- {control.error.when} -

{/if} -
-
- {:else} -
-
- -

- { - control.warned.date = false - }} /> -

- {#if control.error.when}

- {control.error.when} -

{/if} -
-
- {/if} -
- + -

What?

+ -
-
- -

- -

- {#if control.error.country}

- {control.error.country} -

{/if} -
-
- {:else} -
-
- -

- -

- {#if control.error.url}

- {control.error.url} -

{/if} -
-
- {/if} - +
{#if !control.loadClose} @@ -450,14 +121,8 @@ + control.isWaiting = false + }}>Close {/if} - - diff --git a/src/routes/(app)/project/[address]/+page.svelte b/src/routes/(app)/project/[address]/+page.svelte index c9f7172..da7395d 100644 --- a/src/routes/(app)/project/[address]/+page.svelte +++ b/src/routes/(app)/project/[address]/+page.svelte @@ -6,13 +6,16 @@ import Project from '$components/Project.svelte' + import Application from '$components/form/HubApplication.svelte' + import project from '$stores/project.js' - //import { toHexString } from '$lib/utils.js' export let data $: ({ address } = data) + let applicationActive = false + dayjs.extend(localizedFormat) $: p = $project[address] || {} @@ -20,18 +23,11 @@ const endpoint = import.meta.env.VITE_SPRINGBOK_ENDPOINT const gateway = `${endpoint}/ipfs/` - const test = () => { - // // Object { draftNonce: 1 } - // const draftNonce = 1 - // //toHexString(draftNonce) - // //invalid BytesLike value (argument="value", value="0x1", code=INVALID_ARGUMENT, version=6.3.0) - // console.log(draftNonce) - // - // const address = toHexString(draftNonce, 40) - // console.log(address) - } + + +