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

136 lines
2.7 KiB
Svelte
Raw Normal View History

<script>
2020-05-26 10:38:43 +02:00
import { getContext } from "svelte"
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 } from "@budibase/bbui"
let promise = getApps()
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
let hasKey
async function fetchKeys() {
const response = await api.get(`/api/keys/`)
const res = await response.json()
return res.budibase
}
async function checkIfKeysAndApps() {
const key = await fetchKeys()
const apps = await getApps()
if (key) {
hasKey = true
} else {
showCreateAppModal()
}
}
2020-05-26 10:38:43 +02:00
// Handle create app modal
const { open } = getContext("simple-modal")
2020-05-26 16:25:37 +02:00
2020-05-26 10:38:43 +02:00
const showCreateAppModal = () => {
open(
2020-05-26 16:25:37 +02:00
CreateAppModal,
2020-05-26 10:38:43 +02:00
{
2020-08-03 15:59:50 +02:00
hasKey,
2020-05-26 10:38:43 +02:00
},
{
closeButton: false,
closeOnEsc: false,
closeOnOuterClick: false,
2020-05-26 16:25:37 +02:00
styleContent: { padding: 0 },
2020-05-27 12:54:53 +02:00
closeOnOuterClick: true,
2020-05-26 10:38:43 +02:00
}
)
}
2020-08-03 15:59:50 +02:00
checkIfKeysAndApps()
2020-05-26 10:38:43 +02:00
</script>
<div class="header">
<div class="welcome">Welcome to the Budibase Beta</div>
2020-08-11 18:02:54 +02:00
<Button primary purple on:click={showCreateAppModal}>
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>
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>