Skip to content

Commit 8db83d4

Browse files
FIX (mobile): Do not preselect card on mobile for DBs, notifiers and storanges
1 parent d2a9085 commit 8db83d4

File tree

4 files changed

+14
-10
lines changed

4 files changed

+14
-10
lines changed

frontend/src/features/databases/ui/DatabasesComponent.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ export const DatabasesComponent = ({ contentHeight, workspace, isCanManageDBs }:
4747
if (selectDatabaseId) {
4848
updateSelectedDatabaseId(selectDatabaseId);
4949
} else if (!selectedDatabaseId && !isSilent && !isMobile) {
50-
// On desktop, auto-select a database; on mobile, keep it unselected
50+
// On desktop, auto-select a database; on mobile, keep it unselected to show the list first
5151
const savedDatabaseId = localStorage.getItem(
5252
`${SELECTED_DATABASE_STORAGE_KEY}_${workspace.id}`,
5353
);

frontend/src/features/notifiers/ui/NotifiersComponent.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ export const NotifiersComponent = ({ contentHeight, workspace, isCanManageNotifi
4747
if (selectNotifierId) {
4848
updateSelectedNotifierId(selectNotifierId);
4949
} else if (!selectedNotifierId && !isSilent && !isMobile) {
50-
// On desktop, auto-select a notifier; on mobile, keep it unselected
50+
// On desktop, auto-select a notifier; on mobile, keep it unselected to show the list first
5151
const savedNotifierId = localStorage.getItem(
5252
`${SELECTED_NOTIFIER_STORAGE_KEY}_${workspace.id}`,
5353
);

frontend/src/features/storages/ui/StoragesComponent.tsx

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,19 @@ export const StoragesComponent = ({ contentHeight, workspace, isCanManageStorage
3434
}
3535
};
3636

37-
const loadStorages = () => {
38-
setIsLoading(true);
37+
const loadStorages = (isSilent = false, selectStorageId?: string) => {
38+
if (!isSilent) {
39+
setIsLoading(true);
40+
}
3941

4042
storageApi
4143
.getStorages(workspace.id)
4244
.then((storages: Storage[]) => {
4345
setStorages(storages);
44-
if (!selectedStorageId && !isMobile) {
45-
// On desktop, auto-select a storage; on mobile, keep it unselected
46+
if (selectStorageId) {
47+
updateSelectedStorageId(selectStorageId);
48+
} else if (!selectedStorageId && !isSilent && !isMobile) {
49+
// On desktop, auto-select a storage; on mobile, keep it unselected to show the list first
4650
const savedStorageId = localStorage.getItem(
4751
`${SELECTED_STORAGE_STORAGE_KEY}_${workspace.id}`,
4852
);
@@ -154,8 +158,8 @@ export const StoragesComponent = ({ contentHeight, workspace, isCanManageStorage
154158
isShowName
155159
isShowClose={false}
156160
onClose={() => setIsShowAddStorage(false)}
157-
onChanged={() => {
158-
loadStorages();
161+
onChanged={(storage) => {
162+
loadStorages(false, storage.id);
159163
setIsShowAddStorage(false);
160164
}}
161165
/>

frontend/src/shared/hooks/useIsMobile.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,14 @@ import { useEffect, useState } from 'react';
77
* @returns isMobile boolean
88
*/
99
export function useIsMobile(): boolean {
10-
const [isMobile, setIsMobile] = useState<boolean>(false);
10+
// Initialize with actual value to avoid race conditions
11+
const [isMobile, setIsMobile] = useState<boolean>(() => window.innerWidth <= 768);
1112

1213
useEffect(() => {
1314
const updateIsMobile = () => {
1415
setIsMobile(window.innerWidth <= 768);
1516
};
1617

17-
updateIsMobile(); // Set initial value
1818
window.addEventListener('resize', updateIsMobile);
1919

2020
return () => {

0 commit comments

Comments
 (0)