Skip to content

Commit

Permalink
Merge pull request #842 from AdityaBirangal/master
Browse files Browse the repository at this point in the history
[Fix] User can delete any event (Front-end)
  • Loading branch information
TheHazeEffect authored May 26, 2021
2 parents 93e08c1 + 0991e0f commit d4fa906
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 32 deletions.
23 changes: 14 additions & 9 deletions lib/view_models/page_view_model/events_page_view_model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class EventPageViewModel extends BaseModel {
List<EventsModel> get eventList => _eventList;
List<EventsModel> get displayEvents => _displayEvents;
String get dateSelected => _dateSelected;
String get userID => _userID;

setDisplayEvents(List<EventsModel> events) {
_displayEvents = events;
Expand Down Expand Up @@ -177,16 +178,20 @@ class EventPageViewModel extends BaseModel {
}

//function called to delete the event
Future<void> deleteEvent(BuildContext context, String eventId) async {
showProgress(context, 'Deleting Event . . .', isDismissible: false);
final String mutation = Queries().deleteEvent(eventId);
final Map result = await _apiFunctions.gqlquery(mutation);
if (result["exception"] != null) {
CustomToast.exceptionToast(
msg: "Could not delete event! Please try again later");
Future<void> deleteEvent(BuildContext context, EventsModel event) async {
if (event.creator.id != _userID) {
Fluttertoast.showToast(msg: "You can\'t delete events you didn't create");
} else {
showProgress(context, 'Deleting Event . . .', isDismissible: false);
final String mutation = Queries().deleteEvent(event.id);
final Map result = await _apiFunctions.gqlquery(mutation);
if (result["exception"] != null) {
CustomToast.exceptionToast(
msg: "Could not delete event! Please try again later");
}
await getEvents();
hideProgress();
}
await getEvents();
hideProgress();
}

//function to called be called for register
Expand Down
40 changes: 21 additions & 19 deletions lib/views/pages/events/event_card_widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ Widget popUpMenue(
} else if (val == 3) {
return model.editEvent(context, event);
} else if (val == 4) {
return model.deleteEvent(context, event.id);
return model.deleteEvent(context, event);
}
},
itemBuilder: (BuildContext context) => <PopupMenuEntry<int>>[
Expand All @@ -105,24 +105,26 @@ Widget popUpMenue(
style: const TextStyle(color: Colors.black),
),
)),
const PopupMenuItem<int>(
value: 3,
child: const ListTile(
leading: const Icon(Icons.edit, color: Colors.grey),
title: const Text(
'Edit this event',
style: const TextStyle(color: Colors.black),
),
)),
const PopupMenuItem<int>(
value: 4,
child: const ListTile(
leading: const Icon(Icons.delete, color: Colors.grey),
title: const Text(
'Delete This Event',
style: const TextStyle(color: Colors.black),
),
))
if (event.creator.id == model.userID) ...[
const PopupMenuItem<int>(
value: 3,
child: const ListTile(
leading: const Icon(Icons.edit, color: Colors.grey),
title: const Text(
'Edit this event',
style: const TextStyle(color: Colors.black),
),
)),
const PopupMenuItem<int>(
value: 4,
child: const ListTile(
leading: const Icon(Icons.delete, color: Colors.grey),
title: const Text(
'Delete This Event',
style: const TextStyle(color: Colors.black),
),
)),
],
],
);
}
Expand Down
7 changes: 3 additions & 4 deletions lib/views/pages/events/events.dart
Original file line number Diff line number Diff line change
@@ -1,22 +1,21 @@
//flutter packages are called here

import 'package:carousel_slider/carousel_slider.dart';
import 'package:flutter/material.dart';
import 'package:flutter_sticky_header/flutter_sticky_header.dart';
import 'package:sliding_up_panel/sliding_up_panel.dart';
import 'package:table_calendar/table_calendar.dart';
import 'package:talawa/enums/viewstate.dart';
import 'package:talawa/model/events.dart';
import 'package:talawa/utils/custom_toast.dart';
import 'package:talawa/utils/ui_scaling.dart';
import 'package:talawa/utils/uidata.dart';
import 'package:talawa/view_models/page_view_model/events_page_view_model.dart';
import 'package:talawa/views/pages/events/event_card_widget.dart';
import 'package:talawa/views/widgets/loader_gen.dart';
import 'package:talawa/views/widgets/loading.dart';
import 'package:talawa/views/widgets/loading_gen.dart';
import 'package:timeline_list/timeline.dart';
import 'package:timeline_list/timeline_model.dart';
import 'package:table_calendar/table_calendar.dart';
import 'package:carousel_slider/carousel_slider.dart';

import '../../base_view.dart';

class Events extends StatefulWidget {
Expand Down

0 comments on commit d4fa906

Please sign in to comment.