Skip to content

Commit ccb3cee

Browse files
committed
feat: accept/reject integrated
1 parent b5a5f48 commit ccb3cee

12 files changed

+303
-188
lines changed

lib/app/router/router.dart

+3-1
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,12 @@ import 'package:spotify_collab_app/view/screens/signup_screen.dart';
99
import 'package:spotify_collab_app/view/screens/home_screen.dart';
1010
import 'package:spotify_collab_app/view/screens/connect_screen.dart';
1111
import 'package:spotify_collab_app/view/screens/splash_screen.dart';
12-
import 'package:spotify_collab_app/view/screens/yay_screen.dart';
1312

1413
final routerProvider = Provider<GoRouter>((ref) {
1514
return GoRouter(
15+
errorBuilder: (context, state) {
16+
return const HomeScreen();
17+
},
1618
initialLocation: '/',
1719
routes: <GoRoute>[
1820
GoRoute(

lib/providers/admin_screen_provider.dart

+42-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import 'dart:convert';
21
import 'dart:developer';
32

43
import 'package:flutter_riverpod/flutter_riverpod.dart';
@@ -56,4 +55,46 @@ class SongsNotifier extends StateNotifier<SongsResponse> {
5655
success: emptySongs.success,
5756
);
5857
}
58+
59+
Future<bool> acceptSong(String uuid, String uri) async {
60+
try {
61+
final response = await apiUtil.post(
62+
'/v1/songs/accept',
63+
{
64+
'playlist_uuid': uuid,
65+
'song_uri': uri,
66+
},
67+
);
68+
69+
log('Song accepted');
70+
if (response.statusCode == 200) {
71+
fetchSongs(uuid);
72+
return true;
73+
}
74+
} catch (e) {
75+
log(e.toString());
76+
}
77+
return false;
78+
}
79+
80+
Future<bool> rejectSong(String uuid, String uri) async {
81+
try {
82+
final response = await apiUtil.post(
83+
'/v1/songs/reject',
84+
{
85+
'playlist_uuid': uuid,
86+
'song_uri': uri,
87+
},
88+
);
89+
90+
log('Song rejected');
91+
if (response.statusCode == 200) {
92+
fetchSongs(uuid);
93+
return true;
94+
}
95+
} catch (e) {
96+
log(e.toString());
97+
}
98+
return false;
99+
}
59100
}

lib/providers/playlist_provider.dart

-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
import 'dart:developer';
2-
31
import 'package:flutter_riverpod/flutter_riverpod.dart';
4-
import 'package:shared_preferences/shared_preferences.dart';
52
import 'package:spotify_collab_app/utils/api_util.dart';
63
import 'package:spotify_collab_app/view/models/playlist_success_response.dart';
74

lib/utils/api_util.dart

-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
import 'dart:convert';
2-
import 'dart:developer';
3-
41
import 'package:dio/dio.dart';
52
import 'package:shared_preferences/shared_preferences.dart';
63
import 'package:spotify_collab_app/constants/constants.dart';

lib/view/screens/admin_screen.dart

+4-3
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,6 @@ class _AdminScreenState extends ConsumerState<AdminScreen>
3939
Future<void> _fetchSongs() async {
4040
final playlistNotifier = ref.read(playlistProvider.notifier);
4141
final songsNotifier = ref.read(songsProvider.notifier);
42-
await playlistNotifier.fetchPlaylists();
43-
await songsNotifier.fetchSongs(playlistNotifier.selectedPlaylistUuid!);
4442

4543
try {
4644
await songsNotifier.fetchSongs(playlistNotifier.selectedPlaylistUuid!);
@@ -225,7 +223,7 @@ class _AdminScreenState extends ConsumerState<AdminScreen>
225223
return (items.isEmpty)
226224
? const Center(
227225
child: Text(
228-
"No songs",
226+
"No songs in playlist.",
229227
style: TextStyle(
230228
fontFamily: 'Gotham',
231229
color: Colors.white,
@@ -250,6 +248,7 @@ class _AdminScreenState extends ConsumerState<AdminScreen>
250248
final item = items[index];
251249
return isPlaylist
252250
? MusicListItem(
251+
id: item.track!.track!.id!,
253252
title: item.track!.track!.name!,
254253
subtitle: item.track!.track!.artists!
255254
.map((artist) => artist.name!)
@@ -261,6 +260,7 @@ class _AdminScreenState extends ConsumerState<AdminScreen>
261260
isParticipant: isParticipant,
262261
)
263262
: MusicListItem(
263+
id: item.track!.track!.id!,
264264
title: item.track!.track!.album!.name!,
265265
subtitle: null,
266266
imageUrl: null,
@@ -351,6 +351,7 @@ class _AdminScreenState extends ConsumerState<AdminScreen>
351351
itemBuilder: (context, index) {
352352
final item = items[index];
353353
return MusicListItem(
354+
id: item.id!,
354355
title: item.name!,
355356
subtitle: item.artists!
356357
.map((artist) => artist.name!)

lib/view/screens/create_screen.dart

+32-6
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,15 @@ class CreateScreen extends ConsumerWidget {
138138
if (eventNameController.text.isEmpty) {
139139
ScaffoldMessenger.of(context).showSnackBar(
140140
const SnackBar(
141-
content: Text('Event name cannot be empty'),
141+
content: Text(
142+
'Event name cannot be empty',
143+
style: TextStyle(
144+
fontFamily: 'Gotham',
145+
color: Colors.white,
146+
fontWeight: FontWeight.w600,
147+
fontSize: 14,
148+
),
149+
),
142150
backgroundColor: Colors.red,
143151
),
144152
);
@@ -151,21 +159,39 @@ class CreateScreen extends ConsumerWidget {
151159
if (response.statusCode == 200) {
152160
if (response.data["message"] ==
153161
"playlist successfully created") {
162+
if (!context.mounted) return;
154163
ScaffoldMessenger.of(context).showSnackBar(
155164
const SnackBar(
156-
content:
157-
Text('Playlist successfully created'),
165+
content: Text(
166+
'Playlist successfully created',
167+
style: TextStyle(
168+
fontFamily: 'Gotham',
169+
color: Colors.white,
170+
fontWeight: FontWeight.w600,
171+
fontSize: 14,
172+
),
173+
),
158174
backgroundColor: Colors.green,
159175
),
160176
);
161177

162178
context.go('/home');
163179
}
164180
} else {
181+
if (!context.mounted) return;
165182
ScaffoldMessenger.of(context).showSnackBar(
166-
const SnackBar(
167-
content: Text('Failed to create playlist'),
168-
backgroundColor: Colors.red,
183+
SnackBar(
184+
content: const Text(
185+
'Failed to create playlist',
186+
style: TextStyle(
187+
fontFamily: 'Gotham',
188+
color: Colors.white,
189+
fontWeight: FontWeight.w600,
190+
fontSize: 14,
191+
),
192+
),
193+
backgroundColor:
194+
Colors.red.withOpacity(0.8),
169195
),
170196
);
171197
}

lib/view/screens/home_screen.dart

+3-157
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ import 'package:flutter_riverpod/flutter_riverpod.dart';
33
import 'package:flutter_svg/flutter_svg.dart';
44
import 'package:go_router/go_router.dart';
55
import 'package:spotify_collab_app/providers/playlist_provider.dart';
6+
import 'package:spotify_collab_app/view/widgets/custom_title.dart';
7+
import 'package:spotify_collab_app/view/widgets/new_playlist_button.dart';
8+
import 'package:spotify_collab_app/view/widgets/playlist_card.dart';
69

710
class HomeScreen extends ConsumerWidget {
811
const HomeScreen({super.key});
@@ -106,161 +109,4 @@ class HomeScreen extends ConsumerWidget {
106109
}
107110
}
108111

109-
class CustomTitle extends StatelessWidget {
110-
const CustomTitle({
111-
super.key,
112-
required this.title,
113-
});
114112

115-
final String title;
116-
117-
@override
118-
Widget build(BuildContext context) {
119-
return Row(
120-
children: [
121-
const Spacer(),
122-
const SizedBox(width: 20),
123-
Text(
124-
title,
125-
style: const TextStyle(
126-
fontFamily: "Gotham",
127-
fontWeight: FontWeight.w700,
128-
fontSize: 34,
129-
shadows: <Shadow>[
130-
Shadow(offset: Offset(0, 1), color: Color(0xffDA84FE)),
131-
],
132-
),
133-
),
134-
Column(
135-
children: [
136-
SvgPicture.asset('assets/highlight.svg'),
137-
const SizedBox(height: 30),
138-
],
139-
),
140-
const Spacer(),
141-
],
142-
);
143-
}
144-
}
145-
146-
class PlaylistCard extends ConsumerWidget {
147-
const PlaylistCard({
148-
super.key,
149-
this.isActive = false,
150-
required this.name,
151-
required this.id,
152-
});
153-
154-
final bool isActive;
155-
final String? name;
156-
final String? id;
157-
158-
@override
159-
Widget build(BuildContext context, WidgetRef ref) {
160-
final playlistNotifier = ref.read(playlistProvider.notifier);
161-
162-
return Row(
163-
children: [
164-
Expanded(
165-
child: Container(
166-
height: 102,
167-
decoration: BoxDecoration(
168-
color: isActive ? const Color(0xff5822EE) : Colors.white,
169-
borderRadius: const BorderRadius.all(Radius.circular(8)),
170-
),
171-
child: Padding(
172-
padding: const EdgeInsets.all(20.0),
173-
child: Row(
174-
children: [
175-
Container(
176-
height: 57,
177-
width: 57,
178-
decoration: const BoxDecoration(
179-
shape: BoxShape.circle,
180-
color: Colors.grey,
181-
),
182-
child: const Icon(Icons.music_note, size: 32),
183-
),
184-
const SizedBox(width: 10),
185-
Column(
186-
crossAxisAlignment: CrossAxisAlignment.start,
187-
children: [
188-
Text(
189-
name ?? '',
190-
style: TextStyle(
191-
fontFamily: "Gotham",
192-
fontWeight: FontWeight.w700,
193-
fontSize: 16,
194-
color: isActive ? Colors.white : Colors.black,
195-
),
196-
),
197-
],
198-
),
199-
const Spacer(),
200-
Align(
201-
alignment: Alignment.bottomRight,
202-
child: Container(
203-
width: 97,
204-
height: 31,
205-
decoration: BoxDecoration(
206-
color:
207-
!isActive ? const Color(0xff5822EE) : Colors.white,
208-
borderRadius:
209-
const BorderRadius.all(Radius.circular(8)),
210-
),
211-
child: Center(
212-
child: TextButton(
213-
onPressed: () {
214-
playlistNotifier.selectedPlaylistUuid = id ?? '';
215-
playlistNotifier.selectedPlaylistName = name ?? '';
216-
context.push("/admin");
217-
},
218-
child: Text(
219-
isActive ? "Manage" : "View",
220-
style: TextStyle(
221-
color: isActive
222-
? const Color(0xff5822EE)
223-
: Colors.white,
224-
fontFamily: "Gotham",
225-
fontWeight: FontWeight.w700,
226-
fontSize: 16,
227-
),
228-
),
229-
)),
230-
),
231-
),
232-
],
233-
),
234-
),
235-
),
236-
),
237-
],
238-
);
239-
}
240-
}
241-
242-
class NewPlaylistButton extends StatelessWidget {
243-
const NewPlaylistButton({super.key});
244-
245-
@override
246-
Widget build(BuildContext context) {
247-
return Row(
248-
children: [
249-
Expanded(
250-
child: Container(
251-
height: 59,
252-
decoration: const BoxDecoration(
253-
color: Colors.white,
254-
borderRadius: BorderRadius.all(Radius.circular(8)),
255-
),
256-
child: const Icon(
257-
Icons.add_circle,
258-
color: Color(0xff5822EE),
259-
size: 43,
260-
),
261-
),
262-
),
263-
],
264-
);
265-
}
266-
}

lib/view/screens/yay_screen.dart

+4-9
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@ import 'dart:async';
22
import 'package:flutter/material.dart';
33
import 'package:flutter_riverpod/flutter_riverpod.dart';
44
import 'package:flutter_svg/flutter_svg.dart';
5-
import 'package:spotify_collab_app/constants/constants.dart';
6-
import 'package:url_launcher/url_launcher.dart';
75
import 'package:text_marquee/text_marquee.dart';
86

97
class YayScreen extends ConsumerStatefulWidget {
@@ -27,11 +25,6 @@ class ConnectScreenState extends ConsumerState<YayScreen> {
2725
super.dispose();
2826
}
2927

30-
Future<void> _launchSpotifyLogin() async {
31-
const url = '$devUrl/v1/auth/spotify/login/app';
32-
launchUrl(Uri.parse(url));
33-
}
34-
3528
@override
3629
Widget build(BuildContext context) {
3730
return Scaffold(
@@ -117,7 +110,7 @@ class PlaylistCard extends StatelessWidget {
117110
this.isActive = false,
118111
this.name = "DevJams' 24",
119112
this.host = "Souvik",
120-
this.img = "assets/dino.png"});
113+
this.img = "assets/dino.png", String? id});
121114

122115
final bool isActive;
123116
final String name;
@@ -163,7 +156,9 @@ class PlaylistCard extends StatelessWidget {
163156
mainAxisAlignment: MainAxisAlignment.start,
164157
crossAxisAlignment: CrossAxisAlignment.start,
165158
children: [
166-
SizedBox(height: 10,),
159+
const SizedBox(
160+
height: 10,
161+
),
167162
Row(children: [
168163
const Text(
169164
"Event:",

0 commit comments

Comments
 (0)