Skip to content

Commit 874adb5

Browse files
committed
feat: url with workspace id
1 parent d1fe593 commit 874adb5

8 files changed

Lines changed: 413 additions & 364 deletions

File tree

lib/core/router/app_route_config.dart

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,13 @@ import 'package:cookethflow/core/router/app_route_const.dart';
22
import 'package:cookethflow/features/auth/pages/login.dart';
33
import 'package:cookethflow/features/auth/pages/signup.dart';
44
import 'package:cookethflow/features/dashboard/pages/dashboard.dart';
5-
import 'package:cookethflow/features/workspace/pages/canvas_page.dart';
65
import 'package:cookethflow/features/workspace/pages/workspace.dart';
76
import 'package:flutter/material.dart';
87
import 'package:go_router/go_router.dart';
98

109
class AppRouteConfig {
1110
static GoRouter returnRouter() {
1211
return GoRouter(
13-
// observers: [
14-
// (route)=> debugPrint('Route Changed: $(route)'),
15-
// ],
1612
initialLocation: RoutesPath.loginScreen,
1713
routes: [
1814
GoRoute(
@@ -27,22 +23,19 @@ class AppRouteConfig {
2723
(context, state) => NoTransitionPage(child: SignupPage()),
2824
),
2925
GoRoute(
30-
path: RoutesPath.dashboard,
26+
path: '${RoutesPath.dashboard}/u/:username',
3127
name: RouteName.dashboard,
32-
pageBuilder:
33-
(context, state) => NoTransitionPage(child: DashboardPage()),
28+
pageBuilder: (context, state) {
29+
final username = state.pathParameters["username"];
30+
return NoTransitionPage(child: DashboardPage());
31+
},
3432
),
3533
GoRoute(
36-
path: RoutesPath.workspace,
34+
path: '${RoutesPath.workspace}/:workspace_id',
3735
name: RouteName.workspace,
38-
pageBuilder:
39-
(context, state) => NoTransitionPage(child: WorkspacePage()),
40-
),
41-
GoRoute(
42-
path: RoutesPath.canvasPage,
43-
name: RouteName.canvasPage,
4436
pageBuilder: (context, state) {
45-
return NoTransitionPage(child: CanvasPage());
37+
final workspace_id = state.pathParameters['workspace_id'];
38+
return NoTransitionPage(child: WorkspacePage());
4639
},
4740
),
4841
],

lib/features/auth/widgets/login_form.dart

Lines changed: 269 additions & 240 deletions
Large diffs are not rendered by default.

lib/features/auth/widgets/signup_form.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ class SignUpForm extends StatelessWidget {
2626
// Listener for social logins to automatically navigate after successful authentication
2727
if (supabaseService.currentUser != null && GoRouter.of(context).routerDelegate.currentConfiguration?.fullPath != RoutesPath.dashboard) {
2828
WidgetsBinding.instance.addPostFrameCallback((_) {
29-
context.go(RoutesPath.dashboard);
29+
// context.go(RoutesPath.dashboard);
30+
context.goNamed(RouteName.dashboard,pathParameters: {'username': supabaseService.currentUser!.name!});
3031
authProvider.setLoading(false); // Ensure loading is off after navigation
3132
});
3233
}

lib/features/dashboard/pages/desktop/dashboard_desktop.dart

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,9 @@ class DashboardDesktop extends StatelessWidget {
5959
childAspectRatio: 4.5 / 3,
6060
),
6161
itemBuilder: (context, index) {
62-
return ProjectCard(idx: index);
62+
final workspaceId = provider.workspaceList.keys
63+
.elementAt(index);
64+
return ProjectCard(workspaceId: workspaceId);
6365
},
6466
),
6567
),

lib/features/dashboard/providers/dashboard_provider.dart

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import 'package:uuid/uuid.dart';
99
class DashboardProvider extends StateHandler {
1010
late SupabaseClient? supabase;
1111
late SupabaseService supabaseService;
12-
late String currentWorkspaceId;
1312
DashboardProvider(this.supabase, this.supabaseService) : super() {
1413
initialize();
1514
}
@@ -19,14 +18,16 @@ class DashboardProvider extends StateHandler {
1918
int _tabIndex = 0;
2019
bool _isLoading = false;
2120
bool _isInitialized = false;
22-
List<WorkspaceModel> _workspaceList = [];
21+
// List<WorkspaceModel> _workspaceList = [];
22+
Map<String, WorkspaceModel> _workspaceList = {};
2323

2424
// getters
2525
bool get isDrawerOpen => _isDrawerOpen;
2626
int get tabIndex => _tabIndex;
2727
bool get isLoading => _isLoading;
2828
bool get isInitialized => _isInitialized;
29-
List<WorkspaceModel> get workspaceList => _workspaceList;
29+
// List<WorkspaceModel> get workspaceList => _workspaceList;
30+
Map<String, WorkspaceModel> get workspaceList => _workspaceList;
3031

3132
List<Map<String, dynamic>> tabItems = [
3233
{"label": "All", "icon": Icon(PhosphorIcons.cardsThree())},
@@ -92,7 +93,7 @@ class DashboardProvider extends StateHandler {
9293
: DateTime.now(),
9394
);
9495
// print(workspace);
95-
_workspaceList.add(newWorkspace);
96+
_workspaceList[newWorkspace.id] = newWorkspace;
9697
}
9798
} catch (e) {
9899
print("Error parsing workspaces: $e");
@@ -125,7 +126,7 @@ class DashboardProvider extends StateHandler {
125126
await supabase!.from('workspace').insert(newWorkspace);
126127

127128
refreshDashboard();
128-
currentWorkspaceId = newWorkspace["id"];
129+
// currentWorkspaceId = newWorkspace["id"];
129130
} catch (e) {
130131
print("Error creating new project: $e");
131132
} finally {

lib/features/dashboard/widgets/project_card.dart

Lines changed: 104 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -1,119 +1,131 @@
11
import 'package:cookethflow/core/helpers/date_time_helper.dart';
2+
import 'package:cookethflow/core/router/app_route_const.dart';
23
import 'package:cookethflow/features/dashboard/providers/dashboard_provider.dart';
4+
import 'package:cookethflow/features/workspace/pages/workspace.dart';
5+
import 'package:cookethflow/features/workspace/providers/workspace_provider.dart';
36
import 'package:flutter/material.dart';
47
import 'package:flutter_screenutil/flutter_screenutil.dart';
8+
import 'package:go_router/go_router.dart';
59
import 'package:phosphor_flutter/phosphor_flutter.dart';
610
import 'package:provider/provider.dart';
711

812
class ProjectCard extends StatelessWidget {
9-
const ProjectCard({super.key, required this.idx});
10-
final int idx;
13+
const ProjectCard({super.key, required this.workspaceId});
14+
final String workspaceId;
1115

1216
@override
1317
Widget build(BuildContext context) {
1418
DateTimeHelper dth = DateTimeHelper();
15-
return Consumer<DashboardProvider>(
16-
builder: (context, provider, child) {
17-
return Container(
18-
decoration: BoxDecoration(
19-
color: Colors.white,
20-
borderRadius: BorderRadius.circular(12.r),
21-
border: Border.all(color: const Color(0xFFD9D9D9), width: 1.2),
22-
),
23-
child: Column(
24-
crossAxisAlignment: CrossAxisAlignment.stretch,
25-
children: [
26-
Expanded(
27-
flex: 2,
28-
child: Container(
29-
decoration: BoxDecoration(
30-
color: const Color(0xFFD3D3D3),
31-
borderRadius: BorderRadius.only(
32-
topLeft: Radius.circular(12.r),
33-
topRight: Radius.circular(12.r),
19+
return Consumer2<DashboardProvider, WorkspaceProvider>(
20+
builder: (context, provider, workspaceProvider, child) {
21+
return GestureDetector(
22+
onTap: () {
23+
workspaceProvider.setWorkspace(workspaceId);
24+
context.goNamed(RouteName.workspace,pathParameters: {'workspace_id':workspaceId});
25+
},
26+
child: Container(
27+
decoration: BoxDecoration(
28+
color: Colors.white,
29+
borderRadius: BorderRadius.circular(12.r),
30+
border: Border.all(color: const Color(0xFFD9D9D9), width: 1.2),
31+
),
32+
child: Column(
33+
crossAxisAlignment: CrossAxisAlignment.stretch,
34+
children: [
35+
Expanded(
36+
flex: 2,
37+
child: Container(
38+
decoration: BoxDecoration(
39+
color: const Color(0xFFD3D3D3),
40+
borderRadius: BorderRadius.only(
41+
topLeft: Radius.circular(12.r),
42+
topRight: Radius.circular(12.r),
43+
),
3444
),
35-
),
36-
child: Stack(
37-
children: [
38-
// Center(
39-
// child: Image.asset(
40-
// 'assets/images/Frame 400.png',
41-
// fit: BoxFit.cover,
42-
// ),
43-
// ),
44-
Positioned(
45-
top: 12.h,
46-
right: 12.w,
47-
child: Container(
48-
padding: EdgeInsets.all(8.w),
49-
decoration: BoxDecoration(
50-
color: Colors.white,
51-
borderRadius: BorderRadius.circular(12.r),
52-
),
53-
child: IconButton(
54-
onPressed: () {},
55-
icon: Icon(
56-
PhosphorIconsRegular.dotsThree,
57-
size: 32.sp,
58-
color: Colors.black,
45+
child: Stack(
46+
children: [
47+
// Center(
48+
// child: Image.asset(
49+
// 'assets/images/Frame 400.png',
50+
// fit: BoxFit.cover,
51+
// ),
52+
// ),
53+
Positioned(
54+
top: 12.h,
55+
right: 12.w,
56+
child: Container(
57+
padding: EdgeInsets.all(8.w),
58+
decoration: BoxDecoration(
59+
color: Colors.white,
60+
borderRadius: BorderRadius.circular(12.r),
61+
),
62+
child: IconButton(
63+
onPressed: () {},
64+
icon: Icon(
65+
PhosphorIconsRegular.dotsThree,
66+
size: 32.sp,
67+
color: Colors.black,
68+
),
5969
),
6070
),
6171
),
62-
),
63-
],
72+
],
73+
),
6474
),
6575
),
66-
),
67-
Expanded(
68-
flex: 1,
69-
child: Padding(
70-
padding: EdgeInsets.symmetric(horizontal: 24, vertical: 16),
71-
child: Row(
72-
crossAxisAlignment: CrossAxisAlignment.start,
73-
children: [
74-
Expanded(
75-
child: Column(
76-
crossAxisAlignment: CrossAxisAlignment.start,
77-
mainAxisAlignment: MainAxisAlignment.center,
78-
children: [
79-
Text(
80-
provider.workspaceList[idx].name ??
81-
"Name not fetched",
82-
style: TextStyle(
83-
fontFamily: 'Fredrik',
84-
fontSize: 20.sp,
85-
color: Colors.black,
86-
fontWeight: FontWeight.w600,
87-
),
88-
),
89-
SizedBox(height: 4.h),
90-
Text(
91-
dth.formatLastEdited(
92-
provider.workspaceList[idx].lastEdited,
76+
Expanded(
77+
flex: 1,
78+
child: Padding(
79+
padding: EdgeInsets.symmetric(horizontal: 24, vertical: 16),
80+
child: Row(
81+
crossAxisAlignment: CrossAxisAlignment.start,
82+
children: [
83+
Expanded(
84+
child: Column(
85+
crossAxisAlignment: CrossAxisAlignment.start,
86+
mainAxisAlignment: MainAxisAlignment.center,
87+
children: [
88+
Text(
89+
provider.workspaceList[workspaceId]?.name ??
90+
"Name not fetched",
91+
style: TextStyle(
92+
fontFamily: 'Fredrik',
93+
fontSize: 20.sp,
94+
color: Colors.black,
95+
fontWeight: FontWeight.w600,
96+
),
9397
),
94-
style: TextStyle(
95-
fontFamily: 'Fredrik',
96-
color: Colors.grey[600],
97-
fontSize: 14.sp,
98-
fontWeight: FontWeight.w500,
98+
SizedBox(height: 4.h),
99+
Text(
100+
dth.formatLastEdited(
101+
provider
102+
.workspaceList[workspaceId]
103+
?.lastEdited,
104+
),
105+
style: TextStyle(
106+
fontFamily: 'Fredrik',
107+
color: Colors.grey[600],
108+
fontSize: 14.sp,
109+
fontWeight: FontWeight.w500,
110+
),
99111
),
100-
),
101-
],
112+
],
113+
),
102114
),
103-
),
104-
IconButton(
105-
onPressed: () {},
106-
icon: Icon(
107-
PhosphorIconsRegular.star,
108-
size: 32.sp,
109-
color: Colors.black54,
115+
IconButton(
116+
onPressed: () {},
117+
icon: Icon(
118+
PhosphorIconsRegular.star,
119+
size: 32.sp,
120+
color: Colors.black54,
121+
),
110122
),
111-
),
112-
],
123+
],
124+
),
113125
),
114126
),
115-
),
116-
],
127+
],
128+
),
117129
),
118130
);
119131
},

lib/features/workspace/providers/workspace_provider.dart

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import 'package:cookethflow/features/models/canvas_models/objects/rounded_square
1717
import 'package:cookethflow/features/models/canvas_models/objects/square_object.dart';
1818
import 'package:cookethflow/features/models/canvas_models/objects/triangle_object.dart';
1919
import 'package:cookethflow/features/models/canvas_models/user_cursor.dart';
20+
import 'package:cookethflow/features/models/workspace_model.dart';
2021
import 'package:flutter/material.dart';
2122
import 'package:supabase_flutter/supabase_flutter.dart';
2223
import 'package:uuid/uuid.dart';
@@ -43,8 +44,10 @@ class WorkspaceProvider extends StateHandler {
4344
static const double _defaultShapeSize = 100.0;
4445
static const double _handleRadius = 8.0;
4546
Color _currentWorkspaceColor = scaffoldColor;
46-
String _currentworkspaceId = "";
47-
TextEditingController _workspaceNameController = TextEditingController(text: 'Workspace Name');
47+
late WorkspaceModel _currentWorkspace;
48+
TextEditingController _workspaceNameController = TextEditingController(
49+
text: 'Workspace Name',
50+
);
4851

4952
bool get isLoading => _isLoading;
5053
bool get isDrawerOpen => _isDrawerOpen;
@@ -62,8 +65,9 @@ class WorkspaceProvider extends StateHandler {
6265
double get defaultShapeSize => _defaultShapeSize;
6366
double get handleRadius => _handleRadius;
6467
Color get currentWorkspaceColor => _currentWorkspaceColor;
65-
String get currentworkspaceId => _currentworkspaceId;
68+
WorkspaceModel get currentWorkspace => _currentWorkspace;
6669
TextEditingController get workspaceNameController => _workspaceNameController;
70+
SupabaseService get supabaseService => _supabaseService;
6771

6872
// New getter to easily check if any tile is selected for the drawer's border
6973
bool get hasSelectedTile => _selectedTileIndex != null;
@@ -99,8 +103,9 @@ class WorkspaceProvider extends StateHandler {
99103
notifyListeners();
100104
}
101105

102-
void setWorkspaceId() {
103-
_currentworkspaceId = _dashboardProvider.currentWorkspaceId;
106+
void setWorkspace(String id) {
107+
_currentWorkspace = _dashboardProvider.workspaceList[id]!;
108+
_workspaceNameController.text = _currentWorkspace.name;
104109
notifyListeners();
105110
}
106111

0 commit comments

Comments
 (0)