add loading state

This commit is contained in:
kevmodrome 2020-05-27 12:54:53 +02:00
parent 075b264d21
commit 3a72eddd78
5 changed files with 207 additions and 182 deletions

View File

@ -26,6 +26,4 @@
<AppNotification /> <AppNotification />
<Modal>
<Router {routes} /> <Router {routes} />
</Modal>

View File

@ -1,30 +1,36 @@
<script> <script>
import Spinner from "components/common/Spinner.svelte"
import { Input, TextArea, Button } from "@budibase/bbui" import { Input, TextArea, Button } from "@budibase/bbui"
import { goto } from "@sveltech/routify"
import { AppsIcon, InfoIcon, CloseIcon } from "components/common/Icons/" import { AppsIcon, InfoIcon, CloseIcon } from "components/common/Icons/"
import { getContext } from "svelte" import { getContext } from "svelte"
export let onCancel = () => {} import { fade } from "svelte/transition"
export let onOkay = () => {}
const { close } = getContext("simple-modal") const { open, close } = getContext("simple-modal")
let name = "" let name = ""
let description = "" let description = ""
let loading = false
const createNewApp = async () => { const createNewApp = async () => {
const data = { name, description } const data = { name, description }
loading = true
try { try {
const response = await fetch('/api/applications', { const response = await fetch("/api/applications", {
method: 'POST', // *GET, POST, PUT, DELETE, etc. method: "POST", // *GET, POST, PUT, DELETE, etc.
credentials: 'same-origin', // include, *same-origin, omit credentials: "same-origin", // include, *same-origin, omit
headers: { headers: {
'Content-Type': 'application/json' "Content-Type": "application/json",
// 'Content-Type': 'application/x-www-form-urlencoded', // 'Content-Type': 'application/x-www-form-urlencoded',
}, },
body: JSON.stringify(data) // body data type must match "Content-Type" header body: JSON.stringify(data), // body data type must match "Content-Type" header
}); })
} catch (error) {
const res = await response.json()
$goto(`./${res._id}`)
} catch (error) {
console.error(error)
} }
} }
@ -32,23 +38,28 @@
let onChange = () => {} let onChange = () => {}
function _onCancel() { function _onCancel() {
onCancel()
close() close()
} }
async function _onOkay() { async function _onOkay() {
await createNewApp() await createNewApp()
close()
} }
</script> </script>
<div class="container"> <div class="container">
<div class="body"> <div class="body">
<div class="heading"> <div class="heading">
<span class="icon"><AppsIcon /></span> <span class="icon">
<AppsIcon />
</span>
<h3>Create new web app</h3> <h3>Create new web app</h3>
</div> </div>
<Input name="name" label="Name" placeholder="Enter application name" on:change={(e) => name = e.target.value} on:input={(e) => name = e.target.value} /> <Input
name="name"
label="Name"
placeholder="Enter application name"
on:change={e => (name = e.target.value)}
on:input={e => (name = e.target.value)} />
<TextArea <TextArea
bind:value={description} bind:value={description}
name="description" name="description"
@ -56,19 +67,25 @@
placeholder="Describe your application" /> placeholder="Describe your application" />
</div> </div>
<div class="footer"> <div class="footer">
<a href="./#" class="info"><InfoIcon />How to get started</a> <a href="./#" class="info">
<Button outline thin on:click={_onCancel}> <InfoIcon />
Cancel How to get started
</Button> </a>
<Button primary thin on:click={_onOkay}> <Button outline thin on:click={_onCancel}>Cancel</Button>
Save <Button primary thin on:click={_onOkay}>Save</Button>
</Button>
</div> </div>
<div class="close-button" on:click={_onCancel}><CloseIcon /></div> <div class="close-button" on:click={_onCancel}>
<CloseIcon />
</div>
{#if loading}
<div in:fade class="spinner-container">
<Spinner />
<span class="spinner-text">Creating your app...</span>
</div>
{/if}
</div> </div>
<style> <style>
.container { .container {
position: relative; position: relative;
} }
@ -130,4 +147,20 @@
border-bottom-right-radius: 50px; border-bottom-right-radius: 50px;
background-color: var(--grey-light); background-color: var(--grey-light);
} }
.spinner-container {
background: white;
position: absolute;
border-radius: 5px;
left: 0;
top: 0;
right: 0;
bottom: 0;
display: grid;
justify-items: center;
align-content: center;
grid-gap: 50px;
}
.spinner-text {
font-size: 2em;
}
</style> </style>

View File

@ -1,4 +1,5 @@
<script> <script>
import Modal from "svelte-simple-modal"
import { store } from "builderStore" import { store } from "builderStore"
import { fade } from "svelte/transition" import { fade } from "svelte/transition"
@ -20,12 +21,12 @@
await store.setPackage(pkg) await store.setPackage(pkg)
return pkg return pkg
} else { } else {
console.log(pkg)
throw new Error(pkg) throw new Error(pkg)
} }
} }
</script> </script>
<Modal>
<div class="root"> <div class="root">
<div class="top-nav"> <div class="top-nav">
@ -76,6 +77,7 @@
{/await} {/await}
</div> </div>
</Modal>
<style> <style>
.root { .root {

View File

@ -1,4 +1,5 @@
<script> <script>
import Modal from "svelte-simple-modal"
import { import {
SettingsIcon, SettingsIcon,
AppsIcon, AppsIcon,
@ -14,6 +15,7 @@
} from "components/common/Icons/" } from "components/common/Icons/"
</script> </script>
<Modal>
<div class="root"> <div class="root">
<div class="ui-nav"> <div class="ui-nav">
<div class="home-logo"> <div class="home-logo">
@ -112,6 +114,7 @@
<slot /> <slot />
</div> </div>
</div> </div>
</Modal>
<style> <style>
.root { .root {

View File

@ -24,15 +24,6 @@
// Handle create app modal // Handle create app modal
const { open } = getContext("simple-modal") const { open } = getContext("simple-modal")
const onCancel = text => {
name = ""
status = -1
}
const onOkay = text => {
name = text
status = 1
}
const showCreateAppModal = () => { const showCreateAppModal = () => {
open( open(
@ -40,15 +31,13 @@
{ {
message: "What is your name?", message: "What is your name?",
hasForm: true, hasForm: true,
onCancel,
onOkay,
}, },
{ {
closeButton: false, closeButton: false,
closeOnEsc: false, closeOnEsc: false,
closeOnOuterClick: false, closeOnOuterClick: false,
styleContent: { padding: 0 }, styleContent: { padding: 0 },
closeOnOuterClick: true closeOnOuterClick: true,
} }
) )
} }