Skip to content

Commit 3a7d4f5

Browse files
committed
fix: fixed the workspace based object fetching issue
1 parent c674f74 commit 3a7d4f5

File tree

6 files changed

+285
-257
lines changed

6 files changed

+285
-257
lines changed

lib/features/dashboard/providers/dashboard_provider.dart

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,13 @@ class DashboardProvider extends StateHandler {
1818
int _tabIndex = 0;
1919
bool _isLoading = false;
2020
bool _isInitialized = false;
21-
// List<WorkspaceModel> _workspaceList = [];
2221
Map<String, WorkspaceModel> _workspaceList = {};
2322

2423
// getters
2524
bool get isDrawerOpen => _isDrawerOpen;
2625
int get tabIndex => _tabIndex;
2726
bool get isLoading => _isLoading;
2827
bool get isInitialized => _isInitialized;
29-
// List<WorkspaceModel> get workspaceList => _workspaceList;
3028
Map<String, WorkspaceModel> get workspaceList => _workspaceList;
3129

3230
List<Map<String, dynamic>> tabItems = [
@@ -72,7 +70,6 @@ class DashboardProvider extends StateHandler {
7270
return;
7371
}
7472

75-
// print(res.id);
7673
try {
7774
List<dynamic> _dbWorkspace = await supabase!
7875
.from('workspace')
@@ -85,14 +82,13 @@ class DashboardProvider extends StateHandler {
8582
id: workspace["id"],
8683
owner: workspace["owner"],
8784
name: workspace["name"],
88-
editorIdList: workspace["editorId"] ?? [],
89-
viewerIdList: workspace["viewerId"] ?? [],
85+
editorIdList: (workspace["editorId"] as List?)?.cast<String>() ?? [],
86+
viewerIdList: (workspace["viewerId"] as List?)?.cast<String>() ?? [],
9087
lastEdited:
9188
workspace["last edited"] != null
9289
? DateTime.parse(workspace["last edited"])
9390
: DateTime.now(),
9491
);
95-
// print(workspace);
9692
_workspaceList[newWorkspace.id] = newWorkspace;
9793
}
9894
} catch (e) {
@@ -106,6 +102,14 @@ class DashboardProvider extends StateHandler {
106102
}
107103
}
108104

105+
// New method to update workspace name from WorkspaceProvider
106+
void updateWorkspaceName(String workspaceId, String newName) {
107+
if (_workspaceList.containsKey(workspaceId)) {
108+
_workspaceList[workspaceId] = _workspaceList[workspaceId]!.copyWith(name: newName);
109+
notifyListeners();
110+
}
111+
}
112+
109113
Future<void> createNewProject(BuildContext context) async {
110114
_isLoading = true;
111115
try {
@@ -114,19 +118,19 @@ class DashboardProvider extends StateHandler {
114118
_isLoading = false;
115119
print("User not found");
116120
notifyListeners();
121+
return; // Add return to exit if user is null
117122
}
118-
Map<dynamic, dynamic> newWorkspace = {
123+
Map<String, dynamic> newWorkspaceData = { // Use Map<String, dynamic> for clarity
119124
"id": Uuid().v4(),
120-
"owner": res!.id,
125+
"owner": res.id,
121126
"name": "New Project",
122-
"editorId": null,
123-
"viewerId": null,
127+
"editorId": [], // Initialize as empty list if no editors
128+
"viewerId": [], // Initialize as empty list if no viewers
124129
};
125130

126-
await supabase!.from('workspace').insert(newWorkspace);
131+
await supabase!.from('workspace').insert(newWorkspaceData);
127132

128-
refreshDashboard();
129-
// currentWorkspaceId = newWorkspace["id"];
133+
await refreshDashboard(); // Use await here
130134
} catch (e) {
131135
print("Error creating new project: $e");
132136
} finally {
@@ -136,4 +140,4 @@ class DashboardProvider extends StateHandler {
136140
}
137141

138142
void importExistingProject(BuildContext context) {}
139-
}
143+
}
Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
import 'package:cookethflow/features/models/connection_model.dart';
2-
import 'package:cookethflow/features/models/node_model.dart';
3-
import 'package:flutter/widgets.dart';
1+
// import 'package:cookethflow/features/models/connection_model.dart';
2+
// import 'package:cookethflow/features/models/node_model.dart';
43

54
class WorkspaceModel {
65
String id;
@@ -9,8 +8,8 @@ class WorkspaceModel {
98
List<String> editorIdList;
109
List<String> viewerIdList;
1110
DateTime? lastEdited;
12-
List<NodeModel> nodeList;
13-
List<ConnectionModel> connectionList;
11+
// List<NodeModel> nodeList;
12+
// List<ConnectionModel> connectionList;
1413

1514
WorkspaceModel({
1615
required this.id,
@@ -19,28 +18,29 @@ class WorkspaceModel {
1918
required this.editorIdList,
2019
required this.viewerIdList,
2120
required this.lastEdited,
22-
this.nodeList = const [],
23-
this.connectionList = const [],
21+
// this.nodeList = const [],
22+
// this.connectionList = const [],
2423
});
2524

2625
WorkspaceModel copyWith({
2726
String? id,
2827
String? owner,
28+
String? name,
2929
List<String>? editorIdList,
3030
List<String>? viewerIdList,
3131
DateTime? lastEdited,
32-
List<NodeModel>? nodeList,
33-
List<ConnectionModel>? connectionList,
32+
// List<NodeModel>? nodeList,
33+
// List<ConnectionModel>? connectionList,
3434
}) {
3535
return WorkspaceModel(
3636
id: id ?? this.id,
3737
owner: owner ?? this.owner,
38-
name: name,
38+
name: name ?? this.name,
3939
editorIdList: editorIdList ?? List.from(this.editorIdList),
4040
viewerIdList: viewerIdList ?? List.from(this.viewerIdList),
4141
lastEdited: lastEdited ?? this.lastEdited,
42-
nodeList: nodeList ?? List.from(this.nodeList),
43-
connectionList: connectionList ?? List.from(this.connectionList),
42+
// nodeList: nodeList ?? List.from(this.nodeList),
43+
// connectionList: connectionList ?? List.from(this.connectionList),
4444
);
4545
}
4646

@@ -52,8 +52,8 @@ class WorkspaceModel {
5252
'editorIdList': editorIdList,
5353
'viewerIdList': viewerIdList,
5454
'lastEdited': lastEdited?.toIso8601String(),
55-
'nodeList': nodeList.map((node) => node.toJson()).toList(),
56-
'connectionList': connectionList.map((conn) => conn.toJson()).toList(),
55+
// 'nodeList': nodeList.map((node) => node.toJson()).toList(),
56+
// 'connectionList': connectionList.map((conn) => conn.toJson()).toList(),
5757
};
5858
}
5959

@@ -65,20 +65,20 @@ class WorkspaceModel {
6565
editorIdList: List<String>.from(json['editorIdList']),
6666
viewerIdList: List<String>.from(json['viewerIdList']),
6767
lastEdited: DateTime.parse(json['lastEdited'] as String),
68-
nodeList:
69-
(json['nodeList'] as List<dynamic>)
70-
.map(
71-
(nodeJson) =>
72-
NodeModel.fromJson(nodeJson as Map<String, dynamic>),
73-
)
74-
.toList(),
75-
connectionList:
76-
(json['connectionList'] as List<dynamic>)
77-
.map(
78-
(connJson) =>
79-
ConnectionModel.fromJson(connJson as Map<String, dynamic>),
80-
)
81-
.toList(),
68+
// nodeList:
69+
// (json['nodeList'] as List<dynamic>)
70+
// .map(
71+
// (nodeJson) =>
72+
// NodeModel.fromJson(nodeJson as Map<String, dynamic>),
73+
// )
74+
// .toList(),
75+
// connectionList:
76+
// (json['connectionList'] as List<dynamic>)
77+
// .map(
78+
// (connJson) =>
79+
// ConnectionModel.fromJson(connJson as Map<String, dynamic>),
80+
// )
81+
// .toList(),
8282
);
8383
}
8484
}

lib/features/workspace/pages/desktop/workspace_desktop.dart

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import 'package:cookethflow/core/helpers/responsive_layout.helper.dart' as rh;
2-
import 'package:cookethflow/core/theme/colors.dart';
32
import 'package:cookethflow/features/workspace/pages/canvas_page.dart';
43
import 'package:cookethflow/features/workspace/providers/workspace_provider.dart';
54
import 'package:cookethflow/features/workspace/widgets/export_project_button.dart';
@@ -10,7 +9,6 @@ import 'package:cookethflow/features/workspace/widgets/zoom_control_button.dart'
109
import 'package:flutter/material.dart';
1110
import 'package:provider/provider.dart';
1211
import 'package:flutter_screenutil/flutter_screenutil.dart';
13-
import 'package:phosphor_flutter/phosphor_flutter.dart';
1412

1513
class WorkspaceDesktop extends StatelessWidget {
1614
const WorkspaceDesktop({super.key});

lib/features/workspace/pages/workspace.dart

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import 'package:cookethflow/core/helpers/responsive_layout.helper.dart'
22
as responsive_helper;
33
import 'package:flutter/material.dart';
4-
import 'package:flutter_screenutil/flutter_screenutil.dart';
54
import 'package:cookethflow/features/workspace/pages/desktop/workspace_desktop.dart';
65
import 'package:cookethflow/features/workspace/pages/tablet/workspace_tablet.dart';
76
import 'package:cookethflow/features/workspace/pages/mobile/workspace_mobile.dart';

0 commit comments

Comments
 (0)