Add AddStreamDialog

This commit is contained in:
Leon Grünewald 2024-09-02 03:20:52 +02:00
parent 306c84c6e0
commit 723b305064
3 changed files with 100 additions and 50 deletions

View file

@ -2,13 +2,14 @@
import { onMount } from "svelte"; import { onMount } from "svelte";
import Header from "./lib/Header.svelte"; import Header from "./lib/Header.svelte";
import Stream from "./lib/Stream.svelte"; import Stream from "./lib/Stream.svelte";
import AddStreamDialog from "./lib/AddStreamDialog.svelte";
let streams = []; let streams = $state([]);
let fracsX = 0; let fracsX = $state(0);
let fracsY = 0; let fracsY = $state(0);
let containerElement; let showButtons = $state(false);
let showButtons = false; let currentDialog = $state(null);
let showSettings = false; let containerElement = $state(null);
onMount(() => { onMount(() => {
const urlSearchParams = new URLSearchParams(window.location.search); const urlSearchParams = new URLSearchParams(window.location.search);
@ -16,7 +17,9 @@
type, type,
streamId, streamId,
})); }));
});
$effect(() => {
switch (streams.length) { switch (streams.length) {
case 1: case 1:
fracsX = 1; fracsX = 1;
@ -36,32 +39,37 @@
fracsY = 3; fracsY = 3;
} }
}); });
function onKeyDown() {}
</script> </script>
<svelte:body on:keydown={onKeyDown} />
<main> <main>
{#if containerElement} {#if containerElement}
<Header {containerElement} bind:showSettings /> <Header {containerElement} bind:currentDialog />
{/if} {/if}
{#if showSettings} {#if currentDialog === "add-stream"}
<div class="settings"> <AddStreamDialog
<h2>Settings</h2> add={(newStream) => {
<form> currentDialog = null;
<label> streams.push(newStream);
Stream const newUrl = new URL(window.location.toString());
<input type="text" name="url" /> newUrl.searchParams.append(newStream.type, newStream.streamId);
</label> window.history.pushState({}, null, newUrl);
<input type="submit" /> }}
</form> ></AddStreamDialog>
<div>
{#each streams as stream}
<button on:click={() => {}}>{stream.streamId}</button>
{/each}
</div>
</div>
{/if} {/if}
<!--{#if currentDialog === "remove-stream"}
<RemoveStreamDialog
remove={(streamId) => {
const searchParams = new URLSearchParams();
for (const stream of streams) {
searchParams.append(stream.type, stream.streamId);
}
const newUrl = new URL(window.location);
window.location.search = searchParams.toString();
}}
></AddStreamDialog>
{/if}-->
<div <div
bind:this={containerElement} bind:this={containerElement}
class="streams" class="streams"
@ -89,15 +97,4 @@
height: 100vh; height: 100vh;
width: 100vw; width: 100vw;
} }
.settings {
padding: 1rem;
background-color: #0000000a;
position: absolute;
width: 50vh;
height: 50vh;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
</style> </style>

View file

@ -0,0 +1,57 @@
<script>
let { add } = $props();
let step = $state(0);
let type = null;
let streamId = $state("doggoat");
</script>
<div class="add-stream-dialog">
{#if step === 0}
<div>
<h2>Add stream</h2>
<button
onclick={() => {
type = "vdo";
step = 1;
}}>vdo.ninja</button
>
<button
onclick={() => {
type = "twitch";
step = 1;
}}>Twitch</button
>
</div>
{/if}
{#if step === 1}
<div>
<p>
Example:<br />
https://vdo.ninja/?view=<strong>doggoat</strong
>&bitrate=4500&proaudio<br />
https://www.twitch.tv/<strong>saltybet</strong>
</p>
<label>Stream ID: <input bind:value={streamId} /></label>
<button
onclick={() => {
add({ type, streamId });
step = 0;
}}>Add</button
>
</div>
{/if}
</div>
<style>
.add-stream-dialog {
padding: 1rem;
background-color: #0000000a;
position: absolute;
width: 50vh;
height: 50vh;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
</style>

View file

@ -1,29 +1,25 @@
<script> <script>
let showButtons = false; let showButtons = $state(false);
export let showSettings; let {
export let containerElement; currentDialog = $bindable(null),
containerElement = $bindable(null),
} = $props();
</script> </script>
<header> <header>
<button <button
on:click={() => { onclick={() => {
showButtons = !showButtons; showButtons = !showButtons;
}}>[{showButtons ? "<" : ">"}]</button }}>[{showButtons ? "<" : ">"}]</button
> >
{#if showButtons} {#if showButtons}
<button <button
on:click={() => { onclick={() => {
showSettings = !showSettings; currentDialog = "add-stream";
}} }}
> >
Settings</button Add Stream</button
> >
<button
on:click={() => {
if (containerElement) containerElement.requestFullscreen();
}}>Fullscreen</button
>
<!--<button>Placeholder</button>-->
{/if} {/if}
</header> </header>