Skip to content

Commit

Permalink
Add delete confirmation for custom lists
Browse files Browse the repository at this point in the history
  • Loading branch information
raksooo committed Jan 5, 2024
1 parent d6d6273 commit 2bebcce
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 4 deletions.
7 changes: 7 additions & 0 deletions gui/locales/messages.pot
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,9 @@ msgstr ""
msgid "Default"
msgstr ""

msgid "Delete list"
msgstr ""

msgid "Disable"
msgstr ""

Expand Down Expand Up @@ -1035,6 +1038,10 @@ msgctxt "select-location-view"
msgid "Custom lists"
msgstr ""

msgctxt "select-location-view"
msgid "Do you want to delete the list <b>%(list)s</b>?"
msgstr ""

msgctxt "select-location-view"
msgid "Edit list name"
msgstr ""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)({
Expand Down Expand Up @@ -201,3 +201,45 @@ export function EditListDialog(props: EditListProps) {
</ModalAlert>
);
}

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 (
<ModalAlert
type={ModalAlertType.warning}
isOpen={props.isOpen}
buttons={[
<AppButton.RedButton key="save" onClick={confirm}>
{messages.gettext('Delete list')}
</AppButton.RedButton>,
<AppButton.BlueButton key="cancel" onClick={props.hide}>
{messages.gettext('Cancel')}
</AppButton.BlueButton>,
]}
close={props.hide}>
<ModalMessage>
{formatHtml(
sprintf(
messages.pgettext(
'select-location-view',
'Do you want to delete the list <b>%(list)s</b>?',
),
{ list: props.list.name },
),
)}
</ModalMessage>
</ModalAlert>
);
}
16 changes: 13 additions & 3 deletions gui/src/renderer/components/select-location/LocationRow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -162,6 +162,7 @@ function LocationRow<C extends LocationSpecification>(props: IProps<C>) {
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);
Expand Down Expand Up @@ -218,7 +219,7 @@ function LocationRow<C extends LocationSpecification>(props: IProps<C>) {
}, [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);
Expand Down Expand Up @@ -273,7 +274,7 @@ function LocationRow<C extends LocationSpecification>(props: IProps<C>) {
<StyledHoverIconButton onClick={showEditDialog} {...background}>
<StyledHoverIcon source="icon-edit" />
</StyledHoverIconButton>
<StyledHoverIconButton onClick={onRemoveCustomList} $isLast {...background}>
<StyledHoverIconButton onClick={showDeleteDialog} $isLast {...background}>
<StyledHoverIcon source="icon-close" />
</StyledHoverIconButton>
</>
Expand Down Expand Up @@ -318,6 +319,15 @@ function LocationRow<C extends LocationSpecification>(props: IProps<C>) {
{'list' in props.source && (
<EditListDialog list={props.source.list} isOpen={editDialogVisible} hide={hideEditDialog} />
)}

{'list' in props.source && (
<DeleteConfirmDialog
list={props.source.list}
isOpen={deleteDialogVisible}
hide={hideDeleteDialog}
confirm={confirmRemoveCustomList}
/>
)}
</>
);
}
Expand Down

0 comments on commit 2bebcce

Please sign in to comment.