Skip to content

Commit

Permalink
feat: accept/reject integrated
Browse files Browse the repository at this point in the history
  • Loading branch information
JothishKamal committed Dec 29, 2024
1 parent b5a5f48 commit ccb3cee
Show file tree
Hide file tree
Showing 12 changed files with 303 additions and 188 deletions.
4 changes: 3 additions & 1 deletion lib/app/router/router.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@ import 'package:spotify_collab_app/view/screens/signup_screen.dart';
import 'package:spotify_collab_app/view/screens/home_screen.dart';
import 'package:spotify_collab_app/view/screens/connect_screen.dart';
import 'package:spotify_collab_app/view/screens/splash_screen.dart';
import 'package:spotify_collab_app/view/screens/yay_screen.dart';

final routerProvider = Provider<GoRouter>((ref) {
return GoRouter(
errorBuilder: (context, state) {
return const HomeScreen();
},
initialLocation: '/',
routes: <GoRoute>[
GoRoute(
Expand Down
43 changes: 42 additions & 1 deletion lib/providers/admin_screen_provider.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import 'dart:convert';
import 'dart:developer';

import 'package:flutter_riverpod/flutter_riverpod.dart';
Expand Down Expand Up @@ -56,4 +55,46 @@ class SongsNotifier extends StateNotifier<SongsResponse> {
success: emptySongs.success,
);
}

Future<bool> acceptSong(String uuid, String uri) async {
try {
final response = await apiUtil.post(
'/v1/songs/accept',
{
'playlist_uuid': uuid,
'song_uri': uri,
},
);

log('Song accepted');
if (response.statusCode == 200) {
fetchSongs(uuid);
return true;
}
} catch (e) {
log(e.toString());
}
return false;
}

Future<bool> rejectSong(String uuid, String uri) async {
try {
final response = await apiUtil.post(
'/v1/songs/reject',
{
'playlist_uuid': uuid,
'song_uri': uri,
},
);

log('Song rejected');
if (response.statusCode == 200) {
fetchSongs(uuid);
return true;
}
} catch (e) {
log(e.toString());
}
return false;
}
}
3 changes: 0 additions & 3 deletions lib/providers/playlist_provider.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
import 'dart:developer';

import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:spotify_collab_app/utils/api_util.dart';
import 'package:spotify_collab_app/view/models/playlist_success_response.dart';

Expand Down
3 changes: 0 additions & 3 deletions lib/utils/api_util.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
import 'dart:convert';
import 'dart:developer';

import 'package:dio/dio.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:spotify_collab_app/constants/constants.dart';
Expand Down
7 changes: 4 additions & 3 deletions lib/view/screens/admin_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@ class _AdminScreenState extends ConsumerState<AdminScreen>
Future<void> _fetchSongs() async {
final playlistNotifier = ref.read(playlistProvider.notifier);
final songsNotifier = ref.read(songsProvider.notifier);
await playlistNotifier.fetchPlaylists();
await songsNotifier.fetchSongs(playlistNotifier.selectedPlaylistUuid!);

try {
await songsNotifier.fetchSongs(playlistNotifier.selectedPlaylistUuid!);
Expand Down Expand Up @@ -225,7 +223,7 @@ class _AdminScreenState extends ConsumerState<AdminScreen>
return (items.isEmpty)
? const Center(
child: Text(
"No songs",
"No songs in playlist.",
style: TextStyle(
fontFamily: 'Gotham',
color: Colors.white,
Expand All @@ -250,6 +248,7 @@ class _AdminScreenState extends ConsumerState<AdminScreen>
final item = items[index];
return isPlaylist
? MusicListItem(
id: item.track!.track!.id!,
title: item.track!.track!.name!,
subtitle: item.track!.track!.artists!
.map((artist) => artist.name!)
Expand All @@ -261,6 +260,7 @@ class _AdminScreenState extends ConsumerState<AdminScreen>
isParticipant: isParticipant,
)
: MusicListItem(
id: item.track!.track!.id!,
title: item.track!.track!.album!.name!,
subtitle: null,
imageUrl: null,
Expand Down Expand Up @@ -351,6 +351,7 @@ class _AdminScreenState extends ConsumerState<AdminScreen>
itemBuilder: (context, index) {
final item = items[index];
return MusicListItem(
id: item.id!,
title: item.name!,
subtitle: item.artists!
.map((artist) => artist.name!)
Expand Down
38 changes: 32 additions & 6 deletions lib/view/screens/create_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,15 @@ class CreateScreen extends ConsumerWidget {
if (eventNameController.text.isEmpty) {
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(
content: Text('Event name cannot be empty'),
content: Text(
'Event name cannot be empty',
style: TextStyle(
fontFamily: 'Gotham',
color: Colors.white,
fontWeight: FontWeight.w600,
fontSize: 14,
),
),
backgroundColor: Colors.red,
),
);
Expand All @@ -151,21 +159,39 @@ class CreateScreen extends ConsumerWidget {
if (response.statusCode == 200) {
if (response.data["message"] ==
"playlist successfully created") {
if (!context.mounted) return;
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(
content:
Text('Playlist successfully created'),
content: Text(
'Playlist successfully created',
style: TextStyle(
fontFamily: 'Gotham',
color: Colors.white,
fontWeight: FontWeight.w600,
fontSize: 14,
),
),
backgroundColor: Colors.green,
),
);

context.go('/home');
}
} else {
if (!context.mounted) return;
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(
content: Text('Failed to create playlist'),
backgroundColor: Colors.red,
SnackBar(
content: const Text(
'Failed to create playlist',
style: TextStyle(
fontFamily: 'Gotham',
color: Colors.white,
fontWeight: FontWeight.w600,
fontSize: 14,
),
),
backgroundColor:
Colors.red.withOpacity(0.8),
),
);
}
Expand Down
160 changes: 3 additions & 157 deletions lib/view/screens/home_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:flutter_svg/flutter_svg.dart';
import 'package:go_router/go_router.dart';
import 'package:spotify_collab_app/providers/playlist_provider.dart';
import 'package:spotify_collab_app/view/widgets/custom_title.dart';
import 'package:spotify_collab_app/view/widgets/new_playlist_button.dart';
import 'package:spotify_collab_app/view/widgets/playlist_card.dart';

class HomeScreen extends ConsumerWidget {
const HomeScreen({super.key});
Expand Down Expand Up @@ -106,161 +109,4 @@ class HomeScreen extends ConsumerWidget {
}
}

class CustomTitle extends StatelessWidget {
const CustomTitle({
super.key,
required this.title,
});

final String title;

@override
Widget build(BuildContext context) {
return Row(
children: [
const Spacer(),
const SizedBox(width: 20),
Text(
title,
style: const TextStyle(
fontFamily: "Gotham",
fontWeight: FontWeight.w700,
fontSize: 34,
shadows: <Shadow>[
Shadow(offset: Offset(0, 1), color: Color(0xffDA84FE)),
],
),
),
Column(
children: [
SvgPicture.asset('assets/highlight.svg'),
const SizedBox(height: 30),
],
),
const Spacer(),
],
);
}
}

class PlaylistCard extends ConsumerWidget {
const PlaylistCard({
super.key,
this.isActive = false,
required this.name,
required this.id,
});

final bool isActive;
final String? name;
final String? id;

@override
Widget build(BuildContext context, WidgetRef ref) {
final playlistNotifier = ref.read(playlistProvider.notifier);

return Row(
children: [
Expanded(
child: Container(
height: 102,
decoration: BoxDecoration(
color: isActive ? const Color(0xff5822EE) : Colors.white,
borderRadius: const BorderRadius.all(Radius.circular(8)),
),
child: Padding(
padding: const EdgeInsets.all(20.0),
child: Row(
children: [
Container(
height: 57,
width: 57,
decoration: const BoxDecoration(
shape: BoxShape.circle,
color: Colors.grey,
),
child: const Icon(Icons.music_note, size: 32),
),
const SizedBox(width: 10),
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
name ?? '',
style: TextStyle(
fontFamily: "Gotham",
fontWeight: FontWeight.w700,
fontSize: 16,
color: isActive ? Colors.white : Colors.black,
),
),
],
),
const Spacer(),
Align(
alignment: Alignment.bottomRight,
child: Container(
width: 97,
height: 31,
decoration: BoxDecoration(
color:
!isActive ? const Color(0xff5822EE) : Colors.white,
borderRadius:
const BorderRadius.all(Radius.circular(8)),
),
child: Center(
child: TextButton(
onPressed: () {
playlistNotifier.selectedPlaylistUuid = id ?? '';
playlistNotifier.selectedPlaylistName = name ?? '';
context.push("/admin");
},
child: Text(
isActive ? "Manage" : "View",
style: TextStyle(
color: isActive
? const Color(0xff5822EE)
: Colors.white,
fontFamily: "Gotham",
fontWeight: FontWeight.w700,
fontSize: 16,
),
),
)),
),
),
],
),
),
),
),
],
);
}
}

class NewPlaylistButton extends StatelessWidget {
const NewPlaylistButton({super.key});

@override
Widget build(BuildContext context) {
return Row(
children: [
Expanded(
child: Container(
height: 59,
decoration: const BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.all(Radius.circular(8)),
),
child: const Icon(
Icons.add_circle,
color: Color(0xff5822EE),
size: 43,
),
),
),
],
);
}
}
13 changes: 4 additions & 9 deletions lib/view/screens/yay_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ import 'dart:async';
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:flutter_svg/flutter_svg.dart';
import 'package:spotify_collab_app/constants/constants.dart';
import 'package:url_launcher/url_launcher.dart';
import 'package:text_marquee/text_marquee.dart';

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

Future<void> _launchSpotifyLogin() async {
const url = '$devUrl/v1/auth/spotify/login/app';
launchUrl(Uri.parse(url));
}

@override
Widget build(BuildContext context) {
return Scaffold(
Expand Down Expand Up @@ -117,7 +110,7 @@ class PlaylistCard extends StatelessWidget {
this.isActive = false,
this.name = "DevJams' 24",
this.host = "Souvik",
this.img = "assets/dino.png"});
this.img = "assets/dino.png", String? id});

final bool isActive;
final String name;
Expand Down Expand Up @@ -163,7 +156,9 @@ class PlaylistCard extends StatelessWidget {
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
SizedBox(height: 10,),
const SizedBox(
height: 10,
),
Row(children: [
const Text(
"Event:",
Expand Down
Loading

0 comments on commit ccb3cee

Please sign in to comment.