1
0
mirror of https://github.com/garraflavatra/rolens.git synced 2025-01-19 13:27:58 +00:00
rolens/frontend/src/app.svelte

110 lines
2.7 KiB
Svelte
Raw Normal View History

2023-01-10 16:28:27 +00:00
<script>
2023-01-16 19:03:56 +00:00
import { onMount } from 'svelte';
import { Hosts, OpenConnection } from '../wailsjs/go/app/App';
2023-01-15 16:10:30 +00:00
import BlankState from './components/blankstate.svelte';
2023-01-16 19:03:56 +00:00
import ContextMenu from './components/contextmenu.svelte';
import AddressBar from './organisms/addressbar/index.svelte';
import Connection from './organisms/connection/index.svelte';
import { busy, contextMenu, connections } from './stores';
2023-01-10 16:28:27 +00:00
let hosts = {};
2023-01-16 15:56:16 +00:00
let environment;
2023-01-15 15:49:08 +00:00
2023-01-10 16:28:27 +00:00
let activeHostKey = '';
let activeDbKey = '';
let activeCollKey = '';
2023-01-15 15:49:08 +00:00
2023-01-11 19:41:15 +00:00
let addressBarModalOpen = true;
2023-01-10 16:28:27 +00:00
$: host = hosts[activeHostKey];
2023-01-16 19:03:56 +00:00
$: connection = $connections[activeHostKey];
2023-01-10 16:28:27 +00:00
$: database = connection?.databases[activeDbKey];
$: collection = database?.collections?.[activeCollKey];
async function openConnection(hostKey) {
2023-01-14 20:09:21 +00:00
busy.start();
2023-01-10 16:28:27 +00:00
const databases = await OpenConnection(hostKey);
if (databases) {
2023-01-16 19:03:56 +00:00
$connections[hostKey] = { databases: {} };
2023-01-10 16:28:27 +00:00
databases.forEach(dbKey => {
2023-01-16 19:03:56 +00:00
$connections[hostKey].databases[dbKey] = { collections: {} };
2023-01-10 16:28:27 +00:00
});
activeHostKey = hostKey;
addressBarModalOpen = false;
2023-01-16 19:03:56 +00:00
window.runtime.WindowSetTitle(`${hosts[activeHostKey].name} - Mongodup`);
2023-01-10 16:28:27 +00:00
}
2023-01-14 20:09:21 +00:00
busy.end();
2023-01-10 16:28:27 +00:00
}
onMount(() => {
2023-01-16 15:56:16 +00:00
window.runtime.Environment().then(e => environment = e);
2023-01-10 16:28:27 +00:00
Hosts().then(h => hosts = h);
});
</script>
2023-01-18 10:22:02 +00:00
<svelte:window on:contextmenu|preventDefault />
2023-01-16 15:56:16 +00:00
<div id="app" class="platform-{environment?.platform}">
2023-01-17 08:07:53 +00:00
<div class="titlebar"></div>
2023-01-16 15:56:16 +00:00
2023-01-17 08:07:53 +00:00
{#if environment}
2023-01-16 15:56:16 +00:00
<main class:empty={!host || !connection}>
<AddressBar {hosts} bind:activeHostKey on:select={e => openConnection(e.detail)} bind:modalOpen={addressBarModalOpen} />
{#if host && connection}
2023-01-16 19:03:56 +00:00
<Connection {hosts} bind:activeCollKey bind:activeDbKey {activeHostKey} />
2023-01-16 15:56:16 +00:00
{:else}
<BlankState label="A database client is nothing without a host" image="/fish.svg" />
{/if}
</main>
{#key $contextMenu}
<ContextMenu {...$contextMenu} on:close={contextMenu.hide} />
{/key}
2023-01-11 19:41:15 +00:00
{/if}
2023-01-16 15:56:16 +00:00
</div>
2023-01-14 19:38:39 +00:00
2023-01-10 16:28:27 +00:00
<style>
2023-01-16 19:03:56 +00:00
.titlebar {
height: 0;
background-color: #00002a;
2023-01-16 15:56:16 +00:00
--wails-draggable: drag;
2023-01-16 19:03:56 +00:00
}
#app.platform-darwin .titlebar {
2023-01-17 08:07:53 +00:00
height: var(--darwin-titlebar-height);
2023-01-16 15:56:16 +00:00
}
2023-01-10 16:28:27 +00:00
main {
height: 100vh;
2023-01-11 19:41:15 +00:00
display: grid;
grid-template: 3rem auto / 250px 1fr;
gap: 0.5rem;
padding: 0.5rem;
2023-01-10 16:28:27 +00:00
}
2023-01-16 15:56:16 +00:00
#app.platform-darwin main {
2023-01-17 08:07:53 +00:00
height: calc(100vh - var(--darwin-titlebar-height));
2023-01-16 15:56:16 +00:00
}
2023-01-15 16:10:30 +00:00
main.empty {
grid-template: 3rem auto / 1fr;
}
2023-01-17 15:22:49 +00:00
main > :global(*) {
overflow: auto;
min-height: 0;
min-width: 0;
}
2023-01-11 19:41:15 +00:00
main > :global(.addressbar) {
grid-column: 1 / 3;
2023-01-10 16:28:27 +00:00
}
2023-01-14 19:38:39 +00:00
.databaselist {
2023-01-10 19:10:39 +00:00
overflow: scroll;
2023-01-10 16:28:27 +00:00
}
2023-01-15 15:49:08 +00:00
.btn.create {
margin-top: 0.5rem;
}
2023-01-10 16:28:27 +00:00
</style>