File size: 6,749 Bytes
b225a21
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
import 'package:auto_gpt_flutter_client/viewmodels/settings_viewmodel.dart';
import 'package:auto_gpt_flutter_client/viewmodels/skill_tree_viewmodel.dart';
import 'package:auto_gpt_flutter_client/viewmodels/task_viewmodel.dart';
import 'package:auto_gpt_flutter_client/viewmodels/chat_viewmodel.dart';
import 'package:auto_gpt_flutter_client/views/settings/settings_view.dart';
import 'package:auto_gpt_flutter_client/views/side_bar/side_bar_view.dart';
import 'package:auto_gpt_flutter_client/views/skill_tree/skill_tree_view.dart';
import 'package:auto_gpt_flutter_client/views/task/task_view.dart';
import 'package:auto_gpt_flutter_client/views/chat/chat_view.dart';
import 'package:auto_gpt_flutter_client/views/task_queue/task_queue_view.dart';
import 'package:flutter/cupertino.dart';
import 'package:provider/provider.dart';

class MainLayout extends StatelessWidget {
  final ValueNotifier<String> selectedViewNotifier = ValueNotifier('TaskView');

  MainLayout({super.key});

  @override
  Widget build(BuildContext context) {
    // Get the screen width
    double width = MediaQuery.of(context).size.width;

    // Access the various ViewModels from the context
    final taskViewModel = Provider.of<TaskViewModel>(context);
    final chatViewModel = Provider.of<ChatViewModel>(context);
    final settingsViewModel = Provider.of<SettingsViewModel>(context);

    // Initialize the width for the SideBarView
    double sideBarWidth = 60.0;

    // Initialize the width for the TaskView
    double taskViewWidth = 280.0;

    // Initialize the width for the SettingsView
    double settingsViewWidth = 280.0;

    // Calculate remaining width after subtracting the width of the SideBarView
    double remainingWidth = width - sideBarWidth;

    // Declare variables to hold the widths of SkillTreeView, TestQueueView, and ChatView
    double skillTreeViewWidth = 0;
    double testQueueViewWidth = 0;
    double chatViewWidth = 0;

    if (width > 800) {
      return Row(
        children: [
          SizedBox(
              width: sideBarWidth,
              child: SideBarView(selectedViewNotifier: selectedViewNotifier)),
          ValueListenableBuilder(
            valueListenable: selectedViewNotifier,
            builder: (context, String value, _) {
              return Consumer<SkillTreeViewModel>(
                builder: (context, skillTreeViewModel, _) {
                  if (value == 'TaskView') {
                    // TODO: Handle this state reset better
                    skillTreeViewModel.resetState();
                    chatViewWidth = remainingWidth - taskViewWidth;
                    return Row(
                      children: [
                        SizedBox(
                            width: taskViewWidth,
                            child: TaskView(viewModel: taskViewModel)),
                        SizedBox(
                            width: chatViewWidth,
                            child: ChatView(viewModel: chatViewModel))
                      ],
                    );
                  } else if (value == 'SettingsView') {
                    // TODO: Handle this state reset better
                    skillTreeViewModel.resetState();
                    chatViewWidth = remainingWidth - settingsViewWidth;
                    return Row(
                      children: [
                        SizedBox(
                            width: settingsViewWidth,
                            // Render the SettingsView with the same width as TaskView
                            child: SettingsView(viewModel: settingsViewModel)),
                        SizedBox(
                            width: chatViewWidth,
                            // Render the ChatView next to the SettingsView
                            child: ChatView(viewModel: chatViewModel)),
                      ],
                    );
                  } else {
                    if (skillTreeViewModel.selectedNode != null) {
                      // If TaskQueueView should be displayed
                      testQueueViewWidth = remainingWidth * 0.25;
                      skillTreeViewWidth = remainingWidth * 0.25;
                      chatViewWidth = remainingWidth * 0.5;
                    } else {
                      // If only SkillTreeView and ChatView should be displayed
                      skillTreeViewWidth = remainingWidth * 0.5;
                      chatViewWidth = remainingWidth * 0.5;
                    }

                    return Row(
                      children: [
                        SizedBox(
                            width: skillTreeViewWidth,
                            child:
                                SkillTreeView(viewModel: skillTreeViewModel)),
                        if (skillTreeViewModel.selectedNode != null)
                          SizedBox(
                              width: testQueueViewWidth,
                              child: TaskQueueView()),
                        SizedBox(
                            width: chatViewWidth,
                            child: ChatView(viewModel: chatViewModel)),
                      ],
                    );
                  }
                },
              );
            },
          ),
        ],
      );
    } else {
      // For smaller screens, return a tabbed layout
      // TODO: Include settings view for smaller screen sizes
      return CupertinoTabScaffold(
        tabBar: CupertinoTabBar(
          items: const <BottomNavigationBarItem>[
            BottomNavigationBarItem(
              icon: Icon(CupertinoIcons.person),
              label: 'Tasks',
            ),
            BottomNavigationBarItem(
              icon: Icon(CupertinoIcons.chat_bubble),
              label: 'Chat',
            ),
          ],
        ),
        tabBuilder: (BuildContext context, int index) {
          CupertinoTabView? returnValue;

          switch (index) {
            case 0:
              returnValue = CupertinoTabView(builder: (context) {
                return CupertinoPageScaffold(
                  child: SafeArea(child: TaskView(viewModel: taskViewModel)),
                );
              });
              break;
            case 1:
              returnValue = CupertinoTabView(builder: (context) {
                return CupertinoPageScaffold(
                  child: SafeArea(child: ChatView(viewModel: chatViewModel)),
                );
              });
              break;
          }

          return returnValue ??
              CupertinoTabView(builder: (context) {
                return CupertinoPageScaffold(
                  child: Container(), // Default empty container
                );
              });
        },
      );
    }
  }
}