generated from GDGVIT/template
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7 from JothishKamal/dev
feat: admin screen backend integration + fixes
- Loading branch information
Showing
32 changed files
with
2,403 additions
and
706 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,59 +1,70 @@ | ||
import 'package:flutter/material.dart'; | ||
import 'package:flutter_riverpod/flutter_riverpod.dart'; | ||
import 'package:go_router/go_router.dart'; | ||
import 'package:spotify_collab_app/view/screens/admin_screen.dart'; | ||
import 'package:spotify_collab_app/view/screens/create_screen.dart'; | ||
import 'package:spotify_collab_app/view/screens/join_screen.dart'; | ||
import 'package:spotify_collab_app/view/screens/landing_screen.dart'; | ||
import 'package:spotify_collab_app/view/screens/login_screen.dart'; | ||
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'; | ||
|
||
final router = GoRouter( | ||
initialLocation: '/', | ||
routes: <GoRoute>[ | ||
GoRoute( | ||
path: '/', | ||
pageBuilder: (context, state) => const MaterialPage( | ||
child: LandingScreen(), | ||
), | ||
routes: [ | ||
GoRoute( | ||
path: 'login', | ||
pageBuilder: (context, state) => | ||
const MaterialPage(child: LoginScreen()), | ||
), | ||
GoRoute( | ||
path: 'signup', | ||
pageBuilder: (context, state) => | ||
const MaterialPage(child: SignupScreen()), | ||
), | ||
GoRoute( | ||
path: 'connect', | ||
pageBuilder: (context, state) => | ||
const MaterialPage(child: ConnectScreen()), | ||
), | ||
GoRoute( | ||
path: 'home', | ||
pageBuilder: (context, state) => | ||
const MaterialPage(child: HomeScreen()), | ||
), | ||
GoRoute( | ||
path: 'create', | ||
pageBuilder: (context, state) => | ||
const MaterialPage(child: CreateScreen()), | ||
), | ||
GoRoute( | ||
path: 'join', | ||
pageBuilder: (context, state) => | ||
const MaterialPage(child: JoinScreen()), | ||
), | ||
GoRoute( | ||
path: 'admin', | ||
pageBuilder: (context, state) => | ||
const MaterialPage(child: AdminScreen()), | ||
), | ||
], | ||
), | ||
], | ||
); | ||
final routerProvider = Provider<GoRouter>((ref) { | ||
return GoRouter( | ||
errorBuilder: (context, state) { | ||
return const HomeScreen(); | ||
}, | ||
initialLocation: '/', | ||
routes: <GoRoute>[ | ||
GoRoute( | ||
path: '/', | ||
pageBuilder: (context, state) => const MaterialPage( | ||
child: SplashScreen(), | ||
), | ||
), | ||
GoRoute( | ||
path: '/connect', | ||
pageBuilder: (context, state) => const MaterialPage( | ||
child: ConnectScreen(), | ||
), | ||
), | ||
GoRoute( | ||
path: '/home', | ||
pageBuilder: (context, state) => const MaterialPage( | ||
child: HomeScreen(), | ||
), | ||
), | ||
GoRoute( | ||
path: '/login', | ||
pageBuilder: (context, state) => const MaterialPage( | ||
child: LoginScreen(), | ||
), | ||
), | ||
GoRoute( | ||
path: '/signup', | ||
pageBuilder: (context, state) => const MaterialPage( | ||
child: SignupScreen(), | ||
), | ||
), | ||
GoRoute( | ||
path: '/create', | ||
pageBuilder: (context, state) => const MaterialPage( | ||
child: CreateScreen(), | ||
), | ||
), | ||
GoRoute( | ||
path: '/join', | ||
pageBuilder: (context, state) => const MaterialPage( | ||
child: JoinScreen(), | ||
), | ||
), | ||
GoRoute( | ||
path: '/admin', | ||
pageBuilder: (context, state) => const MaterialPage( | ||
child: AdminScreen(), | ||
), | ||
), | ||
], | ||
); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
const devUrl = | ||
'https://spotify-collab-backend-jothishkamal.onrender.com'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,100 @@ | ||
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/songs_response.dart'; | ||
|
||
enum RequestAction { none, acceptAll, rejectAll } | ||
|
||
final tabProvider = StateProvider<int>((ref) => 0); | ||
|
||
final requestActionProvider = | ||
StateProvider<RequestAction>((ref) => RequestAction.none); | ||
|
||
final songsProvider = | ||
StateNotifierProvider<SongsNotifier, SongsResponse>((ref) { | ||
return SongsNotifier(); | ||
}); | ||
|
||
class SongsNotifier extends StateNotifier<SongsResponse> { | ||
SongsNotifier() : super(SongsResponse()); | ||
|
||
Future<void> fetchSongs(String uuid) async { | ||
var prefs = await SharedPreferences.getInstance(); | ||
log(prefs.getString('access_token').toString()); | ||
log(uuid); | ||
try { | ||
final response = await apiUtil.get( | ||
'/v1/songs/$uuid', | ||
); | ||
|
||
log('Songs fetched'); | ||
if (response.statusCode == 200) { | ||
final data = SongsResponse.fromJson(response.data); | ||
|
||
state = state.copyWith( | ||
data: data.data, | ||
message: data.message, | ||
statusCode: data.statusCode, | ||
success: data.success, | ||
); | ||
} | ||
} catch (e) { | ||
log(e.toString()); | ||
} | ||
} | ||
|
||
void clearSongs() { | ||
final emptySongs = SongsResponse(); | ||
|
||
state = state.copyWith( | ||
data: emptySongs.data, | ||
message: emptySongs.message, | ||
statusCode: emptySongs.statusCode, | ||
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; | ||
} | ||
} |
Oops, something went wrong.