Skip to content

Commit

Permalink
Add a dialog for users to choose their name
Browse files Browse the repository at this point in the history
  • Loading branch information
ekzhang committed Oct 7, 2023
1 parent be0fdd0 commit d14641e
Show file tree
Hide file tree
Showing 7 changed files with 163 additions and 87 deletions.
12 changes: 12 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"sshx-xterm": "5.2.1",
"svelte": "^3.59.2",
"svelte-feather-icons": "^4.0.1",
"svelte-persisted-store": "^0.7.0",
"xterm-addon-image": "^0.5.0",
"xterm-addon-web-links": "^0.9.0",
"xterm-addon-webgl": "^0.16.0"
Expand Down
3 changes: 3 additions & 0 deletions src/lib/Session.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import type { WsClient, WsServer, WsUser, WsWinsize } from "./protocol";
import { makeToast } from "./toast";
import Chat, { type ChatMessage } from "./ui/Chat.svelte";
import ChooseName from "./ui/ChooseName.svelte";
import NameList from "./ui/NameList.svelte";
import Settings from "./ui/Settings.svelte";
import Toolbar from "./ui/Toolbar.svelte";
Expand Down Expand Up @@ -359,6 +360,8 @@

<Settings open={settingsOpen} on:close={() => (settingsOpen = false)} />

<ChooseName />

<!--
Dotted circle background appears underneath the rest of the elements, but
moves and zooms with the fabric of the canvas.
Expand Down
10 changes: 10 additions & 0 deletions src/lib/settings.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { persisted } from "svelte-persisted-store";

export type SettingsStore = {
name: string;
};

/** A persisted store for settings of the current user. */
export const settings = persisted<SettingsStore>("sshx-settings-store", {
name: "",
});
33 changes: 33 additions & 0 deletions src/lib/ui/ChooseName.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<script lang="ts">
import { browser } from "$app/environment";
import OverlayMenu from "./OverlayMenu.svelte";
import { settings } from "$lib/settings";
let value = "";
function handleSubmit() {
settings.set({ ...settings, name: value });
}
</script>

<OverlayMenu
title="Welcome!"
description="Before you join — what should we call you?"
maxWidth={640}
open={browser && !$settings.name}
>
<form class="flex gap-2" on:submit|preventDefault={handleSubmit}>
<input
class="flex-1 w-full px-3 py-2 rounded outline-none text-gray-300 bg-zinc-800"
placeholder="Your name"
required
minlength="2"
bind:value
/>
<button
class="flex-shrink-0 px-3 py-2 bg-pink-700 hover:bg-pink-600 active:ring-4 active:ring-pink-500/50 rounded font-medium"
>Join</button
>
</form>
</OverlayMenu>
63 changes: 63 additions & 0 deletions src/lib/ui/OverlayMenu.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<script lang="ts">
import {
Dialog,
DialogDescription,
DialogOverlay,
DialogTitle,
Transition,
TransitionChild,
} from "@rgossiaux/svelte-headlessui";
import { XIcon } from "svelte-feather-icons";
import { createEventDispatcher } from "svelte";
const dispatch = createEventDispatcher<{ close: void }>();
export let title: string;
export let description: string;
export let showCloseButton = false;
export let maxWidth: number = 768; // screen-md
export let open: boolean;
</script>

<Transition show={open}>
<Dialog on:close class="fixed inset-0 z-50 grid place-items-center">
<DialogOverlay class="fixed -z-10 inset-0 bg-black/20 backdrop-blur-sm" />

<TransitionChild
enter="duration-300 ease-out"
enterFrom="scale-95 opacity-0"
enterTo="scale-100 opacity-100"
leave="duration-75 ease-out"
leaveFrom="scale-200 opacity-100"
leaveTo="scale-95 opacity-0"
class="w-full sm:w-[calc(100%-32px)]"
style="max-width: {maxWidth}px"
>
<div
class="relative bg-[#111] sm:border border-zinc-800 px-6 py-10 sm:py-6
h-screen sm:h-auto max-h-screen sm:rounded-lg overflow-y-auto"
>
{#if showCloseButton}
<button
class="absolute top-4 right-4 p-1 rounded hover:bg-zinc-700 active:bg-indigo-700 transition-colors"
aria-label="Close settings"
on:click={() => dispatch("close")}
>
<XIcon class="h-5 w-5" />
</button>
{/if}

<div class="mb-8 text-center">
<DialogTitle class="text-xl font-medium mb-2">
{title}
</DialogTitle>
<DialogDescription class="text-zinc-400">
{description}
</DialogDescription>
</div>

<slot />
</div>
</TransitionChild>
</Dialog>
</Transition>
128 changes: 41 additions & 87 deletions src/lib/ui/Settings.svelte
Original file line number Diff line number Diff line change
@@ -1,97 +1,51 @@
<script lang="ts">
import {
Dialog,
DialogDescription,
DialogOverlay,
DialogTitle,
Transition,
TransitionChild,
} from "@rgossiaux/svelte-headlessui";
import { XIcon } from "svelte-feather-icons";
import { createEventDispatcher } from "svelte";
const dispatch = createEventDispatcher<{ close: void }>();
import OverlayMenu from "./OverlayMenu.svelte";
export let open: boolean;
</script>

<Transition show={open}>
<Dialog on:close class="fixed inset-0 z-50 grid place-items-center">
<DialogOverlay class="fixed -z-10 inset-0 bg-black/20 backdrop-blur-sm" />

<TransitionChild
enter="duration-300 ease-out"
enterFrom="scale-95 opacity-0"
enterTo="scale-100 opacity-100"
leave="duration-75 ease-out"
leaveFrom="scale-200 opacity-100"
leaveTo="scale-95 opacity-0"
class="w-full sm:w-[calc(100%-32px)] max-w-screen-md"
>
<div
class="relative bg-[#111] sm:border border-zinc-800 px-6 py-10 sm:py-6
h-screen sm:h-auto max-h-screen sm:rounded-lg overflow-y-auto"
>
<button
class="absolute top-4 right-4 p-1 rounded hover:bg-zinc-700 active:bg-indigo-700 transition-colors"
aria-label="Close settings"
on:click={() => dispatch("close")}
>
<XIcon class="h-5 w-5" />
</button>

<div class="mb-8 text-center">
<DialogTitle class="text-xl font-medium mb-2">
Terminal Settings
</DialogTitle>
<DialogDescription class="text-zinc-400">
Customize your collaborative terminal.
</DialogDescription>
</div>

<div class="flex flex-col gap-2">
<div class="item">
<div class="flex-1">
<p class="font-medium mb-2">Name</p>
<p class="text-sm text-zinc-400">
How you appear to other users online.
</p>
</div>
<div class="text-red-500">TODO</div>
</div>
<div class="item">
<div class="flex-1">
<p class="font-medium mb-2">Color palette</p>
<p class="text-sm text-zinc-400">
Color scheme for text in terminals.
</p>
</div>
<div class="text-red-500">TODO</div>
</div>
<div class="item">
<div class="flex-1">
<p class="font-medium mb-2">Cursor style</p>
<p class="text-sm text-zinc-400">
How live cursors should be displayed.
</p>
</div>
<div class="text-red-500">TODO</div>
</div>
</div>

<!-- svelte-ignore missing-declaration -->
<p class="mt-6 text-sm text-right text-zinc-400">
<a
target="_blank"
rel="noreferrer"
href="https://github.com/ekzhang/sshx"
>sshx-server v{__APP_VERSION__}</a
>
<OverlayMenu
title="Terminal Settings"
description="Customize your collaborative terminal."
showCloseButton
{open}
on:close
>
<div class="flex flex-col gap-2">
<div class="item">
<div class="flex-1">
<p class="font-medium mb-2">Name</p>
<p class="text-sm text-zinc-400">
How you appear to other users online.
</p>
</div>
</TransitionChild>
</Dialog>
</Transition>
<div class="text-red-500">TODO</div>
</div>
<div class="item">
<div class="flex-1">
<p class="font-medium mb-2">Color palette</p>
<p class="text-sm text-zinc-400">Color scheme for text in terminals.</p>
</div>
<div class="text-red-500">TODO</div>
</div>
<div class="item">
<div class="flex-1">
<p class="font-medium mb-2">Cursor style</p>
<p class="text-sm text-zinc-400">
How live cursors should be displayed.
</p>
</div>
<div class="text-red-500">TODO</div>
</div>
</div>

<!-- svelte-ignore missing-declaration -->
<p class="mt-6 text-sm text-right text-zinc-400">
<a target="_blank" rel="noreferrer" href="https://github.com/ekzhang/sshx"
>sshx-server v{__APP_VERSION__}</a
>
</p>
</OverlayMenu>

<style lang="postcss">
.item {
Expand Down

0 comments on commit d14641e

Please sign in to comment.