Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
7280bf4
update rules
sawka Feb 19, 2026
4c6fd13
first cut at new block-tab based badge system
sawka Feb 20, 2026
51489eb
Merge remote-tracking branch 'origin/main' into sawka/block-indicators
sawka Mar 2, 2026
a75253f
run go generate, fix baseds import
sawka Mar 2, 2026
f7fda6a
Merge remote-tracking branch 'origin/main' into sawka/block-indicators
sawka Mar 5, 2026
f3d27e5
move indicators to their own file (badge.ts)
sawka Mar 5, 2026
95ec727
move tabindicatormap too
sawka Mar 5, 2026
ac7f295
move subscription to badge.ts, clean up some warnings
sawka Mar 5, 2026
e3aa0b8
clean up some warnings
sawka Mar 5, 2026
30788d0
setup FE badge store
sawka Mar 5, 2026
a7acdb9
working on badge integration
sawka Mar 5, 2026
f980494
add clearall for badge event
sawka Mar 5, 2026
260c767
add clearbyid
sawka Mar 5, 2026
c448ee7
add badgewatchpid
sawka Mar 5, 2026
f30f394
working on `wsh badge`
sawka Mar 5, 2026
a88c3bf
hook up pid watching to wsh badge command
sawka Mar 5, 2026
8d6f2ad
checkpoint on moving from tabiindicators to badges
sawka Mar 5, 2026
339cd6c
clear transient tab badges with focus as well
sawka Mar 5, 2026
ccf64e6
more badge migration
sawka Mar 5, 2026
498e0d9
remove tabindicators (backend+frontend), more badges
sawka Mar 6, 2026
09fed4e
getting the badges to show... up to 3 on a tab...
sawka Mar 6, 2026
2fb15c4
add flag color
sawka Mar 6, 2026
1806574
add context menu to flag tab...
sawka Mar 6, 2026
144db86
remove badge persistence
sawka Mar 6, 2026
820f535
focus should not clear pidlinked badges
sawka Mar 6, 2026
897f2d4
update tab bar, change flag to be a flag, resort badges
sawka Mar 6, 2026
c737c6e
Merge remote-tracking branch 'origin/main' into sawka/block-indicators
sawka Mar 6, 2026
e50de18
clean up some scss
sawka Mar 6, 2026
ddc9cff
remove ::after psudo element, just render the dividers in react
sawka Mar 6, 2026
9d1007d
dont use ctx in long running poller
sawka Mar 9, 2026
2518d31
fix nits
sawka Mar 9, 2026
dc2315d
fix nit
sawka Mar 9, 2026
64f6d4f
merge main
sawka Mar 9, 2026
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
Prev Previous commit
Next Next commit
focus should not clear pidlinked badges
  • Loading branch information
sawka committed Mar 6, 2026
commit 820f53548cb024027f60b892eda99a71f890153c
12 changes: 6 additions & 6 deletions frontend/app/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
// SPDX-License-Identifier: Apache-2.0

import {
clearTransientBadgeForTab,
clearTransientBadgesForBlock,
clearBadgesForBlockOnFocus,
clearBadgesForTabOnFocus,
getBadgeAtom,
getBlockBadgeAtom,
getTransientBadgeAtom,
} from "@/app/store/badge";
import { ClientModel } from "@/app/store/client-model";
import { GlobalModel } from "@/app/store/global-model";
Expand Down Expand Up @@ -222,7 +222,7 @@ const BadgeAutoClearing = () => {
const focusedNode = useAtomValue(layoutModel.focusedNode);
const focusedBlockId = focusedNode?.data?.blockId;
const badge = useAtomValue(getBlockBadgeAtom(focusedBlockId));
const tabTransientBadge = useAtomValue(getTransientBadgeAtom(tabId != null ? `tab:${tabId}` : null));
const tabTransientBadge = useAtomValue(getBadgeAtom(tabId != null ? `tab:${tabId}` : null));
const prevFocusedBlockIdRef = useRef<string>(null);
const prevDocHasFocusRef = useRef<boolean>(false);
const prevTabDocHasFocusRef = useRef<boolean>(false);
Expand All @@ -244,7 +244,7 @@ const BadgeAutoClearing = () => {
}
const currentFocusedNode = globalStore.get(layoutModel.focusedNode);
if (currentFocusedNode?.data?.blockId === focusedBlockId) {
clearTransientBadgesForBlock(focusedBlockId);
clearBadgesForBlockOnFocus(focusedBlockId);
}
}, delay);
return () => clearTimeout(timeoutId);
Expand All @@ -262,7 +262,7 @@ const BadgeAutoClearing = () => {
if (!document.hasFocus()) {
return;
}
clearTransientBadgeForTab(tabId);
clearBadgesForTabOnFocus(tabId);
}, delay);
return () => clearTimeout(timeoutId);
}, [tabId, tabTransientBadge, documentHasFocus]);
Expand Down
120 changes: 36 additions & 84 deletions frontend/app/store/badge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,47 +10,45 @@ import { globalStore } from "./jotaiStore";
import * as WOS from "./wos";
import { waveEventSubscribeSingle } from "./wps";

const PersistentBadgeMap = new Map<string, PrimitiveAtom<Badge>>();
const TransientBadgeMap = new Map<string, PrimitiveAtom<Badge>>();
const CombinedBadgeMap = new Map<string, Atom<Badge>>();
const BadgeMap = new Map<string, PrimitiveAtom<Badge>>();
const TabBadgeAtomCache = new Map<string, Atom<Badge[]>>();

function clearBadgeInternal(oref: string, persistent: boolean) {
function clearBadgeInternal(oref: string) {
const eventData: WaveEvent = {
event: "badge",
scopes: [oref],
data: {
oref: oref,
persistent: persistent,
clear: true,
} as BadgeEvent,
};
fireAndForget(() => RpcApi.EventPublishCommand(TabRpcClient, eventData));
}

function clearTransientBadgesForBlock(blockId: string) {
function clearBadgesForBlockOnFocus(blockId: string) {
const oref = WOS.makeORef("block", blockId);
const transientAtom = TransientBadgeMap.get(oref);
if (transientAtom != null && globalStore.get(transientAtom) != null) {
clearBadgeInternal(oref, false);
const badgeAtom = BadgeMap.get(oref);
const badge = badgeAtom != null ? globalStore.get(badgeAtom) : null;
if (badge != null && !badge.pidlinked) {
clearBadgeInternal(oref);
}
}

function clearTransientBadgeForTab(tabId: string) {
function clearBadgesForTabOnFocus(tabId: string) {
const oref = WOS.makeORef("tab", tabId);
const transientAtom = TransientBadgeMap.get(oref);
if (transientAtom != null && globalStore.get(transientAtom) != null) {
clearBadgeInternal(oref, false);
const badgeAtom = BadgeMap.get(oref);
const badge = badgeAtom != null ? globalStore.get(badgeAtom) : null;
if (badge != null && !badge.pidlinked) {
clearBadgeInternal(oref);
}
}

function clearAllBadges(persistent: boolean) {
function clearAllBadges() {
const eventData: WaveEvent = {
event: "badge",
scopes: [],
data: {
oref: "",
persistent: persistent,
clearall: true,
} as BadgeEvent,
};
Expand All @@ -63,39 +61,22 @@ function clearBadgesForTab(tabId: string) {
const blockIds = (tab as Tab)?.blockids ?? [];
for (const blockId of blockIds) {
const oref = WOS.makeORef("block", blockId);
const persistentAtom = PersistentBadgeMap.get(oref);
if (persistentAtom != null && globalStore.get(persistentAtom) != null) {
clearBadgeInternal(oref, true);
}
const transientAtom = TransientBadgeMap.get(oref);
if (transientAtom != null && globalStore.get(transientAtom) != null) {
clearBadgeInternal(oref, false);
const badgeAtom = BadgeMap.get(oref);
if (badgeAtom != null && globalStore.get(badgeAtom) != null) {
clearBadgeInternal(oref);
}
}
}

function getCombinedBadgeAtom(oref: string): Atom<Badge> {
let rtn = CombinedBadgeMap.get(oref);
if (rtn != null) {
return rtn;
function getBadgeAtom(oref: string): PrimitiveAtom<Badge> {
if (oref == null) {
return NullAtom as PrimitiveAtom<Badge>;
}
let rtn = BadgeMap.get(oref);
if (rtn == null) {
rtn = atom(null) as PrimitiveAtom<Badge>;
BadgeMap.set(oref, rtn);
}
const persistentAtom = getPersistentBadgeAtom(oref);
const transientAtom = getTransientBadgeAtom(oref);
rtn = atom((get) => {
const persistent = get(persistentAtom);
const transient = get(transientAtom);
if (persistent == null) {
return transient;
}
if (transient == null) {
return persistent;
}
if (transient.priority !== persistent.priority) {
return transient.priority > persistent.priority ? transient : persistent;
}
return transient.badgeid >= persistent.badgeid ? transient : persistent;
});
CombinedBadgeMap.set(oref, rtn);
return rtn;
}

Expand All @@ -104,7 +85,7 @@ function getBlockBadgeAtom(blockId: string): Atom<Badge> {
return NullAtom as Atom<Badge>;
}
const oref = WOS.makeORef("block", blockId);
return getCombinedBadgeAtom(oref);
return getBadgeAtom(oref);
}

function getTabBadgeAtom(tabId: string): Atom<Badge[]> {
Expand All @@ -116,19 +97,19 @@ function getTabBadgeAtom(tabId: string): Atom<Badge[]> {
return rtn;
}
const tabOref = WOS.makeORef("tab", tabId);
const tabTransientAtom = getTransientBadgeAtom(tabOref);
const tabBadgeAtom = getBadgeAtom(tabOref);
const tabAtom = atom((get) => WOS.getObjectValue<Tab>(tabOref, get));
rtn = atom((get) => {
const tab = get(tabAtom);
const blockIds = tab?.blockids ?? [];
const badges: Badge[] = [];
for (const blockId of blockIds) {
const badge = get(getCombinedBadgeAtom(WOS.makeORef("block", blockId)));
const badge = get(getBadgeAtom(WOS.makeORef("block", blockId)));
if (badge != null) {
badges.push(badge);
}
}
const tabBadge = get(tabTransientAtom);
const tabBadge = get(tabBadgeAtom);
if (tabBadge != null) {
badges.push(tabBadge);
}
Expand All @@ -144,27 +125,6 @@ function getTabBadgeAtom(tabId: string): Atom<Badge[]> {
return rtn;
}

function getPersistentBadgeAtom(oref: string): PrimitiveAtom<Badge> {
let rtn = PersistentBadgeMap.get(oref);
if (rtn == null) {
rtn = atom(null) as PrimitiveAtom<Badge>;
PersistentBadgeMap.set(oref, rtn);
}
return rtn;
}

function getTransientBadgeAtom(oref: string): PrimitiveAtom<Badge> {
if (oref == null) {
return NullAtom as PrimitiveAtom<Badge>;
}
let rtn = TransientBadgeMap.get(oref);
if (rtn == null) {
rtn = atom(null) as PrimitiveAtom<Badge>;
TransientBadgeMap.set(oref, rtn);
}
return rtn;
}

async function loadBadges() {
const badges = await RpcApi.GetAllBadgesCommand(TabRpcClient);
if (badges == null) {
Expand All @@ -174,13 +134,8 @@ async function loadBadges() {
if (badgeEvent.oref == null) {
continue;
}
if (badgeEvent.persistent) {
const curAtom = getPersistentBadgeAtom(badgeEvent.oref);
globalStore.set(curAtom, badgeEvent.badge ?? null);
} else {
const curAtom = getTransientBadgeAtom(badgeEvent.oref);
globalStore.set(curAtom, badgeEvent.badge ?? null);
}
const curAtom = getBadgeAtom(badgeEvent.oref);
globalStore.set(curAtom, badgeEvent.badge ?? null);
}
}

Expand All @@ -202,14 +157,13 @@ function setBadge(blockId: string, badge: Omit<Badge, "badgeid"> & { badgeid?: s
fireAndForget(() => RpcApi.EventPublishCommand(TabRpcClient, eventData));
}

function clearBadgeById(blockId: string, badgeId: string, persistent: boolean) {
function clearBadgeById(blockId: string, badgeId: string) {
const oref = WOS.makeORef("block", blockId);
const eventData: WaveEvent = {
event: "badge",
scopes: [oref],
data: {
oref: oref,
persistent: persistent,
clearbyid: badgeId,
} as BadgeEvent,
};
Expand All @@ -222,16 +176,15 @@ function setupBadgesSubscription() {
handler: (event) => {
const data = event.data;
if (data?.clearall) {
const map = data.persistent ? PersistentBadgeMap : TransientBadgeMap;
for (const atom of map.values()) {
for (const atom of BadgeMap.values()) {
globalStore.set(atom, null);
}
return;
}
if (data?.oref == null) {
return;
}
const curAtom = data.persistent ? getPersistentBadgeAtom(data.oref) : getTransientBadgeAtom(data.oref);
const curAtom = getBadgeAtom(data.oref);
if (data.clearbyid) {
const existing = globalStore.get(curAtom);
if (existing?.badgeid === data.clearbyid) {
Expand All @@ -247,13 +200,12 @@ function setupBadgesSubscription() {
export {
clearAllBadges,
clearBadgeById,
clearBadgesForBlockOnFocus,
clearBadgesForTab,
clearTransientBadgeForTab,
clearTransientBadgesForBlock,
clearBadgesForTabOnFocus,
getBadgeAtom,
getBlockBadgeAtom,
getPersistentBadgeAtom,
getTabBadgeAtom,
getTransientBadgeAtom,
loadBadges,
setBadge,
setupBadgesSubscription,
Expand Down