From fe0c92af6cd971024d4aa7fb25b5b9fc5ae732d8 Mon Sep 17 00:00:00 2001 From: edge Date: Mon, 18 Mar 2024 19:26:08 +0900 Subject: [PATCH 1/5] g11n: add translations for disabled delete tab --- assets/translations/en.json | 4 +++- assets/translations/ko.json | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/assets/translations/en.json b/assets/translations/en.json index 8d1efffa..d59346f2 100644 --- a/assets/translations/en.json +++ b/assets/translations/en.json @@ -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", diff --git a/assets/translations/ko.json b/assets/translations/ko.json index 98bc1c3d..38c71343 100644 --- a/assets/translations/ko.json +++ b/assets/translations/ko.json @@ -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": "시간표 복제하기", From a08bc9b752e2a83738f0627849903967439966b6 Mon Sep 17 00:00:00 2001 From: edge Date: Mon, 18 Mar 2024 19:27:14 +0900 Subject: [PATCH 2/5] feat: add delete last tablr dialog --- lib/widgets/otl_dialog.dart | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/lib/widgets/otl_dialog.dart b/lib/widgets/otl_dialog.dart index e41f5a38..5dfa86b9 100644 --- a/lib/widgets/otl_dialog.dart +++ b/lib/widgets/otl_dialog.dart @@ -29,6 +29,8 @@ enum OTLDialogType { /// namedArgs: 'timetable' deleteTab, + disabledDeleteLastTab, + deleteAccount, accountDeleted, @@ -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', @@ -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: From 37f51bcc6f5a6a9bfe6bc83abb0269014a581c8e Mon Sep 17 00:00:00 2001 From: edge Date: Mon, 18 Mar 2024 19:28:41 +0900 Subject: [PATCH 3/5] feat: add dialog when delete last timetable --- lib/pages/timetable_page.dart | 49 +++++++++++++++++++++++++-------- lib/widgets/timetable_tabs.dart | 22 ++++++++------- 2 files changed, 49 insertions(+), 22 deletions(-) diff --git a/lib/pages/timetable_page.dart b/lib/pages/timetable_page.dart index 87d21560..d1de441d 100644 --- a/lib/pages/timetable_page.dart +++ b/lib/pages/timetable_page.dart @@ -249,18 +249,43 @@ class _TimetablePageState extends State { _selectedLecture = null; });*/ }, - onDeleteTap: () { - OTLNavigator.pushDialog( - context: context, - builder: (_) => OTLDialog( - type: OTLDialogType.deleteTab, - namedArgs: { - 'timetable': 'timetable.tab' - .tr(args: [timetableModel.selectedIndex.toString()]) - }, - onTapPos: () => context.read().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()]) + }, + // onTapPos: () {} + ), + ); + } else { + OTLNavigator.pushDialog( + context: context, + builder: (_) => OTLDialog( + type: OTLDialogType.deleteTab, + namedArgs: { + 'timetable': 'timetable.tab' + .tr(args: [timetableModel.selectedIndex.toString()]) + }, + onTapPos: () => context.read().deleteTimetable(), + ), + ); + } }, onExportTap: (type) { context diff --git a/lib/widgets/timetable_tabs.dart b/lib/widgets/timetable_tabs.dart index 31b50bf8..6d4f28df 100644 --- a/lib/widgets/timetable_tabs.dart +++ b/lib/widgets/timetable_tabs.dart @@ -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( @@ -78,7 +78,7 @@ class _TimetableTabsState extends State { ); if (i == _index) { - bool canDelete = widget.length > 2 && i != 0; + // bool canDelete = widget.length > 2 && i != 0; return Padding( padding: const EdgeInsets.only(right: 8.0), child: Dropdown( @@ -117,13 +117,15 @@ class _TimetableTabsState extends State { 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, + // disabled: !canDelete, + ) + ] /*ItemData( value: 4, text: 'timetable.tab_menu.syllabus'.tr(), @@ -135,7 +137,7 @@ class _TimetableTabsState extends State { 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 }, ), From edcd62349fbc5f3a79dec1a809901d24fcc252b3 Mon Sep 17 00:00:00 2001 From: edge Date: Mon, 18 Mar 2024 19:29:24 +0900 Subject: [PATCH 4/5] test: add timetabletab onDeleteTab parameter --- test/widgets/pump_test.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/widgets/pump_test.dart b/test/widgets/pump_test.dart index 75418bc2..7772cefc 100644 --- a/test/widgets/pump_test.dart +++ b/test/widgets/pump_test.dart @@ -83,7 +83,7 @@ void main() { length: 1, onTap: (_) {}, onCopyTap: () {}, - onDeleteTap: () {}, + onDeleteTap: (_) {}, onExportTap: (_) {}, ).scaffold); }); From 41ada8239285453f075f713afddbce9b2fadbf51 Mon Sep 17 00:00:00 2001 From: edge Date: Wed, 20 Mar 2024 22:50:41 +0900 Subject: [PATCH 5/5] chore: remove unnecessary comment --- lib/pages/timetable_page.dart | 1 - lib/widgets/timetable_tabs.dart | 2 -- 2 files changed, 3 deletions(-) diff --git a/lib/pages/timetable_page.dart b/lib/pages/timetable_page.dart index d1de441d..4c24e1a8 100644 --- a/lib/pages/timetable_page.dart +++ b/lib/pages/timetable_page.dart @@ -270,7 +270,6 @@ class _TimetablePageState extends State { 'timetable': 'timetable.tab' .tr(args: [timetableModel.selectedIndex.toString()]) }, - // onTapPos: () {} ), ); } else { diff --git a/lib/widgets/timetable_tabs.dart b/lib/widgets/timetable_tabs.dart index 6d4f28df..5147cce6 100644 --- a/lib/widgets/timetable_tabs.dart +++ b/lib/widgets/timetable_tabs.dart @@ -78,7 +78,6 @@ class _TimetableTabsState extends State { ); if (i == _index) { - // bool canDelete = widget.length > 2 && i != 0; return Padding( padding: const EdgeInsets.only(right: 8.0), child: Dropdown( @@ -123,7 +122,6 @@ class _TimetableTabsState extends State { text: 'timetable.tab_menu.delete'.tr(), icon: Icons.delete_outlined, textColor: OTLColor.red, - // disabled: !canDelete, ) ] /*ItemData(