Show a joined channel's web tab whichever reply comes first (closes #193) #196
+12
-3
@@ -858,14 +858,23 @@ function App() {
|
|||||||
method: "POST",
|
method: "POST",
|
||||||
body: JSON.stringify({ command: "JOIN", to: name }),
|
body: JSON.stringify({ command: "JOIN", to: name }),
|
||||||
});
|
});
|
||||||
|
// Show the channel's tab. Preact runs this update at once on the
|
||||||
|
// newest tab list, so the tab is found there by name: the user's
|
||||||
|
// own JOIN event may already have added it, and other tabs may
|
||||||
|
// have closed.
|
||||||
setTabs((prev) => {
|
setTabs((prev) => {
|
||||||
if (prev.find((t) => t.type === "channel" && t.name === name))
|
const idx = prev.findIndex(
|
||||||
|
(t) => t.type === "channel" && t.name === name,
|
||||||
|
);
|
||||||
|
if (idx >= 0) {
|
||||||
|
setActiveTab(idx);
|
||||||
|
|
||||||
return prev;
|
return prev;
|
||||||
|
}
|
||||||
|
setActiveTab(prev.length);
|
||||||
|
|
||||||
return [...prev, { type: "channel", name }];
|
return [...prev, { type: "channel", name }];
|
||||||
});
|
});
|
||||||
const newIdx = tabsRef.current.length;
|
|
||||||
setActiveTab(newIdx);
|
|
||||||
try {
|
try {
|
||||||
const hist = await api(
|
const hist = await api(
|
||||||
`/history?target=${encodeURIComponent(name)}&limit=50`,
|
`/history?target=${encodeURIComponent(name)}&limit=50`,
|
||||||
|
|||||||
Reference in New Issue
Block a user