From 084131f9563d68056a24898c1302674391b0c7c7 Mon Sep 17 00:00:00 2001 From: Eric Zhang Date: Sat, 6 Apr 2024 17:12:11 -0400 Subject: [PATCH] Design updates (#82) * Adjust font weight * Settings refactor and scrollback * Fix embarrassing typo * Text in -> with --- src/lib/settings.ts | 39 ++++++++++++--- src/lib/ui/Avatars.svelte | 2 +- src/lib/ui/Chat.svelte | 2 +- src/lib/ui/ChooseName.svelte | 7 +-- src/lib/ui/LiveCursor.svelte | 2 +- src/lib/ui/NameList.svelte | 2 +- src/lib/ui/Settings.svelte | 97 +++++++++++++++++++++--------------- src/lib/ui/XTerm.svelte | 11 ++-- src/routes/+error.svelte | 2 +- src/routes/+page.svelte | 14 +++--- 10 files changed, 110 insertions(+), 68 deletions(-) diff --git a/src/lib/settings.ts b/src/lib/settings.ts index c5febe5..ad3dd8e 100644 --- a/src/lib/settings.ts +++ b/src/lib/settings.ts @@ -1,13 +1,40 @@ import { persisted } from "svelte-persisted-store"; -import { type ThemeName, defaultTheme } from "./ui/themes"; +import themes, { type ThemeName, defaultTheme } from "./ui/themes"; +import { derived, type Readable } from "svelte/store"; -export type SettingsStore = { +export type Settings = { name: string; theme: ThemeName; + scrollback: number; }; +const storedSettings = persisted>("sshx-settings-store", {}); + /** A persisted store for settings of the current user. */ -export const settings = persisted("sshx-settings-store", { - name: "", - theme: defaultTheme, -}); +export const settings: Readable = derived( + storedSettings, + ($storedSettings) => { + // Do some validation on all of the stored settings. + const name = $storedSettings.name ?? ""; + + let theme = $storedSettings.theme; + if (!theme || !Object.hasOwn(themes, theme)) { + theme = defaultTheme; + } + + let scrollback = $storedSettings.scrollback; + if (typeof scrollback !== "number" || scrollback < 0) { + scrollback = 5000; + } + + return { + name, + theme, + scrollback, + }; + }, +); + +export function updateSettings(values: Partial) { + storedSettings.update((settings) => ({ ...settings, ...values })); +} diff --git a/src/lib/ui/Avatars.svelte b/src/lib/ui/Avatars.svelte index 92f1904..f87dc0c 100644 --- a/src/lib/ui/Avatars.svelte +++ b/src/lib/ui/Avatars.svelte @@ -32,7 +32,7 @@ diff --git a/src/lib/ui/Chat.svelte b/src/lib/ui/Chat.svelte index 63203a6..c9df9d3 100644 --- a/src/lib/ui/Chat.svelte +++ b/src/lib/ui/Chat.svelte @@ -60,7 +60,7 @@ dispatch("close")} /> -
Chat Messages
+
Chat Messages
diff --git a/src/lib/ui/ChooseName.svelte b/src/lib/ui/ChooseName.svelte index 4a24a97..54d4db6 100644 --- a/src/lib/ui/ChooseName.svelte +++ b/src/lib/ui/ChooseName.svelte @@ -2,15 +2,12 @@ import { browser } from "$app/environment"; import OverlayMenu from "./OverlayMenu.svelte"; - import { settings } from "$lib/settings"; + import { settings, updateSettings } from "$lib/settings"; let value = ""; function handleSubmit() { - settings.update((curSettings) => ({ - ...curSettings, - name: value, - })); + updateSettings({ name: value }); } diff --git a/src/lib/ui/LiveCursor.svelte b/src/lib/ui/LiveCursor.svelte index 2ec32bd..b26aeb7 100644 --- a/src/lib/ui/LiveCursor.svelte +++ b/src/lib/ui/LiveCursor.svelte @@ -51,7 +51,7 @@ {#if showName || hovering || time - lastMove < 1500}

{user.name} diff --git a/src/lib/ui/NameList.svelte b/src/lib/ui/NameList.svelte index f4f03e6..732accb 100644 --- a/src/lib/ui/NameList.svelte +++ b/src/lib/ui/NameList.svelte @@ -15,7 +15,7 @@ class="w-3.5 h-3.5 rounded-full" />

{user.name}
diff --git a/src/lib/ui/Settings.svelte b/src/lib/ui/Settings.svelte index e12fa6a..8f7d2f5 100644 --- a/src/lib/ui/Settings.svelte +++ b/src/lib/ui/Settings.svelte @@ -1,32 +1,23 @@ @@ -39,33 +30,28 @@ >
-
-

Name

-

- Choose how you appear to other users. -

+
+

Name

+

Choose how you appear to other users.

{ - if (nameValue.length >= 2) { - settings.update((curSettings) => ({ - ...curSettings, - name: nameValue, - })); + if (inputName.length >= 2) { + updateSettings({ name: inputName }); } }} />
-
-

Color palette

-

Color theme for text in terminals.

+
+

Color palette

+

Color theme for text in terminals.

+
+
+

Scrollback

+

+ Lines of previous text displayed in the terminal window. +

+
+
+ { + if (inputScrollback >= 0) { + updateSettings({ scrollback: inputScrollback }); + } + }} + step="100" + /> +
+
@@ -104,6 +111,18 @@ @apply bg-zinc-800/25 rounded-lg p-4 flex gap-4 flex-col sm:flex-row items-start; } + .item > div:first-child { + @apply flex-1; + } + + .item-title { + @apply font-medium text-zinc-200 mb-1; + } + + .item-subtitle { + @apply text-sm text-zinc-400; + } + .input-common { @apply w-52 px-3 py-2 text-sm rounded-md bg-transparent hover:bg-white/5; @apply border border-zinc-700 outline-none focus:ring-2 focus:ring-indigo-500/50; diff --git a/src/lib/ui/XTerm.svelte b/src/lib/ui/XTerm.svelte index 8b7010c..19785d2 100644 --- a/src/lib/ui/XTerm.svelte +++ b/src/lib/ui/XTerm.svelte @@ -39,7 +39,7 @@ import type { Terminal } from "sshx-xterm"; import { Buffer } from "buffer"; - import themes, { defaultTheme } from "./themes"; + import themes from "./themes"; import CircleButton from "./CircleButton.svelte"; import CircleButtons from "./CircleButtons.svelte"; import { settings } from "$lib/settings"; @@ -67,13 +67,12 @@ export let termEl: HTMLDivElement = null as any; // suppress "missing prop" warning let term: Terminal | null = null; - $: theme = Object.hasOwn(themes, $settings.theme) - ? themes[$settings.theme] - : themes[defaultTheme]; + $: theme = themes[$settings.theme]; $: if (term) { // If the theme changes, update existing terminals' appearance. term.options.theme = theme; + term.options.scrollback = $settings.scrollback; } let loaded = false; @@ -140,7 +139,7 @@ fontWeight: 400, fontWeightBold: 500, lineHeight: 1.06, - scrollback: 5000, + scrollback: $settings.scrollback, theme, }); @@ -247,7 +246,7 @@
{currentTitle}
diff --git a/src/routes/+error.svelte b/src/routes/+error.svelte index e18d964..977e998 100644 --- a/src/routes/+error.svelte +++ b/src/routes/+error.svelte @@ -31,7 +31,7 @@ Return home diff --git a/src/routes/+page.svelte b/src/routes/+page.svelte index cde4414..281497c 100644 --- a/src/routes/+page.svelte +++ b/src/routes/+page.svelte @@ -97,7 +97,7 @@

- Get started in two quick steps + Get started with two quick steps

h1 { - @apply font-bold text-4xl sm:text-5xl max-w-[26ch] py-2; + @apply font-medium text-4xl sm:text-5xl max-w-[26ch] py-2 sm:tracking-tight; line-height: 1.15; } h2 { - @apply font-bold text-3xl sm:text-4xl md:text-center scroll-mt-16; + @apply font-medium text-3xl sm:text-4xl md:text-center scroll-mt-16; } b { - @apply text-zinc-300 font-semibold; + @apply text-zinc-300 font-medium; } code { @@ -296,7 +296,7 @@ } .feature-block h3 { - @apply font-semibold mb-2; + @apply font-medium mb-2; } .feature-block p { @@ -308,7 +308,7 @@ } .step-heading { - @apply text-2xl text-zinc-200 font-semibold flex items-center md:justify-center; + @apply text-2xl text-zinc-200 font-medium flex items-center md:justify-center; } .pill {