Skip to content

The open alternative to Salesforce, designed for AI.

Turn the mobile bottom bar into the home page's tab bar (#24232)

Félix Malfaitda6ab4a3de6c
diff --git a/packages/twenty-front/src/modules/ai/components/AiChatEditorSection.tsx b/packages/twenty-front/src/modules/ai/components/AiChatEditorSection.tsx
index 199058c621d..3c9d6bea73d 100644
--- a/packages/twenty-front/src/modules/ai/components/AiChatEditorSection.tsx
+++ b/packages/twenty-front/src/modules/ai/components/AiChatEditorSection.tsx
@@ -50,7 +50,7 @@ const StyledInputBox = styled.div<{ isMobile: boolean }>`
display: flex;
flex-direction: column;
gap: ${themeCssVariables.spacing[2]};
- min-height: ${({ isMobile }) => (isMobile ? '88px' : '140px')};
+ min-height: ${({ isMobile }) => (isMobile ? 'auto' : '140px')};
padding: ${themeCssVariables.spacing[2]};
width: 100%;
@@ -76,7 +76,7 @@ const StyledEditorWrapper = styled.div<{ isMobile: boolean }>`
font-weight: ${themeCssVariables.font.weight.regular};
line-height: 16px;
max-height: ${({ isMobile }) => (isMobile ? '160px' : '320px')};
- min-height: ${({ isMobile }) => (isMobile ? '36px' : '48px')};
+ min-height: ${({ isMobile }) => (isMobile ? 'auto' : '48px')};
outline: none;
overflow-y: auto;
padding: 0;
diff --git a/packages/twenty-front/src/modules/ai/components/MobileHomeAiChatSection.tsx b/packages/twenty-front/src/modules/ai/components/MobileHomeAiChatSection.tsx
new file mode 100644
index 00000000000..9275cffebfb
--- /dev/null
+++ b/packages/twenty-front/src/modules/ai/components/MobileHomeAiChatSection.tsx
@@ -0,0 +1,39 @@
+import { AiChatThreadDeleteConfirmationModal } from '@/ai/components/AiChatThreadDeleteConfirmationModal';
+import { NavigationDrawerAiChatThreadSection } from '@/ai/components/NavigationDrawerAiChatThreadSection';
+import { AI_CHAT_THREAD_ACTIONS_SURFACE } from '@/ai/constants/AiChatThreadActionsSurface';
+import { useAiChatThreadClick } from '@/ai/hooks/useAiChatThreadClick';
+import { useChatThreads } from '@/ai/hooks/useChatThreads';
+import { currentAiChatThreadState } from '@/ai/states/currentAiChatThreadState';
+import { useAtomStateValue } from '@/ui/utilities/state/jotai/hooks/useAtomStateValue';
+import { useLingui } from '@lingui/react/macro';
+
+const MOBILE_HOME_AI_CHAT_SECTION_ID = 'MobileHomeAiChat';
+
+export const MobileHomeAiChatSection = () => {
+ const { t } = useLingui();
+
+ const currentAiChatThread = useAtomStateValue(currentAiChatThreadState);
+ const { handleThreadClick } = useAiChatThreadClick({
+ resetNavigationStack: true,
+ });
+ const { threads } = useChatThreads();
+
+ if (threads.length === 0) {
+ return null;
+ }
+
+ return (
+ <>
+ <NavigationDrawerAiChatThreadSection
+ sectionId={MOBILE_HOME_AI_CHAT_SECTION_ID}
+ title={t`Conversations`}
+ threads={threads}
+ currentThreadId={currentAiChatThread}
+ onThreadClick={handleThreadClick}
+ />
+ <AiChatThreadDeleteConfirmationModal
+ surface={AI_CHAT_THREAD_ACTIONS_SURFACE.NAV_DRAWER}
+ />
+ </>
+ );
+};
diff --git a/packages/twenty-front/src/modules/navigation/components/MainNavigationDrawerNavigationContent.tsx b/packages/twenty-front/src/modules/navigation/components/MainNavigationDrawerNavigationContent.tsx
index f0dc6890449..145e241a8cd 100644
--- a/packages/twenty-front/src/modules/navigation/components/MainNavigationDrawerNavigationContent.tsx
+++ b/packages/twenty-front/src/modules/navigation/components/MainNavigationDrawerNavigationContent.tsx
@@ -1,16 +1,9 @@
-import { styled } from '@linaria/react';
-
import { NavigationMenuItemFolderContentDispatcherEffect } from '@/navigation-menu-item/edit/components/NavigationMenuItemFolderContentDispatcher';
import { useNavigationMenuItemsByFolder } from '@/navigation-menu-item/display/folder/hooks/useNavigationMenuItemsByFolder';
import { MainNavigationDrawerScrollableItems } from '@/navigation/components/MainNavigationDrawerScrollableItems';
import { currentNavigationMenuItemFolderIdState } from '@/navigation-menu-item/common/states/currentNavigationMenuItemFolderIdState';
import { useAtomStateValue } from '@/ui/utilities/state/jotai/hooks/useAtomStateValue';
-const StyledScrollableContent = styled.div`
- height: 100%;
- min-height: 0;
-`;
-
export const MainNavigationDrawerNavigationContent = () => {
const currentNavigationMenuItemFolderId = useAtomStateValue(
currentNavigationMenuItemFolderIdState,
@@ -22,7 +15,7 @@ export const MainNavigationDrawerNavigationContent = () => {
);
return (
- <StyledScrollableContent>
+ <>
{openedNavigationMenuItemFolder ? (
<NavigationMenuItemFolderContentDispatcherEffect
folderName={openedNavigationMenuItemFolder.folderName}
@@ -34,6 +27,6 @@ export const MainNavigationDrawerNavigationContent = () => {
) : (
<MainNavigationDrawerScrollableItems />
)}
- </StyledScrollableContent>
+ </>
);
};
diff --git a/packages/twenty-front/src/modules/navigation/components/MobileHomeTabsRow.tsx b/packages/twenty-front/src/modules/navigation/components/MobileHomeTabsRow.tsx
deleted file mode 100644
index 546af1a742b..00000000000
--- a/packages/twenty-front/src/modules/navigation/components/MobileHomeTabsRow.tsx
+++ /dev/null
@@ -1,180 +0,0 @@
-import { useHasPermissionFlag } from '@/settings/roles/hooks/useHasPermissionFlag';
-import { navigationDrawerActiveTabState } from '@/ui/navigation/states/navigationDrawerActiveTabState';
-import {
- type NavigationDrawerActiveTab,
- NAVIGATION_DRAWER_TABS,
-} from '@/ui/navigation/states/navigationDrawerTabs';
-import { useAtomState } from '@/ui/utilities/state/jotai/hooks/useAtomState';
-import { styled } from '@linaria/react';
-import { useLingui } from '@lingui/react/macro';
-import { useContext } from 'react';
-import {
- type IconComponent,
- IconComment,
- IconHome,
- IconSettings,
-} from 'twenty-ui/icon';
-import { isDefined } from 'twenty-shared/utils';
-import { ThemeContext, themeCssVariables } from 'twenty-ui/theme-constants';
-import { PermissionFlagType } from '~/generated-metadata/graphql';
-
-const StyledPill = styled.div`
- align-items: center;
- background: ${themeCssVariables.background.secondary};
- border: 1px solid ${themeCssVariables.border.color.medium};
- border-radius: ${themeCssVariables.border.radius.pill};
- box-sizing: border-box;
- corner-shape: round;
- display: flex;
- gap: ${themeCssVariables.spacing[0.5]};
- height: ${themeCssVariables.spacing[8]};
- max-width: 100%;
- padding: 3px;
- width: max-content;
-`;
-
-const StyledTab = styled.div<{ isActive: boolean }>`
- align-items: center;
- background: ${({ isActive }) =>
- isActive ? themeCssVariables.background.transparent.light : 'transparent'};
- border-radius: ${themeCssVariables.border.radius.pill};
- color: ${({ isActive }) =>
- isActive
- ? themeCssVariables.font.color.primary
- : themeCssVariables.font.color.tertiary};
- corner-shape: round;
- cursor: pointer;
- display: flex;
- font-size: ${themeCssVariables.font.size.sm};
- font-weight: ${themeCssVariables.font.weight.medium};
- gap: ${themeCssVariables.spacing[1]};
- height: 100%;
- justify-content: center;
- padding-inline: ${({ isActive }) =>
- isActive ? themeCssVariables.spacing[3] : themeCssVariables.spacing[2]};
- white-space: nowrap;
-
- &:hover {
- background: ${({ isActive }) =>
- isActive
- ? themeCssVariables.background.transparent.light
- : themeCssVariables.background.transparent.lighter};
- }
-`;
-
-const StyledTabIcon = styled.div`
- align-items: center;
- display: flex;
- flex-shrink: 0;
- justify-content: center;
-`;
-
-export const MobileHomeTabsRow = () => {
- const { t } = useLingui();
- const { theme } = useContext(ThemeContext);
- const [navigationDrawerActiveTab, setNavigationDrawerActiveTab] =
- useAtomState(navigationDrawerActiveTabState);
- const hasAiPermission = useHasPermissionFlag(PermissionFlagType.AI);
-
- const tabs: {
- tab: NavigationDrawerActiveTab;
- label: string;
- Icon: IconComponent;
- }[] = [
- {
- tab: NAVIGATION_DRAWER_TABS.NAVIGATION_MENU,
- label: t`Home`,
- Icon: IconHome,
- },
- ...(hasAiPermission
- ? [
- {
- tab: NAVIGATION_DRAWER_TABS.AI_CHAT_HISTORY,
- label: t`Chat`,
- Icon: IconComment,
- },
- ]
- : []),
- {
- tab: NAVIGATION_DRAWER_TABS.SETTINGS,
- label: t`Settings`,
- Icon: IconSettings,
- },
- ];
-
- // Only the selected tab is in the tab order, so the arrow, Home and End keys
- // are the only way to reach the others from the keyboard.
- const getTabIndexForKey = (key: string, currentIndex: number) => {
- if (key === 'ArrowRight') {
- return (currentIndex + 1) % tabs.length;
- }
- if (key === 'ArrowLeft') {
- return (currentIndex - 1 + tabs.length) % tabs.length;
- }
- if (key === 'Home') {
- return 0;
- }
- if (key === 'End') {
- return tabs.length - 1;
- }
- return null;
- };
-
- const handleTabKeyDown =
- (currentIndex: number) => (event: React.KeyboardEvent<HTMLDivElement>) => {
- if (event.key === 'Enter' || event.key === ' ') {
- event.preventDefault();
- setNavigationDrawerActiveTab(tabs[currentIndex].tab);
- return;
- }
-
- const nextIndex = getTabIndexForKey(event.key, currentIndex);
-
- if (!isDefined(nextIndex)) {
- return;
- }
-
- event.preventDefault();
- setNavigationDrawerActiveTab(tabs[nextIndex].tab);
-
- const nextTabElement =
- event.currentTarget.parentElement?.children[nextIndex];
-
- if (nextTabElement instanceof HTMLElement) {
- nextTabElement.focus();
- }
- };
-
- return (
- <StyledPill role="tablist" aria-label={t`Navigation tabs`}>
- {tabs.map(({ tab, label, Icon }, index) => {
- const isActive = navigationDrawerActiveTab === tab;
-
- return (
- <StyledTab
- key={tab}
- isActive={isActive}
- role="tab"
- aria-selected={isActive}
- aria-label={label}
- tabIndex={isActive ? 0 : -1}
- onClick={() => setNavigationDrawerActiveTab(tab)}
- onKeyDown={handleTabKeyDown(index)}
- >
- <StyledTabIcon>
- <Icon
- size={theme.icon.size.md}
- color={
- isActive
- ? theme.font.color.primary
- : theme.font.color.tertiary
- }
- />
- </StyledTabIcon>
- {isActive && label}
- </StyledTab>
- );
- })}
- </StyledPill>
- );
-};
diff --git a/packages/twenty-front/src/modules/navigation/components/MobileNavigationBar.tsx b/packages/twenty-front/src/modules/navigation/components/MobileNavigationBar.tsx
index 8a67a141e05..4891eb6cd0b 100644
--- a/packages/twenty-front/src/modules/navigation/components/MobileNavigationBar.tsx
+++ b/packages/twenty-front/src/modules/navigation/components/MobileNavigationBar.tsx
@@ -1,178 +1,46 @@
-import { useLingui } from '@lingui/react/macro';
-
-import { useSwitchToNewAiChat } from '@/ai/hooks/useSwitchToNewAiChat';
-import { MAIN_CONTEXT_STORE_INSTANCE_ID } from '@/context-store/constants/MainContextStoreInstanceId';
-import { contextStoreCurrentObjectMetadataItemIdComponentState } from '@/context-store/states/contextStoreCurrentObjectMetadataItemIdComponentState';
import { MobileNavigationBarScrollEffect } from '@/navigation/components/MobileNavigationBarScrollEffect';
-import { useIsSettingsDrawer } from '@/navigation/hooks/useIsSettingsDrawer';
-import { useIsSettingsPage } from '@/navigation/hooks/useIsSettingsPage';
+import { useMobileNavigationBarItems } from '@/navigation/hooks/useMobileNavigationBarItems';
import { isMobileNavigationBarVisibleState } from '@/navigation/states/isMobileNavigationBarVisibleState';
-import { useFilteredObjectMetadataItems } from '@/object-metadata/hooks/useFilteredObjectMetadataItems';
-import { useHasPermissionFlag } from '@/settings/roles/hooks/useHasPermissionFlag';
-import { useOpenRecordsSearchPageInSidePanel } from '@/side-panel/hooks/useOpenRecordsSearchPageInSidePanel';
-import { useSidePanelMenu } from '@/side-panel/hooks/useSidePanelMenu';
import { isSidePanelOpenedState } from '@/side-panel/states/isSidePanelOpenedState';
import { RootStackingContextZIndices } from '@/ui/layout/constants/RootStackingContextZIndices';
-import { currentMobileNavigationDrawerState } from '@/navigation/states/currentMobileNavigationDrawerState';
-import { isNavigationDrawerExpandedState } from '@/ui/navigation/states/isNavigationDrawerExpanded';
-import { useSetAtomComponentState } from '@/ui/utilities/state/jotai/hooks/useSetAtomComponentState';
-import { useSetAtomState } from '@/ui/utilities/state/jotai/hooks/useSetAtomState';
import { useAtomStateValue } from '@/ui/utilities/state/jotai/hooks/useAtomStateValue';
import { styled } from '@linaria/react';
-import { useLocation, useNavigate } from 'react-router-dom';
-import { AppPath } from 'twenty-shared/types';
-import {
- type IconComponent,
- IconHome,
- IconMessageCirclePlus,
- IconSearch,
-} from 'twenty-ui/icon';
import { NavigationBar } from 'twenty-ui/navigation';
import { themeCssVariables } from 'twenty-ui/theme-constants';
-import { PermissionFlagType } from '~/generated-metadata/graphql';
-
-type NavigationBarItemName = 'home' | 'search' | 'newAiChat';
-// The bar floats over the page, so the container has to let taps through to
-// whatever is scrolling underneath it. flex-start rather than left so the bar
-// follows the writing direction in RTL locales.
-const StyledFloatingContainer = styled.div`
- bottom: 0;
+const StyledBarContainer = styled.div`
display: flex;
- justify-content: flex-start;
- left: 0;
+ flex-shrink: 0;
padding: ${themeCssVariables.spacing[3]};
padding-bottom: calc(
${themeCssVariables.spacing[3]} + env(safe-area-inset-bottom, 0px)
);
- pointer-events: none;
- position: absolute;
- right: 0;
z-index: ${RootStackingContextZIndices.MobileNavigationBar};
- > * {
- pointer-events: auto;
- }
-
@media print {
display: none;
}
`;
export const MobileNavigationBar = () => {
- const { t } = useLingui();
- const navigate = useNavigate();
- const { pathname } = useLocation();
const isSidePanelOpened = useAtomStateValue(isSidePanelOpenedState);
- const { closeSidePanelMenu } = useSidePanelMenu();
- const { openRecordsSearchPage } = useOpenRecordsSearchPageInSidePanel();
- const isSettingsPage = useIsSettingsPage();
- const isSettingsDrawer = useIsSettingsDrawer();
- const { switchToNewChat } = useSwitchToNewAiChat();
- const { alphaSortedActiveNonSystemObjectMetadataItems } =
- useFilteredObjectMetadataItems();
- const hasAiPermission = useHasPermissionFlag(PermissionFlagType.AI);
const isMobileNavigationBarVisible = useAtomStateValue(
isMobileNavigationBarVisibleState,
);
+ const { items, activeItemName } = useMobileNavigationBarItems();
- const setContextStoreCurrentObjectMetadataItemId = useSetAtomComponentState(
- contextStoreCurrentObjectMetadataItemIdComponentState,
- MAIN_CONTEXT_STORE_INSTANCE_ID,
- );
- const setCurrentMobileNavigationDrawer = useSetAtomState(
- currentMobileNavigationDrawerState,
- );
- const setIsNavigationDrawerExpanded = useSetAtomState(
- isNavigationDrawerExpandedState,
- );
-
- // Settings is the one drawer left on mobile, and it stays open across
- // navigation, so it would cover whatever the bottom bar goes to. Guarded so a
- // tap outside settings leaves the persisted expansion alone: it is shared with
- // the desktop drawer, which every tap would otherwise collapse.
- const closeSettingsDrawer = () => {
- if (!isSettingsDrawer) {
- return;
- }
-
- setCurrentMobileNavigationDrawer('main');
- setIsNavigationDrawerExpanded(false);
- };
-
- const isHomePage = pathname === AppPath.Home;
-
- // The side panel is full screen on mobile, so the bar would be floating over
- // a view it does not navigate. It comes back when the panel closes.
const isHidden = isSidePanelOpened || !isMobileNavigationBarVisible;
- const activeItemName: NavigationBarItemName | undefined = isHomePage
- ? 'home'
- : undefined;
-
- const items: {
- name: NavigationBarItemName;
- label: string;
- Icon: IconComponent;
- onClick: () => void;
- }[] = [
- {
- name: 'home',
- label: t`Home`,
- Icon: IconHome,
- onClick: () => {
- closeSidePanelMenu();
- closeSettingsDrawer();
- navigate(AppPath.Home);
- },
- },
- {
- name: 'search',
- label: t`Search`,
- Icon: IconSearch,
- onClick: () => {
- closeSidePanelMenu();
- closeSettingsDrawer();
-
- if (isSettingsPage) {
- const firstObjectMetadataItem =
- alphaSortedActiveNonSystemObjectMetadataItems[0];
- if (firstObjectMetadataItem !== undefined) {
- setContextStoreCurrentObjectMetadataItemId(
- firstObjectMetadataItem.id,
- );
- }
- }
-
- openRecordsSearchPage();
- },
- },
- ...(hasAiPermission
- ? [
- {
- name: 'newAiChat' as const,
- label: t`New AI chat`,
- Icon: IconMessageCirclePlus,
- onClick: () => {
- closeSidePanelMenu();
- closeSettingsDrawer();
- switchToNewChat();
- },
- },
- ]
- : []),
- ];
-
return (
<>
<MobileNavigationBarScrollEffect />
- <StyledFloatingContainer>
+ <StyledBarContainer>
<NavigationBar
- activeItemName={activeItemName ?? ''}
+ activeItemName={activeItemName}
isHidden={isHidden}
items={items}
/>
- </StyledFloatingContainer>
+ </StyledBarContainer>
</>
);
};
diff --git a/packages/twenty-front/src/modules/navigation/components/SettingsNavigationDrawer.tsx b/packages/twenty-front/src/modules/navigation/components/SettingsNavigationDrawer.tsx
index 4a41b705cba..c208c59903e 100644
--- a/packages/twenty-front/src/modules/navigation/components/SettingsNavigationDrawer.tsx
+++ b/packages/twenty-front/src/modules/navigation/components/SettingsNavigationDrawer.tsx
@@ -48,13 +48,17 @@ export const SettingsNavigationDrawer = ({
);
const hasAiPermission = useHasPermissionFlag(PermissionFlagType.AI);
+ // The tab is shared with the desktop drawer, so gating the content on the row
+ // too stops a tab set there stranding this drawer with no way back.
+ const showTabsRow = hasAiPermission && !isMobile;
+
const showAiChatContent =
- hasAiPermission &&
+ showTabsRow &&
navigationDrawerActiveTab === NAVIGATION_DRAWER_TABS.AI_CHAT_HISTORY;
return (
<NavigationDrawer className={className} title={t`Settings`}>
- {hasAiPermission && (
+ {showTabsRow && (
<NavigationDrawerFixedContent>
<MainNavigationDrawerTabsRow
NavigationMenuTabIcon={IconSettings}
@@ -66,7 +70,7 @@ export const SettingsNavigationDrawer = ({
<NavigationDrawerScrollableContent>
<NavigationDrawerTabbedContent
showAiChatContent={showAiChatContent}
- shouldMountAiChatContent={hasAiPermission}
+ shouldMountAiChatContent={showTabsRow}
navigationContent={<SettingsNavigationDrawerItems />}
/>
</NavigationDrawerScrollableContent>
diff --git a/packages/twenty-front/src/modules/navigation/hooks/__tests__/useDefaultHomePagePath.test.ts b/packages/twenty-front/src/modules/navigation/hooks/__tests__/useDefaultHomePagePath.test.ts
index 8f37eaffdba..e829581db17 100644
--- a/packages/twenty-front/src/modules/navigation/hooks/__tests__/useDefaultHomePagePath.test.ts
+++ b/packages/twenty-front/src/modules/navigation/hooks/__tests__/useDefaultHomePagePath.test.ts
@@ -24,6 +24,12 @@ import { getTestEnrichedObjectMetadataItemsMock } from '~/testing/utils/getTestE
import { setTestObjectMetadataItemsInMetadataStore } from '~/testing/utils/setTestObjectMetadataItemsInMetadataStore';
import { setTestViewsInMetadataStore } from '~/testing/utils/setTestViewsInMetadataStore';
+let mockIsMobile = false;
+
+jest.mock('@/ui/utilities/responsive/hooks/useIsMobile', () => ({
+ useIsMobile: () => mockIsMobile,
+}));
+
const Wrapper = ({ children }: { children: ReactNode }) =>
createElement(JotaiProvider, { store: jotaiStore }, children);
@@ -177,6 +183,10 @@ const renderHooks = ({
};
describe('useDefaultHomePagePath', () => {
+ afterEach(() => {
+ mockIsMobile = false;
+ });
+
it('should return proper path when no currentUser', async () => {
const { result } = renderHooks({
withCurrentUser: false,
@@ -318,6 +328,32 @@ describe('useDefaultHomePagePath', () => {
expect(result.current.defaultHomePagePath).toEqual(AppPath.Index);
});
});
+ it('should return the mobile home page on mobile', async () => {
+ mockIsMobile = true;
+
+ const { result } = renderHooks({
+ withCurrentUser: true,
+ withExistingView: false,
+ navigationMenuItems: [buildObjectNavigationMenuItem('person', 0)],
+ });
+
+ await waitFor(() => {
+ expect(result.current.defaultHomePagePath).toEqual(AppPath.Home);
+ });
+ });
+ it('should still return the sign in page on mobile when there is no currentUser', async () => {
+ mockIsMobile = true;
+ jotaiStore.set(currentUserState.atom, null);
+
+ const { result } = renderHooks({
+ withCurrentUser: false,
+ withExistingView: false,
+ });
+
+ await waitFor(() => {
+ expect(result.current.defaultHomePagePath).toEqual(AppPath.SignInUp);
+ });
+ });
it('should defer to AppPath.Index when object metadata is loaded but empty while navigation menu items are not loaded yet', async () => {
const { result } = renderHooks({
withCurrentUser: true,
diff --git a/packages/twenty-front/src/modules/navigation/hooks/useDefaultHomePagePath.ts b/packages/twenty-front/src/modules/navigation/hooks/useDefaultHomePagePath.ts
index 597a2a3052b..1e0a8dbc7aa 100644
--- a/packages/twenty-front/src/modules/navigation/hooks/useDefaultHomePagePath.ts
+++ b/packages/twenty-front/src/modules/navigation/hooks/useDefaultHomePagePath.ts
@@ -8,6 +8,7 @@ import { useFilteredObjectMetadataItems } from '@/object-metadata/hooks/useFilte
import { objectMetadataItemsSelector } from '@/object-metadata/states/objectMetadataItemsSelector';
import { filterReadableActiveObjectMetadataItems } from '@/object-metadata/utils/filterReadableActiveObjectMetadataItems';
import { useObjectPermissions } from '@/object-record/hooks/useObjectPermissions';
+import { useIsMobile } from '@/ui/utilities/responsive/hooks/useIsMobile';
import { useAtomFamilySelectorValue } from '@/ui/utilities/state/jotai/hooks/useAtomFamilySelectorValue';
import { useAtomFamilyStateValue } from '@/ui/utilities/state/jotai/hooks/useAtomFamilyStateValue';
import { useAtomStateValue } from '@/ui/utilities/state/jotai/hooks/useAtomStateValue';
@@ -19,6 +20,7 @@ import { getAppPath, getSettingsPath, isDefined } from 'twenty-shared/utils';
export const useDefaultHomePagePath = () => {
const currentUser = useAtomStateValue(currentUserState);
+ const isMobile = useIsMobile();
const { objectPermissionsByObjectMetadataId } = useObjectPermissions();
const metadataStore = useAtomFamilyStateValue(
metadataStoreState,
@@ -90,6 +92,10 @@ export const useDefaultHomePagePath = () => {
return AppPath.SignInUp;
}
+ if (isMobile) {
+ return AppPath.Home;
+ }
+
// Both stores are transiently empty during the post-login window;
// deciding the redirect before they are loaded could strand users on a
// wrong fallback (/settings/profile or the alphabetically-first object).
@@ -118,6 +124,7 @@ export const useDefaultHomePagePath = () => {
);
}, [
currentUser,
+ isMobile,
readableNonSystemObjectMetadataItems,
areObjectMetadataItemsLoaded,
areNavigationMenuItemsLoaded,
diff --git a/packages/twenty-front/src/modules/navigation/hooks/useMobileNavigationBarItems.ts b/packages/twenty-front/src/modules/navigation/hooks/useMobileNavigationBarItems.ts
new file mode 100644
index 00000000000..c7debe398a4
--- /dev/null
+++ b/packages/twenty-front/src/modules/navigation/hooks/useMobileNavigationBarItems.ts
@@ -0,0 +1,123 @@
+import { useSwitchToNewAiChat } from '@/ai/hooks/useSwitchToNewAiChat';
+import { MAIN_CONTEXT_STORE_INSTANCE_ID } from '@/context-store/constants/MainContextStoreInstanceId';
+import { contextStoreCurrentObjectMetadataItemIdComponentState } from '@/context-store/states/contextStoreCurrentObjectMetadataItemIdComponentState';
+import { useIsSettingsDrawer } from '@/navigation/hooks/useIsSettingsDrawer';
+import { useIsSettingsPage } from '@/navigation/hooks/useIsSettingsPage';
+import { currentMobileNavigationDrawerState } from '@/navigation/states/currentMobileNavigationDrawerState';
+import { useFilteredObjectMetadataItems } from '@/object-metadata/hooks/useFilteredObjectMetadataItems';
+import { useHasPermissionFlag } from '@/settings/roles/hooks/useHasPermissionFlag';
+import { useOpenRecordsSearchPageInSidePanel } from '@/side-panel/hooks/useOpenRecordsSearchPageInSidePanel';
+import { useSidePanelMenu } from '@/side-panel/hooks/useSidePanelMenu';
+import { isNavigationDrawerExpandedState } from '@/ui/navigation/states/isNavigationDrawerExpanded';
+import { useSetAtomComponentState } from '@/ui/utilities/state/jotai/hooks/useSetAtomComponentState';
+import { useSetAtomState } from '@/ui/utilities/state/jotai/hooks/useSetAtomState';
+import { useLingui } from '@lingui/react/macro';
+import { useLocation, useNavigate } from 'react-router-dom';
+import { AppPath } from 'twenty-shared/types';
+import { isDefined } from 'twenty-shared/utils';
+import {
+ type IconComponent,
+ IconHome,
+ IconMessageCirclePlus,
+ IconSearch,
+} from 'twenty-ui/icon';
+import { PermissionFlagType } from '~/generated-metadata/graphql';
+
+type MobileNavigationBarItemName = 'home' | 'search' | 'newAiChat';
+
+type MobileNavigationBarItem = {
+ name: MobileNavigationBarItemName;
+ label: string;
+ Icon: IconComponent;
+ onClick: () => void;
+};
+
+export const useMobileNavigationBarItems = (): {
+ items: MobileNavigationBarItem[];
+ activeItemName: MobileNavigationBarItemName | '';
+} => {
+ const { t } = useLingui();
+ const navigate = useNavigate();
+ const { pathname } = useLocation();
+ const { closeSidePanelMenu } = useSidePanelMenu();
+ const { openRecordsSearchPage } = useOpenRecordsSearchPageInSidePanel();
+ const { switchToNewChat } = useSwitchToNewAiChat();
+ const isSettingsPage = useIsSettingsPage();
+ const isSettingsDrawer = useIsSettingsDrawer();
+ const { alphaSortedActiveNonSystemObjectMetadataItems } =
+ useFilteredObjectMetadataItems();
+ const hasAiPermission = useHasPermissionFlag(PermissionFlagType.AI);
+
+ const setContextStoreCurrentObjectMetadataItemId = useSetAtomComponentState(
+ contextStoreCurrentObjectMetadataItemIdComponentState,
+ MAIN_CONTEXT_STORE_INSTANCE_ID,
+ );
+ const setCurrentMobileNavigationDrawer = useSetAtomState(
+ currentMobileNavigationDrawerState,
+ );
+ const setIsNavigationDrawerExpanded = useSetAtomState(
+ isNavigationDrawerExpandedState,
+ );
+
+ // The expansion state is shared with the desktop drawer, so the guard keeps a
+ // tap outside settings from collapsing it there.
+ const closeSettingsDrawer = () => {
+ if (!isSettingsDrawer) {
+ return;
+ }
+
+ setCurrentMobileNavigationDrawer('main');
+ setIsNavigationDrawerExpanded(false);
+ };
+
+ return {
+ activeItemName: pathname === AppPath.Home ? 'home' : '',
+ items: [
+ {
+ name: 'home',
+ label: t`Home`,
+ Icon: IconHome,
+ onClick: () => {
+ closeSidePanelMenu();
+ closeSettingsDrawer();
+ navigate(AppPath.Home);
+ },
+ },
+ {
+ name: 'search',
+ label: t`Search`,
+ Icon: IconSearch,
+ onClick: () => {
+ closeSidePanelMenu();
+ closeSettingsDrawer();
+
+ if (isSettingsPage) {
+ const firstObjectMetadataItem =
+ alphaSortedActiveNonSystemObjectMetadataItems[0];
+ if (isDefined(firstObjectMetadataItem)) {
+ setContextStoreCurrentObjectMetadataItemId(
+ firstObjectMetadataItem.id,
+ );
+ }
+ }
+
+ openRecordsSearchPage();
+ },
+ },
+ ...(hasAiPermission
+ ? [
+ {
+ name: 'newAiChat' as const,
+ label: t`New AI chat`,
+ Icon: IconMessageCirclePlus,
+ onClick: () => {
+ closeSidePanelMenu();
+ closeSettingsDrawer();
+ switchToNewChat();
+ },
+ },
+ ]
+ : []),
+ ],
+ };
+};
diff --git a/packages/twenty-front/src/modules/side-panel/components/SidePanelContainer.tsx b/packages/twenty-front/src/modules/side-panel/components/SidePanelContainer.tsx
index c8934a601e8..36ad651633e 100644
--- a/packages/twenty-front/src/modules/side-panel/components/SidePanelContainer.tsx
+++ b/packages/twenty-front/src/modules/side-panel/components/SidePanelContainer.tsx
@@ -8,20 +8,14 @@ import { ContextStoreComponentInstanceContext } from '@/context-store/states/con
import { objectMetadataItemsSelector } from '@/object-metadata/states/objectMetadataItemsSelector';
import { RecordComponentInstanceContextsWrapper } from '@/object-record/components/RecordComponentInstanceContextsWrapper';
import { getRecordIndexIdFromObjectNamePluralAndViewId } from '@/object-record/utils/getRecordIndexIdFromObjectNamePluralAndViewId';
-import { useIsMobile } from '@/ui/utilities/responsive/hooks/useIsMobile';
import { useAtomComponentStateValue } from '@/ui/utilities/state/jotai/hooks/useAtomComponentStateValue';
import { useAtomStateValue } from '@/ui/utilities/state/jotai/hooks/useAtomStateValue';
-import { themeCssVariables } from 'twenty-ui/theme-constants';
-const StyledSidePanelContainer = styled.div<{ isMobile: boolean }>`
+const StyledSidePanelContainer = styled.div`
display: flex;
flex: 1;
flex-direction: column;
- max-height: ${({ isMobile }) => {
- const mobileOffset = isMobile ? themeCssVariables.spacing[16] : '0px';
-
- return `calc(100% - ${mobileOffset})`;
- }};
+ max-height: 100%;
min-height: 0;
`;
@@ -34,7 +28,6 @@ export const SidePanelContainer = ({ children }: SidePanelContainerProps) => {
contextStoreCurrentObjectMetadataItemIdComponentState,
MAIN_CONTEXT_STORE_INSTANCE_ID,
);
- const isMobile = useIsMobile();
const objectMetadataItems = useAtomStateValue(objectMetadataItemsSelector);
@@ -61,9 +54,7 @@ export const SidePanelContainer = ({ children }: SidePanelContainerProps) => {
<CommandMenuComponentInstanceContext.Provider
value={{ instanceId: SIDE_PANEL_COMPONENT_INSTANCE_ID }}
>
- <StyledSidePanelContainer isMobile={isMobile}>
- {children}
- </StyledSidePanelContainer>
+ <StyledSidePanelContainer>{children}</StyledSidePanelContainer>
</CommandMenuComponentInstanceContext.Provider>
</ContextStoreComponentInstanceContext.Provider>
</RecordComponentInstanceContextsWrapper>
diff --git a/packages/twenty-front/src/pages/mobile-home/MobileHomePage.tsx b/packages/twenty-front/src/pages/mobile-home/MobileHomePage.tsx
index ac206d333a0..e72490924a1 100644
--- a/packages/twenty-front/src/pages/mobile-home/MobileHomePage.tsx
+++ b/packages/twenty-front/src/pages/mobile-home/MobileHomePage.tsx
@@ -1,16 +1,11 @@
+import { MobileHomeAiChatSection } from '@/ai/components/MobileHomeAiChatSection';
import { MainNavigationDrawerNavigationContent } from '@/navigation/components/MainNavigationDrawerNavigationContent';
-import { MobileHomeTabsRow } from '@/navigation/components/MobileHomeTabsRow';
-import { NavigationDrawerTabbedContent } from '@/navigation/components/NavigationDrawerTabbedContent';
import { useDefaultHomePagePath } from '@/navigation/hooks/useDefaultHomePagePath';
-import { SettingsNavigationDrawerItems } from '@/settings/components/SettingsNavigationDrawerItems';
import { useHasPermissionFlag } from '@/settings/roles/hooks/useHasPermissionFlag';
import { MultiWorkspaceDropdownButton } from '@/ui/navigation/navigation-drawer/components/MultiWorkspaceDropdown/MultiWorkspaceDropdownButton';
import { NavigationDrawerFixedContent } from '@/ui/navigation/navigation-drawer/components/NavigationDrawerFixedContent';
import { NavigationDrawerScrollableContent } from '@/ui/navigation/navigation-drawer/components/NavigationDrawerScrollableContent';
-import { navigationDrawerActiveTabState } from '@/ui/navigation/states/navigationDrawerActiveTabState';
-import { NAVIGATION_DRAWER_TABS } from '@/ui/navigation/states/navigationDrawerTabs';
import { useIsMobile } from '@/ui/utilities/responsive/hooks/useIsMobile';
-import { useAtomStateValue } from '@/ui/utilities/state/jotai/hooks/useAtomStateValue';
import { styled } from '@linaria/react';
import { Navigate } from 'react-router-dom';
import { themeCssVariables } from 'twenty-ui/theme-constants';
@@ -27,20 +22,15 @@ const StyledContainer = styled.div`
width: 100%;
`;
-const StyledTopRow = styled.div`
- align-items: center;
+const StyledSections = styled.div`
display: flex;
- gap: ${themeCssVariables.spacing[2]};
- justify-content: space-between;
- width: 100%;
+ flex-direction: column;
+ gap: ${themeCssVariables.spacing[3]};
`;
export const MobileHomePage = () => {
const isMobile = useIsMobile();
const { defaultHomePagePath } = useDefaultHomePagePath();
- const navigationDrawerActiveTab = useAtomStateValue(
- navigationDrawerActiveTabState,
- );
const hasAiPermission = useHasPermissionFlag(PermissionFlagType.AI);
// Desktop keeps the drawer, so the page has nothing to show there.
@@ -48,34 +38,17 @@ export const MobileHomePage = () => {
return <Navigate to={defaultHomePagePath} replace />;
}
- const showAiChatContent =
- hasAiPermission &&
- navigationDrawerActiveTab === NAVIGATION_DRAWER_TABS.AI_CHAT_HISTORY;
-
- const showSettingsContent =
- navigationDrawerActiveTab === NAVIGATION_DRAWER_TABS.SETTINGS;
-
return (
<StyledContainer>
<NavigationDrawerFixedContent>
- <StyledTopRow>
- <MobileHomeTabsRow />
- <MultiWorkspaceDropdownButton shouldHideLabel />
- </StyledTopRow>
+ <MultiWorkspaceDropdownButton />
</NavigationDrawerFixedContent>
<NavigationDrawerScrollableContent>
- <NavigationDrawerTabbedContent
- showAiChatContent={showAiChatContent}
- shouldMountAiChatContent={hasAiPermission}
- navigationContent={
- showSettingsContent ? (
- <SettingsNavigationDrawerItems />
- ) : (
- <MainNavigationDrawerNavigationContent />
- )
- }
- />
+ <StyledSections>
+ <MainNavigationDrawerNavigationContent />
+ {hasAiPermission && <MobileHomeAiChatSection />}
+ </StyledSections>
</NavigationDrawerScrollableContent>
</StyledContainer>
);