Skip to content

Commit

Permalink
Fix flash of "read-only" badge on initial page load (#106)
Browse files Browse the repository at this point in the history
  • Loading branch information
ekzhang authored Dec 30, 2024
1 parent ebdcbbd commit c94590c
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
11 changes: 5 additions & 6 deletions src/lib/Session.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -106,11 +106,13 @@
const chunknums: Record<number, number> = {};
const locks: Record<number, any> = {};
let userId = 0;
let hasWriteAccess: boolean | null = null;
let users: [number, WsUser][] = [];
let shells: [number, WsWinsize][] = [];
let subscriptions = new Set<number>();
// May be undefined before `users` is first populated.
$: hasWriteAccess = users.find(([uid]) => uid === userId)?.[1]?.canWrite;
let moving = -1; // Terminal ID that is being dragged.
let movingOrigin = [0, 0]; // Coordinates of mouse at origin when drag started.
let movingSize: WsWinsize; // New [x, y] position of the dragged terminal.
Expand Down Expand Up @@ -169,9 +171,6 @@
}
});
} else if (message.users) {
hasWriteAccess = message.users.some(
([uid, user]) => uid === userId && user.canWrite,
);
users = message.users;
} else if (message.userDiff) {
const [id, update] = message.userDiff;
Expand Down Expand Up @@ -264,7 +263,7 @@
let counter = 0n;
async function handleCreate() {
if (!hasWriteAccess) {
if (hasWriteAccess === false) {
makeToast({
kind: "info",
message: "You are in read-only mode and cannot create new terminals.",
Expand Down Expand Up @@ -466,7 +465,7 @@
{:else if connected}
<div class="flex items-center">
<div class="text-green-400">You are connected!</div>
{#if userId && !hasWriteAccess}
{#if userId && hasWriteAccess === false}
<div
class="bg-yellow-900 text-yellow-200 px-1 py-0.5 rounded ml-3 inline-flex items-center gap-1"
>
Expand Down
4 changes: 2 additions & 2 deletions src/lib/ui/Toolbar.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import logo from "$lib/assets/logo.svg";
export let connected: boolean;
export let hasWriteAccess: boolean | null;
export let hasWriteAccess: boolean | undefined;
export let newMessages: boolean;
const dispatch = createEventDispatcher<{
Expand All @@ -37,7 +37,7 @@
disabled={!connected || !hasWriteAccess}
title={!connected
? "Not connected"
: !hasWriteAccess
: hasWriteAccess === false // Only show the "No write access" title after confirming read-only mode.
? "No write access"
: "Create new terminal"}
>
Expand Down

0 comments on commit c94590c

Please sign in to comment.