Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix flash of "read-only" badge on initial page load #106

Merged
merged 1 commit into from
Dec 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading