From 2bebcce89bab9b4de95ed2cfa3c496059602ea3b Mon Sep 17 00:00:00 2001 From: Oskar Nyberg Date: Tue, 2 Jan 2024 13:04:40 +0100 Subject: [PATCH] Add delete confirmation for custom lists --- gui/locales/messages.pot | 7 +++ .../select-location/CustomListDialogs.tsx | 44 ++++++++++++++++++- .../select-location/LocationRow.tsx | 16 +++++-- 3 files changed, 63 insertions(+), 4 deletions(-) diff --git a/gui/locales/messages.pot b/gui/locales/messages.pot index 161ad721c7dc..70a89c22e725 100644 --- a/gui/locales/messages.pot +++ b/gui/locales/messages.pot @@ -99,6 +99,9 @@ msgstr "" msgid "Default" msgstr "" +msgid "Delete list" +msgstr "" + msgid "Disable" msgstr "" @@ -1035,6 +1038,10 @@ msgctxt "select-location-view" msgid "Custom lists" msgstr "" +msgctxt "select-location-view" +msgid "Do you want to delete the list %(list)s?" +msgstr "" + msgctxt "select-location-view" msgid "Edit list name" msgstr "" diff --git a/gui/src/renderer/components/select-location/CustomListDialogs.tsx b/gui/src/renderer/components/select-location/CustomListDialogs.tsx index 7af8c1b622df..56244e73ebcf 100644 --- a/gui/src/renderer/components/select-location/CustomListDialogs.tsx +++ b/gui/src/renderer/components/select-location/CustomListDialogs.tsx @@ -18,7 +18,7 @@ import { useSelector } from '../../redux/store'; import * as AppButton from '../AppButton'; import * as Cell from '../cell'; import { normalText, tinyText } from '../common-styles'; -import { ModalAlert, ModalMessage } from '../Modal'; +import { ModalAlert, ModalAlertType, ModalMessage } from '../Modal'; import SimpleInput from '../SimpleInput'; const StyledModalMessage = styled(ModalMessage)({ @@ -201,3 +201,45 @@ export function EditListDialog(props: EditListProps) { ); } + +interface DeleteConfirmDialogProps { + list: ICustomList; + isOpen: boolean; + hide: () => void; + confirm: () => void; +} + +// Dialog for changing the name of a custom list. +export function DeleteConfirmDialog(props: DeleteConfirmDialogProps) { + const confirm = useCallback(() => { + props.confirm(); + props.hide(); + }, []); + + return ( + + {messages.gettext('Delete list')} + , + + {messages.gettext('Cancel')} + , + ]} + close={props.hide}> + + {formatHtml( + sprintf( + messages.pgettext( + 'select-location-view', + 'Do you want to delete the list %(list)s?', + ), + { list: props.list.name }, + ), + )} + + + ); +} diff --git a/gui/src/renderer/components/select-location/LocationRow.tsx b/gui/src/renderer/components/select-location/LocationRow.tsx index e958bd0c98bb..79b44d372a66 100644 --- a/gui/src/renderer/components/select-location/LocationRow.tsx +++ b/gui/src/renderer/components/select-location/LocationRow.tsx @@ -19,7 +19,7 @@ import ChevronButton from '../ChevronButton'; import { measurements, normalText } from '../common-styles'; import ImageView from '../ImageView'; import RelayStatusIndicator from '../RelayStatusIndicator'; -import { AddToListDialog, EditListDialog } from './CustomListDialogs'; +import { AddToListDialog, DeleteConfirmDialog, EditListDialog } from './CustomListDialogs'; import { CitySpecification, CountrySpecification, @@ -162,6 +162,7 @@ function LocationRow(props: IProps) { const { updateCustomList, deleteCustomList } = useAppContext(); const [addToListDialogVisible, showAddToListDialog, hideAddToListDialog] = useBoolean(); const [editDialogVisible, showEditDialog, hideEditDialog] = useBoolean(); + const [deleteDialogVisible, showDeleteDialog, hideDeleteDialog] = useBoolean(); const background = getButtonColor(props.source.selected, props.level, props.source.disabled); const customLists = useSelector((state) => state.settings.customLists); @@ -218,7 +219,7 @@ function LocationRow(props: IProps) { }, [customLists, props.source.location]); // Remove an entire custom list. - const onRemoveCustomList = useCallback(async () => { + const confirmRemoveCustomList = useCallback(async () => { if (props.source.location.customList) { try { await deleteCustomList(props.source.location.customList); @@ -273,7 +274,7 @@ function LocationRow(props: IProps) { - + @@ -318,6 +319,15 @@ function LocationRow(props: IProps) { {'list' in props.source && ( )} + + {'list' in props.source && ( + + )} ); }