Skip to content

Commit

Permalink
chore(weave): smart tab defaults w/ chat in call peek drawer
Browse files Browse the repository at this point in the history
  • Loading branch information
gtarpenning committed Oct 30, 2024
1 parent baceec7 commit 8c30a00
Showing 1 changed file with 13 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -176,16 +176,28 @@ export const SimplePageLayoutWithHeader: FC<{
// We try to preserve the selected tab even if the set of tabs changes,
// falling back to the first tab.
const [tabId, setTabId] = useState(tabs[0].label);
// If the user has manually selected a tab, always keep that tab selected
// otherwise, always default to the leftmost tab. Some calls have chat
// tabs, others do not, so unless the user has explicitly selected a different
// tab, always show the chat tab when possible.
const [userSelectedTab, setUserSelectedTab] = useState(false);
const idxSelected = tabs.findIndex(t => t.label === tabId);
const tabValue = idxSelected !== -1 ? idxSelected : 0;
const handleTabChange = (newValue: string) => {
setTabId(newValue);
setUserSelectedTab(true);
};
useEffect(() => {
if (idxSelected === -1) {
setTabId(tabs[0].label);
setUserSelectedTab(false);
} else if (!userSelectedTab && idxSelected === 1) {
// User has not selected a tab, but the current tab is not the leftmost tab.
// Default to the leftmost.
// Example: view call w/o chat [tab='call'] -> view call w/ chat [tab='call']
setTabId(tabs[0].label);
}
}, [tabs, idxSelected]);
}, [tabs, idxSelected, userSelectedTab]);
const tabContent = useMemo(() => tabs[tabValue].content, [tabs, tabValue]);

return (
Expand Down

0 comments on commit 8c30a00

Please sign in to comment.