budibase/packages/builder/src/pages/index.svelte

122 lines
2.6 KiB
Svelte
Raw Normal View History

<script>
2020-05-07 11:53:34 +02:00
import { store } from "builderStore"
2020-08-03 15:59:50 +02:00
import api from "builderStore/api"
2020-04-02 15:16:46 +02:00
import AppList from "components/start/AppList.svelte"
import { onMount } from "svelte"
import ActionButton from "components/common/ActionButton.svelte"
import { get } from "builderStore/api"
2020-04-02 15:16:46 +02:00
import Spinner from "components/common/Spinner.svelte"
2020-05-26 16:25:37 +02:00
import CreateAppModal from "components/start/CreateAppModal.svelte"
import { Button, Heading } from "@budibase/bbui"
import analytics from "analytics"
import { Modal } from "components/common/Modal"
let promise = getApps()
let hasKey
let modal
async function getApps() {
const res = await get("/api/applications")
const json = await res.json()
if (res.ok) {
return json
} else {
throw new Error(json)
}
}
2020-08-03 15:59:50 +02:00
async function fetchKeys() {
const response = await api.get(`/api/keys/`)
return await response.json()
2020-08-03 15:59:50 +02:00
}
async function checkIfKeysAndApps() {
const keys = await fetchKeys()
2020-08-03 15:59:50 +02:00
const apps = await getApps()
if (keys.userId) {
2020-08-03 15:59:50 +02:00
hasKey = true
analytics.identify(keys.userId)
}
if (!keys.budibase) {
modal.show()
2020-08-03 15:59:50 +02:00
}
}
checkIfKeysAndApps()
2020-05-26 10:38:43 +02:00
</script>
<div class="header">
<Heading medium black>Welcome to the Budibase Beta</Heading>
<Button primary black on:click={modal.show}>Create New Web App</Button>
</div>
2020-05-26 10:38:43 +02:00
<div class="banner">
<img src="/_builder/assets/orange-landscape.png" alt="rocket" />
2020-06-04 20:30:44 +02:00
<div class="banner-content">
Every accomplishment starts with a decision to try.
</div>
</div>
<Modal bind:this={modal} wide padded={false}>
<CreateAppModal {hasKey} />
</Modal>
2020-05-26 10:38:43 +02:00
{#await promise}
<div class="spinner-container">
<Spinner />
</div>
{:then result}
<AppList apps={result} />
{:catch err}
<h1 style="color:red">{err}</h1>
{/await}
<style>
.header {
display: flex;
justify-content: space-between;
align-items: center;
margin: 40px 80px 0px 80px;
}
.welcome {
font-size: var(--font-size-3xl);
color: var(--ink);
font-weight: 600;
}
.banner {
display: flex;
align-items: center;
justify-content: center;
position: relative;
text-align: center;
color: white;
margin: 20px 80px 40px 80px;
border-radius: 16px;
}
.banner img {
height: 250px;
width: 100%;
border-radius: 5px;
2020-06-04 20:30:44 +02:00
}
.banner-content {
position: absolute;
font-size: 24px;
color: var(--white);
font-weight: 500;
}
.spinner-container {
height: 100%;
width: 100%;
display: flex;
align-items: center;
justify-content: center;
}
</style>