Skip to content

Commit

Permalink
Merge pull request #170 from sparcs-kaist/feat@alert-dialog-delete-ti…
Browse files Browse the repository at this point in the history
…metable

Resolve #169, Alert dialog when deleting last time table
  • Loading branch information
sboh1214 authored Mar 22, 2024
2 parents af5f6b4 + 41ada82 commit 7d42261
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 25 deletions.
4 changes: 3 additions & 1 deletion assets/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,15 @@
"add_overlapping_lecture": "Add Overlapping Lecture",
"delete_lecture": "Delete Lecture",
"delete_tab": "Delete Table",
"delete_last_tab": "Can't Delete Table",
"ask_add_lecture": "Do you want to add lecture '{lecture}'?",
"ask_add_lecture_with_tab": "Do you want to add lecture '{lecture}' to {timetable}?",
"ask_add_overlapping_lecture": "Time overlaps with {lectures}. If you add '{lecture}', the lecture(s) will be deleted. Do you want to add it to the timetable?",
"ask_add_overlapping_lecture_with_tab": "Time overlaps with {lectures} in {timetable}. If you add '{lecture}', the lecture(s) will be deleted. Do you want to add it to the timetable?",
"ask_delete_lecture": "Do you want to delete lecture '{lecture}'?",
"ask_delete_lecture_with_tab": "Do you want to delete lecture '{lecture}' from {timetable}?",
"ask_delete_tab": "Do you really want to delete {timetable}?"
"ask_delete_tab": "Do you really want to delete {timetable}?",
"disabled_delete_last_tab": "You can't delete the last timetable."
},
"tab_menu": {
"copy": "Copy Timetable",
Expand Down
4 changes: 3 additions & 1 deletion assets/translations/ko.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,15 @@
"add_overlapping_lecture": "겹치는 수업 추가",
"delete_lecture": "수업 삭제",
"delete_tab": "시간표 삭제",
"delete_last_tab": "시간표 삭제 불가",
"ask_add_lecture": "'{lecture}' 수업을 추가하시겠습니까?",
"ask_add_lecture_with_tab": "'{lecture}' 수업을 {timetable}에 추가하시겠습니까?",
"ask_add_overlapping_lecture": "{lectures}와(과) 시간이 겹칩니다. '{lecture}'을(를) 추가하시면 해당 수업은 삭제됩니다. 시간표에 추가하시겠습니까?",
"ask_add_overlapping_lecture_with_tab": "{timetable}의 {lectures}와(과) 시간이 겹칩니다. '{lecture}'을(를) 추가하시면 해당 수업은 삭제됩니다. 시간표에 추가하시겠습니까?",
"ask_delete_lecture": "'{lecture}' 수업을 삭제하시겠습니까?",
"ask_delete_lecture_with_tab": "'{lecture}' 수업을 {timetable}에서 삭제하시겠습니까?",
"ask_delete_tab": "{timetable}을(를) 정말 삭제하시겠습니까?"
"ask_delete_tab": "{timetable}을(를) 정말 삭제하시겠습니까?",
"disabled_delete_last_tab": "마지막 시간표는 삭제할 수 없습니다."
},
"tab_menu": {
"copy": "시간표 복제하기",
Expand Down
48 changes: 36 additions & 12 deletions lib/pages/timetable_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -249,18 +249,42 @@ class _TimetablePageState extends State<TimetablePage> {
_selectedLecture = null;
});*/
},
onDeleteTap: () {
OTLNavigator.pushDialog(
context: context,
builder: (_) => OTLDialog(
type: OTLDialogType.deleteTab,
namedArgs: {
'timetable': 'timetable.tab'
.tr(args: [timetableModel.selectedIndex.toString()])
},
onTapPos: () => context.read<TimetableModel>().deleteTimetable(),
),
);
onDeleteTap: (i) {
if (i == 0) {
OTLNavigator.pushDialog(
context: context,
builder: (_) => OTLDialog(
type: OTLDialogType.accountDeleted,
namedArgs: {
'timetable': 'timetable.tab'
.tr(args: [timetableModel.selectedIndex.toString()])
},
onTapPos: () {}),
);
} else if (timetableModel.timetables.length <= 2) {
OTLNavigator.pushDialog(
context: context,
builder: (_) => OTLDialog(
type: OTLDialogType.disabledDeleteLastTab,
namedArgs: {
'timetable': 'timetable.tab'
.tr(args: [timetableModel.selectedIndex.toString()])
},
),
);
} else {
OTLNavigator.pushDialog(
context: context,
builder: (_) => OTLDialog(
type: OTLDialogType.deleteTab,
namedArgs: {
'timetable': 'timetable.tab'
.tr(args: [timetableModel.selectedIndex.toString()])
},
onTapPos: () => context.read<TimetableModel>().deleteTimetable(),
),
);
}
},
onExportTap: (type) {
context
Expand Down
10 changes: 10 additions & 0 deletions lib/widgets/otl_dialog.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ enum OTLDialogType {
/// namedArgs: 'timetable'
deleteTab,

disabledDeleteLastTab,

deleteAccount,

accountDeleted,
Expand Down Expand Up @@ -107,6 +109,13 @@ extension OTLDialogTypeExt on OTLDialogType {
icon: 'timetable',
posText: 'common.delete',
),
OTLDialogType.disabledDeleteLastTab: _OTLDialogData(
title: 'timetable.dialog.delete_last_tab',
content: 'timetable.dialog.disabled_delete_last_tab',
icon: 'alert',
negText: 'common.close',
btnStyle: BtnStyle.one,
),
OTLDialogType.deleteAccount: _OTLDialogData(
title: 'user.delete_account',
content: 'user.ask_delete_account',
Expand Down Expand Up @@ -258,6 +267,7 @@ class OTLDialog extends StatelessWidget {
case OTLDialogType.deleteLecture:
case OTLDialogType.deleteLectureWithTab:
case OTLDialogType.deleteTab:
case OTLDialogType.disabledDeleteLastTab:
case OTLDialogType.deleteAccount:
case OTLDialogType.accountDeleted:
case OTLDialogType.resetSettings:
Expand Down
20 changes: 10 additions & 10 deletions lib/widgets/timetable_tabs.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class TimetableTabs extends StatefulWidget {
final int length;
final Function(int) onTap;
final VoidCallback onCopyTap;
final VoidCallback onDeleteTap;
final Function(int) onDeleteTap;
final Function(ShareType) onExportTap;

TimetableTabs(
Expand Down Expand Up @@ -78,7 +78,6 @@ class _TimetableTabsState extends State<TimetableTabs> {
);

if (i == _index) {
bool canDelete = widget.length > 2 && i != 0;
return Padding(
padding: const EdgeInsets.only(right: 8.0),
child: Dropdown<int>(
Expand Down Expand Up @@ -117,13 +116,14 @@ class _TimetableTabsState extends State<TimetableTabs> {
text: 'timetable.tab_menu.export_cal'.tr(),
icon: Icons.calendar_today_outlined,
),
ItemData(
value: 3,
text: 'timetable.tab_menu.delete'.tr(),
icon: Icons.delete_outlined,
textColor: OTLColor.red,
disabled: !canDelete,
),
if (i != 0) ...[
ItemData(
value: 3,
text: 'timetable.tab_menu.delete'.tr(),
icon: Icons.delete_outlined,
textColor: OTLColor.red,
)
]
/*ItemData(
value: 4,
text: 'timetable.tab_menu.syllabus'.tr(),
Expand All @@ -135,7 +135,7 @@ class _TimetableTabsState extends State<TimetableTabs> {
if (value == 0) widget.onCopyTap();
if (value == 1) widget.onExportTap(ShareType.image);
if (value == 2) widget.onExportTap(ShareType.ical);
if (value == 3 && canDelete) widget.onDeleteTap();
if (value == 3) widget.onDeleteTap(i);
// if (value == 4) Pass
},
),
Expand Down
2 changes: 1 addition & 1 deletion test/widgets/pump_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ void main() {
length: 1,
onTap: (_) {},
onCopyTap: () {},
onDeleteTap: () {},
onDeleteTap: (_) {},
onExportTap: (_) {},
).scaffold);
});
Expand Down

0 comments on commit 7d42261

Please sign in to comment.