Last active
December 30, 2022 18:26
-
-
Save ndugger/a2e3de18e29dafafbe30c7be9d6ae4f5 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class AppRoot extends HookConsumerWidget { | |
const AppRoot({ super.key }); | |
@override | |
Widget build(BuildContext context, WidgetRef ref) { | |
final workspaceList = useWorkspaceList(ref); | |
final authentication = useAuthentication(ref); | |
final realtimeWebSocket = useWebSocket(ref, realtimeSocket); | |
useWebSocketEvent(realtimeWebSocket, IncomingRealtimeEvent.authKeyUpdated, (key) { | |
authentication.notifier.updateKey(key); | |
}, [authentication]); | |
useWebSocketEvent(realtimeWebSocket, IncomingRealtimeEvent.userAccountUpdated, (user) { | |
authentication.notifier.updateAccount(User.fromJson(user)); | |
}, [authentication]); | |
useWebSocketEvent(realtimeWebSocket, IncomingRealtimeEvent.workspaceListUpdated, (workspaces) { | |
workspaceList.notifier.updateList(workspaces.map<Workspace>((workspace) => Workspace.fromJson(workspace)).toList()); | |
}, [workspaceList]); | |
useEffect(() { | |
if (authentication.state.authenticated) { | |
realtimeWebSocket.emit(OutgoingRealtimeEvent.requestListWorkspaces, [authentication.state.key]); | |
} else { | |
realtimeWebSocket.emit(OutgoingRealtimeEvent.requestUserAuthentication, [credentials]); | |
} | |
}, [authentication.state.authenticated]); | |
return Application( | |
root: Window( | |
children: [ | |
const WorkspaceSwitcher(), | |
Expanded( | |
child: Pathfinder( | |
paths: [ | |
Path( | |
name: '/', | |
builder: (context) => const WorkspaceScreen() | |
), | |
Path( | |
name: '/workspaces/{workspace_id}', | |
builder: (context) => const WorkspaceScreen() | |
), | |
Path( | |
name: '/sessions/{session_id}', | |
builder: (context) => const SessionScreen() | |
) | |
] | |
) | |
) | |
], | |
) | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment