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

chore(weave): smart tab defaults w/ chat in call peek drawer #2823

Merged
merged 1 commit into from
Oct 30, 2024
Merged
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
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
Loading