Skip to content

Instantly share code, notes, and snippets.

@ndugger
Last active December 30, 2022 18:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ndugger/a2e3de18e29dafafbe30c7be9d6ae4f5 to your computer and use it in GitHub Desktop.
Save ndugger/a2e3de18e29dafafbe30c7be9d6ae4f5 to your computer and use it in GitHub Desktop.
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