event-based routing?
This commit is contained in:
parent
e37c07adb4
commit
cee43342b9
@ -1,13 +1,33 @@
|
|||||||
<script>
|
<script>
|
||||||
import { emit, listen } from '@tauri-apps/api/event';
|
import { emit, listen } from '@tauri-apps/api/event';
|
||||||
|
import queue from './lib/queue.js';
|
||||||
import Home from './views/Home.svelte';
|
import Home from './views/Home.svelte';
|
||||||
import Approve from './views/Approve.svelte';
|
import Approve from './views/Approve.svelte';
|
||||||
|
import ShowApproved from './views/ShowApproved.svelte';
|
||||||
|
import ShowDenied from './views/ShowDenied.svelte';
|
||||||
|
|
||||||
let activeComponent = Home;
|
const VIEWS = {
|
||||||
|
Home: Home,
|
||||||
|
Approve: Approve,
|
||||||
|
ShowApproved: ShowApproved,
|
||||||
|
ShowDenied: ShowDenied,
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
let currentView = Home;
|
||||||
|
function navigate(event) {
|
||||||
|
currentView = VIEWS[event.detail.target];
|
||||||
|
}
|
||||||
|
|
||||||
listen('credentials-request', (event) => {
|
listen('credentials-request', (event) => {
|
||||||
activeComponent = Approve;
|
queue.put(1)
|
||||||
})
|
});
|
||||||
|
|
||||||
|
let requests = queue();
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<svelte:component this={activeComponent} />
|
{#if currentView === Home}
|
||||||
|
<svelte:component this={currentView} on:navigate={navigate} {requests} />
|
||||||
|
{:else}
|
||||||
|
<svelte:component this={currentView} on:navigate={navigate} />
|
||||||
|
{/if}
|
||||||
|
@ -2,17 +2,25 @@
|
|||||||
import { createEventDispatcher } from 'svelte';
|
import { createEventDispatcher } from 'svelte';
|
||||||
|
|
||||||
const dispatch = createEventDispatcher();
|
const dispatch = createEventDispatcher();
|
||||||
|
|
||||||
|
function approve() {
|
||||||
|
dispatch('navigate', {target: 'ShowApproved'});
|
||||||
|
}
|
||||||
|
|
||||||
|
function deny() {
|
||||||
|
dispatch('navigate', {target: 'ShowDenied'});
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<h2 class="text-3xl text-gray-200">An application would like to access your AWS credentials.</h2>
|
<h2 class="text-3xl text-gray-200">An application would like to access your AWS credentials.</h2>
|
||||||
|
|
||||||
<button on:click={() => dispatch('response', 'approved')}>
|
<button on:click={approve}>
|
||||||
<svg class="w-32 stroke-green-500" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="1">
|
<svg class="w-32 stroke-green-500" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="1">
|
||||||
<path stroke-linecap="round" stroke-linejoin="round" d="M9 12l2 2 4-4m6 2a9 9 0 11-18 0 9 9 0 0118 0z" />
|
<path stroke-linecap="round" stroke-linejoin="round" d="M9 12l2 2 4-4m6 2a9 9 0 11-18 0 9 9 0 0118 0z" />
|
||||||
</svg>
|
</svg>
|
||||||
</button>
|
</button>
|
||||||
|
|
||||||
<button on:click={() => dispatch('response', 'denied')}>
|
<button on:click={deny}>
|
||||||
<svg class="w-32 stroke-red-600" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="1">
|
<svg class="w-32 stroke-red-600" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="1">
|
||||||
<path stroke-linecap="round" stroke-linejoin="round" d="M10 14l2-2m0 0l2-2m-2 2l-2-2m2 2l2 2m7-2a9 9 0 11-18 0 9 9 0 0118 0z" />
|
<path stroke-linecap="round" stroke-linejoin="round" d="M10 14l2-2m0 0l2-2m-2 2l-2-2m2 2l2 2m7-2a9 9 0 11-18 0 9 9 0 0118 0z" />
|
||||||
</svg>
|
</svg>
|
||||||
|
@ -1 +1,12 @@
|
|||||||
|
<script>
|
||||||
|
import { createEventDispatcher } from 'svelte';
|
||||||
|
|
||||||
|
const dispatch = createEventDispatcher();
|
||||||
|
|
||||||
|
let requests;
|
||||||
|
let r = await requests.get();
|
||||||
|
|
||||||
|
dispatch('navigate', {target: 'Approve.svelte'});
|
||||||
|
</script>
|
||||||
|
|
||||||
<h1 class="text-4xl text-gray-300">Creddy</h1>
|
<h1 class="text-4xl text-gray-300">Creddy</h1>
|
7
src/views/ShowApproved.svelte
Normal file
7
src/views/ShowApproved.svelte
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
<script>
|
||||||
|
import { createEventDispatcher } from 'svelte';
|
||||||
|
const dispatch = createEventDispatcher();
|
||||||
|
window.setTimeout(() => dispatch('navigate', {target: 'Home'}), 3000);
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<h1 class="text-4xl text-gray-300">Approved!</h1>
|
7
src/views/ShowDenied.svelte
Normal file
7
src/views/ShowDenied.svelte
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
<script>
|
||||||
|
import { createEventDispatcher } from 'svelte';
|
||||||
|
const dispatch = createEventDispatcher();
|
||||||
|
window.setTimeout(() => dispatch('navigate', {target: 'Home'}), 3000);
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<h1 class="text-4xl text-gray-300">Denied!</h1>
|
Loading…
x
Reference in New Issue
Block a user