Skip to content

Commit

Permalink
Merge pull request #209 from atharva-khewle/main
Browse files Browse the repository at this point in the history
NOTES FIXED. NOW IT WORKS FOR BOTH TEACHER AND STUDENT
  • Loading branch information
atharva-khewle authored Jul 15, 2024
2 parents 4e352b2 + ed99214 commit 7a9a084
Show file tree
Hide file tree
Showing 8 changed files with 82 additions and 15 deletions.
7 changes: 7 additions & 0 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,13 @@ Future<void> _firebaseMessagingBackgroundHandler(RemoteMessage message) async {
print("Handling a background message: ${message.messageId}");
}


var debugprint = "////////////////////////////////////////////////////////////////////////////////////////////////////////TESTING/////////////////////////////////////////////////////////////////////////";





Future<void> main() async {
WidgetsFlutterBinding.ensureInitialized();
await Firebase.initializeApp();
Expand Down
8 changes: 7 additions & 1 deletion lib/new_ui/screens/login_screen/login_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -73,22 +73,28 @@ class _LoginScreenState extends ConsumerState<LoginScreen> {
setState(() {
loggedInButtonPressed = true;
});
print("print1");
UserCredential? userCredential = await ref
.watch(authProvider.notifier)
.signInUser(_emailTextEditingController.text.trim(),
_passwordTextEditingController.text.trim(), context);

print("print2");
if (userCredential == null) {
setState(() {
loggedInButtonPressed = false;
});
return;
}
print("print3");

await ref.watch(authProvider.notifier).getUserData(ref, context);
print("print4");
UserModel? userModel = ref.watch(userModelProvider);
print("print5");
print("print6");

if (userModel != null) {
print("print6");
ref.watch(authProvider.notifier).setupFCMNotifications(ref,
userModel.studentModel, FirebaseAuth.instance.currentUser!.uid);

Expand Down
9 changes: 8 additions & 1 deletion lib/new_ui/screens/notes_screen/widgets/note_list.dart
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ class _NoteListState extends ConsumerState<NoteList> {
@override
Widget build(BuildContext context) {
List<NotesModel> allNotes = ref.watch(notesProvider);
UserModel? user = ref.read(userModelProvider);

// allNotes = applyFilters(allNotes);
// debugPrint("all notes are ${allNotes}");
// List<NotesModel> allNotes = [];
Expand All @@ -118,8 +120,13 @@ class _NoteListState extends ConsumerState<NoteList> {
}
return newString;
}).toList();
print(i);
print(attachments.toString());
print(widget.subjects.toString());
print(allNotes[i].professorName);
print(user?.facultyModel?.name);

if(widget.subjects.contains(allNotes[i].subject))
if(widget.subjects.contains(allNotes[i].subject) || user?.facultyModel?.name==allNotes[i].professorName)
return Column(
children: [
SizedBox(height: 10),
Expand Down
29 changes: 29 additions & 0 deletions lib/new_ui/screens/notes_screen/widgets/notes_filter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,25 @@ import 'package:tsec_app/provider/subjects_provider.dart';
import 'package:tsec_app/utils/custom_snackbar.dart';
import 'package:tsec_app/utils/profile_details.dart';








/////////////////////////// THIS IS DROPDOWN FOR NOTES PAGE WHERE U SEE AND SELECT ALL SEBJECTS ////////////////////////










class NotesFilterBar extends ConsumerStatefulWidget {
DateTime? startDate;
String searchQuery;
Expand Down Expand Up @@ -132,9 +151,14 @@ class _NotesFilterBarState extends ConsumerState<NotesFilterBar>
SemesterData semData = subjects.dataMap[
"${calcGradYear(user.studentModel?.gradyear)}_${user.studentModel?.branch}"] ??
SemesterData(even_sem: [], odd_sem: []);

debugPrint(semData.even_sem.toString());
debugPrint(semData.odd_sem.toString());


List<String> allSubjects =
evenOrOddSem() == "even_sem" ? semData.even_sem : semData.odd_sem;
print("selected senm subjects ${allSubjects.toString()}");
// debugPrint(allSubjects.toString());
// debugPrint(
// "${user!.studentModel?.gradyear} ${user.studentModel?.branch} ${evenOrOddSem()}");
Expand Down Expand Up @@ -238,6 +262,11 @@ class _NotesFilterBarState extends ConsumerState<NotesFilterBar>
thickness: 1,
color: timePickerBorder,
),




//THIS IS FOR DROPDOWN
user.isStudent && allSubjects.isNotEmpty
? Column(
mainAxisSize: MainAxisSize.max,
Expand Down
1 change: 1 addition & 0 deletions lib/new_ui/screens/splash_screen/splash_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ class _SplashScreenState extends ConsumerState<SplashScreen> {
return Scaffold(
body: Center(
child: SizedBox(
//SECOND SCREEN LOGO
child: Image.asset(ImageAssets.tsecapplogo),
height: 250,
width: 250,
Expand Down
2 changes: 2 additions & 0 deletions lib/provider/auth_provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,9 @@ class AuthProvider extends StateNotifier<bool> {
Future getUserData(WidgetRef ref, BuildContext context) async {
//this is being called on both splash and login screen
final user = _ref.watch(firebaseAuthProvider).currentUser;
print("in getUserData");
if (user?.uid != null) {
print("uid not null : ${user?.uid}");
UserModel? userModel = await ref
.watch(authProvider.notifier)
.fetchUserDetails(user, context);
Expand Down
3 changes: 2 additions & 1 deletion lib/screens/notification_screen/notification_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -102,13 +102,14 @@ class _NotificationScreenState extends ConsumerState<NotificationScreen> {
_lastDate = notificationTime;
return Center(
child: Chip(
backgroundColor: Colors.white,
backgroundColor: Colors.transparent,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(20.0),
),
labelStyle: const TextStyle(fontSize: 12),
label: Text(
DateFormat("dd MMMM,yyyy").format(notificationTime),
style: TextStyle(color: Colors.white),
),
),
);
Expand Down
38 changes: 26 additions & 12 deletions lib/services/notes_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class NotesService {
final FirebaseStorage firebaseStorage;
NotesService(this.firebaseAuth, this.firebaseFirestore, this.firebaseStorage);
CollectionReference<Map<String, dynamic>> notesCollection =
FirebaseFirestore.instance.collection('Notes');
FirebaseFirestore.instance.collection('Notes');

Stream<User?> get userCurrentState => firebaseAuth.authStateChanges();

Expand Down Expand Up @@ -65,31 +65,45 @@ class NotesService {
}

Future<List<NotesModel>> fetchNotes(UserModel? user) async {
late QuerySnapshot<Map<String, dynamic>> querySnapshot;
print(debugPrint);
print(user);
if (user == null) return [];
late QuerySnapshot<Map<String, dynamic>> querySnapshot;

try{
if (user.isStudent) {
// debugPrint(
// "${user.studentModel?.branch}, ${user.studentModel?.div}, ${calcGradYear(user.studentModel!.gradyear)}");

final gradyear = calcGradYear(user.studentModel?.gradyear);
print(gradyear);
querySnapshot = await notesCollection
.where(
'target_classes',
arrayContains: {
"branch": user.studentModel?.branch,
"division": user.studentModel?.div,
"year": calcGradYear(user.studentModel!.gradyear),
},
)
'target_classes',
arrayContains: {
"branch": user.studentModel?.branch,
"division": user.studentModel?.div,
"year": gradyear,
},
)
.orderBy("time", descending: true)
.get();
} else {
querySnapshot = await notesCollection
.where("professor_name", isEqualTo: user.facultyModel?.name)
.get();
}

}catch(e){
print(calcGradYear(user.studentModel?.gradyear));
print(user.studentModel?.name);
print(user.facultyModel?.name);
print("Error in notes_service.dart in fetchnotes ${e}");
}
List<NotesModel> reqNotes = [];

for (QueryDocumentSnapshot<Map<String, dynamic>> document
in querySnapshot.docs) {
in querySnapshot.docs) {
var noteData = document.data();
NotesModel note = NotesModel.fromJson(noteData);
note.id = document.id;
Expand Down Expand Up @@ -128,7 +142,7 @@ class NotesService {
await notesDoc.update(note.toJson());
} else {
DocumentReference<Map<String, dynamic>> noteUploaded =
await notesCollection.add(note.toJson());
await notesCollection.add(note.toJson());
note.id = noteUploaded.id;
}
} catch (e) {
Expand All @@ -146,4 +160,4 @@ class NotesService {
debugPrint('Error updating or creating document: $e');
}
}
}
}

0 comments on commit 7a9a084

Please sign in to comment.