Skip to content

Commit b4a39f6

Browse files
committed
feat: workspace creation limit set to 10, workspace last edited automated the timestamp
1 parent 34f37d2 commit b4a39f6

File tree

3 files changed

+78
-55
lines changed

3 files changed

+78
-55
lines changed

lib/core/providers/supabase_provider.dart

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -136,9 +136,9 @@ class SupabaseService extends StateHandler {
136136
// and added to your Supabase Auth Providers -> Google -> Redirect URIs
137137
// For desktop, usually 'http://localhost:port' or similar is used.
138138
final String? redirectUrl =
139-
kIsWeb?
140-
'http://cookethflow.cookethcompany.xyz/dashboard' // For web development
141-
// 'http://localhost:3000/dashboard'
139+
kIsWeb? kReleaseMode ?
140+
'http://cookethflow.cookethcompany.xyz/dashboard':
141+
'http://localhost:3000/dashboard'
142142
: (Platform.isAndroid || Platform.isIOS
143143
? 'myapp://login-callback/'
144144
: null); // For mobile/desktop
@@ -162,9 +162,9 @@ class SupabaseService extends StateHandler {
162162
Future<String> signInWithGithub() async {
163163
try {
164164
final String? redirectUrl =
165-
kIsWeb?
166-
'http://cookethflow.cookethcompany.xyz/dashboard'
167-
// 'http://localhost:3000/dashboard'
165+
kIsWeb? kReleaseMode ?
166+
'http://cookethflow.cookethcompany.xyz/dashboard':
167+
'http://localhost:3000/dashboard'
168168
: (Platform.isAndroid || Platform.isIOS
169169
? 'my.scheme://my-host'
170170
: null); // Replace with your actual scheme

lib/features/dashboard/providers/dashboard_provider.dart

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,10 @@ class DashboardProvider extends StateHandler {
2929

3030
List<WorkspaceModel> get displayedWorkspaces {
3131
final allWorkspaces = _workspaceList.values.toList();
32-
allWorkspaces.sort((a, b) => (b.lastEdited ?? DateTime(0)).compareTo(a.lastEdited ?? DateTime(0)));
32+
allWorkspaces.sort(
33+
(a, b) =>
34+
(b.lastEdited ?? DateTime(0)).compareTo(a.lastEdited ?? DateTime(0)),
35+
);
3336

3437
switch (_tabIndex) {
3538
case 1: // Starred
@@ -128,7 +131,9 @@ class DashboardProvider extends StateHandler {
128131
final workspace = _workspaceList[workspaceId];
129132
if (workspace == null) return;
130133

131-
final updatedWorkspace = workspace.copyWith(isStarred: !workspace.isStarred);
134+
final updatedWorkspace = workspace.copyWith(
135+
isStarred: !workspace.isStarred,
136+
);
132137
_workspaceList[workspaceId] = updatedWorkspace;
133138
notifyListeners();
134139

@@ -146,15 +151,15 @@ class DashboardProvider extends StateHandler {
146151
}
147152
}
148153

149-
Future<void> createNewProject(BuildContext context) async {
154+
Future<String> createNewProject(BuildContext context) async {
150155
_isLoading = true;
151156
try {
152157
var res = supabase?.auth.currentUser;
153158
if (res == null) {
154159
_isLoading = false;
155160
print("User not found");
156161
notifyListeners();
157-
return;
162+
return 'User not found';
158163
}
159164
Map<String, dynamic> newWorkspaceData = {
160165
"id": Uuid().v4(),
@@ -168,8 +173,15 @@ class DashboardProvider extends StateHandler {
168173
await supabase!.from('workspace').insert(newWorkspaceData);
169174

170175
await refreshDashboard();
176+
return 'Workspace created successfully!!';
171177
} catch (e) {
172178
print("Error creating new project: $e");
179+
String output = e.toString();
180+
if (e.toString() ==
181+
'PostgrestException(message: User has reached the maximum limit of 10 workspaces., code: P0001, details: , hint: null)') {
182+
output = 'Maximum limit of workspaces reached. Upgrade your plan for more!';
183+
}
184+
return output;
173185
} finally {
174186
_isLoading = false;
175187
notifyListeners();
@@ -219,21 +231,15 @@ class DashboardProvider extends StateHandler {
219231

220232
try {
221233
print('Deleting canvas_objects for workspace: $id');
222-
await supabase!
223-
.from('canvas_objects')
224-
.delete()
225-
.eq('workspace_id', id);
234+
await supabase!.from('canvas_objects').delete().eq('workspace_id', id);
226235
print('Canvas objects for workspace $id deleted from database.');
227236

228237
print('Deleting workspace: $id');
229-
await supabase!
230-
.from('workspace')
231-
.delete()
232-
.eq('id', id);
238+
await supabase!.from('workspace').delete().eq('id', id);
233239
print('Workspace $id deleted from database.');
234240

235241
_workspaceList.remove(id);
236-
242+
237243
print("Workspace $id removed from local list.");
238244
} catch (e) {
239245
print("Error deleting workspace $id: $e");
@@ -243,4 +249,4 @@ class DashboardProvider extends StateHandler {
243249
await refreshDashboard();
244250
}
245251
}
246-
}
252+
}

lib/features/dashboard/widgets/add_project_dialogue.dart

Lines changed: 52 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -12,40 +12,57 @@ class AddProject extends StatelessWidget {
1212

1313
@override
1414
Widget build(BuildContext context) {
15-
return Consumer2<DashboardProvider,SupabaseService>(builder: (context, provider,suprovider, child) {
16-
return AlertDialog(
17-
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(12)),
18-
title: Text(
19-
'Create Project',
20-
style: TextStyle(fontFamily: 'Frederik',fontSize: 28.sp ,fontWeight: FontWeight.bold),
21-
),
22-
content: Column(
23-
mainAxisSize: MainAxisSize.min,
24-
children: [
25-
BuildProject(
26-
icon: PhosphorIconsRegular.plus,
27-
label: 'Start Blank Project',
28-
onTap: () async {
29-
context.pop();
30-
provider.createNewProject(context);
31-
},
32-
txtColor: suprovider.isDark?Colors.white:Colors.black,
33-
borderColor: suprovider.isDark?Colors.white:Colors.black,
15+
return Consumer2<DashboardProvider, SupabaseService>(
16+
builder: (context, provider, suprovider, child) {
17+
return AlertDialog(
18+
shape: RoundedRectangleBorder(
19+
borderRadius: BorderRadius.circular(12),
20+
),
21+
title: Text(
22+
'Create Project',
23+
style: TextStyle(
24+
fontFamily: 'Frederik',
25+
fontSize: 28.sp,
26+
fontWeight: FontWeight.bold,
3427
),
35-
SizedBox(height: 16),
36-
BuildProject(
37-
icon: PhosphorIconsRegular.fileArrowDown,
38-
label: 'Import Existing Project',
39-
onTap: () async {
40-
context.pop();
41-
provider.importExistingProject(context);
42-
},
43-
txtColor: suprovider.isDark?Colors.white:Colors.black,
44-
borderColor: suprovider.isDark?Colors.white:Colors.black,
45-
),
46-
],
47-
),
48-
);
49-
});
28+
),
29+
content: Column(
30+
mainAxisSize: MainAxisSize.min,
31+
children: [
32+
BuildProject(
33+
icon: PhosphorIconsRegular.plus,
34+
label: 'Start Blank Project',
35+
onTap: () async {
36+
String output = await provider.createNewProject(context);
37+
if (output != 'Workspace created successfully!!') {
38+
ScaffoldMessenger.of(context).showSnackBar(
39+
SnackBar(
40+
content: Text(output),
41+
backgroundColor: Colors.lightGreen,
42+
duration: const Duration(seconds: 3),
43+
),
44+
);
45+
}
46+
context.pop();
47+
},
48+
txtColor: suprovider.isDark ? Colors.white : Colors.black,
49+
borderColor: suprovider.isDark ? Colors.white : Colors.black,
50+
),
51+
SizedBox(height: 16),
52+
BuildProject(
53+
icon: PhosphorIconsRegular.fileArrowDown,
54+
label: 'Import Existing Project',
55+
onTap: () async {
56+
context.pop();
57+
provider.importExistingProject(context);
58+
},
59+
txtColor: suprovider.isDark ? Colors.white : Colors.black,
60+
borderColor: suprovider.isDark ? Colors.white : Colors.black,
61+
),
62+
],
63+
),
64+
);
65+
},
66+
);
5067
}
51-
}
68+
}

0 commit comments

Comments
 (0)