@@ -30,6 +30,7 @@ import { LoadingProvider } from './contexts/loading-context';
3030import { LoginPage } from './features/auth/login-page' ;
3131import { AllViewGrid } from './features/dashboard/all-view-grid' ;
3232import type { CardType } from './features/dashboard/components/AddCardDialogContainer' ;
33+ import { AddEntityDialog } from './features/dashboard/components/add-entity-dialog' ;
3334import { DashboardLayout } from './features/dashboard/dashboard-layout' ;
3435import { DeviceGrid } from './features/dashboard/device-grid' ;
3536import {
@@ -46,17 +47,14 @@ import {
4647import { useCustomCards } from './hooks/use-custom-cards' ;
4748import { useDevices , useRooms } from './hooks/use-devices' ;
4849import { useDashboardEntitiesStore , useSettingsStore } from './stores' ;
50+ import { importDashboardConfigFromFile } from './utils/dashboard-config' ;
4951import { getDeviceRoom , getDeviceRoomLabel } from './utils/device-location' ;
5052
5153const AddCardDialog = lazy ( async ( ) => {
5254 const module = await import ( './features/dashboard/components/AddCardDialogContainer' ) ;
5355 return { default : module . AddCardDialogContainer } ;
5456} ) ;
5557
56- const AddEntityDialog = lazy ( async ( ) => {
57- const module = await import ( './features/dashboard/components/add-entity-dialog' ) ;
58- return { default : module . AddEntityDialog } ;
59- } ) ;
6058const DashboardOnboardingDialog = lazy ( async ( ) => {
6159 const module = await import ( './features/dashboard/components/dashboard-onboarding-dialog' ) ;
6260 return { default : module . DashboardOnboardingDialog } ;
@@ -72,7 +70,7 @@ const SettingsSection = lazy(async () => {
7270 * The main dashboard view after authentication
7371 */
7472function Dashboard ( ) {
75- const { activeSection } = useNavigation ( ) ;
73+ const { activeSection, setActiveSection } = useNavigation ( ) ;
7674 const { connected, connecting, error } = useHomeAssistant ( ) ;
7775 const [ devicesLoaded , setDevicesLoaded ] = useState ( false ) ;
7876 const [ showAddCardDialog , setShowAddCardDialog ] = useState ( false ) ;
@@ -106,6 +104,10 @@ function Dashboard() {
106104 const { deviceMap } = useDeviceMap ( devices ) ;
107105 const { deviceMap : availableDeviceMap } = useDeviceMap ( allDevices ) ;
108106 const allEntityIds = useMemo ( ( ) => Array . from ( availableDeviceMap . keys ( ) ) , [ availableDeviceMap ] ) ;
107+ const addableEntityIds = useMemo (
108+ ( ) => ( hiddenEntityIds . length > 0 ? hiddenEntityIds : allEntityIds ) ,
109+ [ allEntityIds , hiddenEntityIds ]
110+ ) ;
109111 const lightDeviceMap = useMemo (
110112 ( ) => new Map ( Array . from ( deviceMap . entries ( ) ) . filter ( ( [ , device ] ) => device . type === 'lights' ) ) ,
111113 [ deviceMap ]
@@ -215,6 +217,30 @@ function Dashboard() {
215217 [ hideAutoEntity ]
216218 ) ;
217219
220+ const handleImportDashboardConfig = useCallback ( async ( file : File ) => {
221+ try {
222+ await importDashboardConfigFromFile ( file ) ;
223+ toast . success ( 'Dashboard config imported. Reloading...' ) ;
224+ window . setTimeout ( ( ) => {
225+ window . location . reload ( ) ;
226+ } , 600 ) ;
227+ } catch {
228+ toast . error ( 'Failed to import dashboard config' ) ;
229+ }
230+ } , [ ] ) ;
231+
232+ const handleChooseAllEntities = useCallback ( ( ) => {
233+ setActiveSection ( 'home' ) ;
234+ changeRoom ( 'All' ) ;
235+ completeOnboarding ( allEntityIds , false ) ;
236+ } , [ allEntityIds , changeRoom , completeOnboarding , setActiveSection ] ) ;
237+
238+ const handleChooseBlankDashboard = useCallback ( ( ) => {
239+ setActiveSection ( 'home' ) ;
240+ changeRoom ( 'All' ) ;
241+ completeOnboarding ( allEntityIds , true ) ;
242+ } , [ allEntityIds , changeRoom , completeOnboarding , setActiveSection ] ) ;
243+
218244 // Handle updating a card
219245 const handleUpdateCard = useCallback (
220246 ( cardId : string , data : Record < string , unknown > ) => {
@@ -281,6 +307,7 @@ function Dashboard() {
281307 ? 'All light entities have been removed from the dashboard.'
282308 : 'No Home Assistant light entities are currently available.'
283309 }
310+ actionIcon = { Lightbulb }
284311 actionLabel = { hiddenEntityIds . length > 0 ? 'Add Entity' : undefined }
285312 onAction = { hiddenEntityIds . length > 0 ? ( ) => setShowAddEntityDialog ( true ) : undefined }
286313 />
@@ -334,7 +361,7 @@ function Dashboard() {
334361 onToggleEditMode = { toggleEditMode }
335362 onMoveRoom = { moveRoom }
336363 onAddCard = { ( ) => setShowAddCardDialog ( true ) }
337- onAddEntity = { hiddenEntityIds . length > 0 ? ( ) => setShowAddEntityDialog ( true ) : undefined }
364+ onAddEntity = { addableEntityIds . length > 0 ? ( ) => setShowAddEntityDialog ( true ) : undefined }
338365 addEntityLabel = "Add Entity"
339366 />
340367
@@ -378,8 +405,9 @@ function Dashboard() {
378405 icon = { Lightbulb }
379406 title = "No Visible Entities"
380407 description = "Your dashboard is empty. Add entities from your hidden list or add custom cards to start building it."
381- actionLabel = { hiddenEntityIds . length > 0 ? 'Add Entity' : undefined }
382- onAction = { hiddenEntityIds . length > 0 ? ( ) => setShowAddEntityDialog ( true ) : undefined }
408+ actionIcon = { Lightbulb }
409+ actionLabel = { addableEntityIds . length > 0 ? 'Add Entity' : undefined }
410+ onAction = { addableEntityIds . length > 0 ? ( ) => setShowAddEntityDialog ( true ) : undefined }
383411 />
384412 ) }
385413
@@ -395,27 +423,30 @@ function Dashboard() {
395423 ) }
396424
397425 { showAddEntityDialog && (
398- < Suspense fallback = { null } >
399- < AddEntityDialog
400- open = { showAddEntityDialog }
401- onClose = { ( ) => setShowAddEntityDialog ( false ) }
402- onAddEntity = { handleAddEntity }
403- currentRoom = { activeRoom }
404- deviceMap = { availableDeviceMap }
405- addedEntityIds = { [ ] }
406- visibleEntityIds = { hiddenEntityIds }
407- title = "Add Entity"
408- description = "Add Home Assistant entities back to the dashboard."
409- actionLabel = "Add"
410- />
411- </ Suspense >
426+ < AddEntityDialog
427+ open = { showAddEntityDialog }
428+ onClose = { ( ) => setShowAddEntityDialog ( false ) }
429+ onAddEntity = { handleAddEntity }
430+ currentRoom = { activeRoom }
431+ deviceMap = { availableDeviceMap }
432+ addedEntityIds = { [ ] }
433+ visibleEntityIds = { addableEntityIds }
434+ title = "Add Entity"
435+ description = {
436+ hiddenEntityIds . length > 0
437+ ? 'Add Home Assistant entities back to the dashboard.'
438+ : 'Choose Home Assistant entities to add to the dashboard.'
439+ }
440+ actionLabel = "Add"
441+ />
412442 ) }
413443 { ! onboardingCompleted && allEntityIds . length > 0 && (
414444 < Suspense fallback = { null } >
415445 < DashboardOnboardingDialog
416446 open
417- onChooseAll = { ( ) => completeOnboarding ( allEntityIds , false ) }
418- onChooseBlank = { ( ) => completeOnboarding ( allEntityIds , true ) }
447+ onChooseAll = { handleChooseAllEntities }
448+ onChooseBlank = { handleChooseBlankDashboard }
449+ onImportConfig = { handleImportDashboardConfig }
419450 />
420451 </ Suspense >
421452 ) }
0 commit comments