Skip to content

Commit 7afbc63

Browse files
author
Robb Satterwhite
committed
Clean up deletion handling.
1 parent 5414a5c commit 7afbc63

File tree

2 files changed

+18
-28
lines changed

2 files changed

+18
-28
lines changed

src/components/OneList.js

Lines changed: 12 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,9 @@
1515
* 3) form to add an item / addMode===true
1616
* 4) form to move a list (list of other categories) / moveMode===true
1717
* 5) form to copy a list (name of new list) / copyMode===true
18+
* 6) the actual list of items will be displayed unless #4 or #5 is visible.
1819
*/
19-
import React, { Fragment, useState, useEffect } from 'react';
20+
import React, { Fragment, useState } from 'react';
2021
import { Link, useLocation, Redirect, useHistory } from 'react-router-dom';
2122
import '../css/lists.css';
2223
import { useStore } from '../store/StoreContext';
@@ -31,8 +32,9 @@ import MoveList from './MoveList'; // form to move the list to another category
3132
import AddItemForm from './AddItemForm'; // form to add an item
3233
import ItemsGroup from './ItemsGroup'; // the actual group (list) of items
3334
import { IconButton, MakeSettingsButton, MakeHelpButton } from './IconButton';
34-
import { getMobile } from '../store/getData';
35+
// import { getMobile } from '../store/getData';
3536
import { useEscape } from '../util/helpers'; // set addMode to false
37+
import * as api from '../util/constants';
3638

3739
const OneList = () => {
3840
const data = useLocation(); // to retrieve params from data.state
@@ -42,7 +44,8 @@ const OneList = () => {
4244
console.log('** listID: ' + listID);
4345
const { state, dispatch } = useStore(); // this must come before conditional render
4446
const history = useHistory();
45-
const [addMode, setAddMode] = useState(!getMobile(state)); // if mobile, show only button
47+
const [addMode, setAddMode] = useState(false); // just show items, not add form.
48+
// const [addMode, setAddMode] = useState(!getMobile(state)); // if mobile, show only button
4649
const [editMode, setEditMode] = useState(false); // edit list name
4750
const [moveMode, setMoveMode] = useState(false); // show form to change category
4851
const [moreMode, setMoreMode] = useState(false); // show or hide extra group of icons
@@ -83,15 +86,15 @@ const OneList = () => {
8386
setEditMode(false);
8487
};
8588

86-
87-
useEffect(() => { // make sure addMode is up to date if isMobile tester is slow
88-
// console.log('** setting AddMode to ' + (!state.isMobile).toString());
89-
setAddMode(!getMobile(state));
90-
}, [state.isMobile]);
89+
// NOTE: Reinstate this in order to show/hide add form depending on platform.
90+
// useEffect(() => { // make sure addMode is up to date if isMobile tester is slow
91+
// // console.log('** setting AddMode to ' + (!state.isMobile).toString());
92+
// setAddMode(!getMobile(state));
93+
// }, [state.isMobile]);
9194

9295
const removeList = async () => {
9396
await handleRemoveList(listID, state, dispatch);
94-
if (parentCatID!=null) history.push('/cat/', { categoryID:parentCatID });
97+
// if (parentCatID!=null) history.push('/cat/', { categoryID:parentCatID });
9598
};
9699

97100
/**
@@ -189,19 +192,6 @@ const OneList = () => {
189192
);
190193
};
191194

192-
const showMoveZone = () => {
193-
const moveListProps = { cancelMove: cancelMove, listRec: oneListRec };
194-
return (<MoveList props={moveListProps} />);
195-
};
196-
const showEditZone = () => {
197-
const editListProps = { cancelEdit: cancelEdit, listRec: oneListRec };
198-
return (<EditList props={editListProps} />);
199-
};
200-
const showCopyZone = () => {
201-
const copyListProps = { cancelCopy: cancelCopy, listRec: oneListRec };
202-
return (<CopyList props={copyListProps} />);
203-
};
204-
205195
/**
206196
* The header area includes an edit button, and when this is pressed the edit form
207197
* (to change the list name) will be shown, and the main list will disappear until

src/store/handlers.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -148,15 +148,15 @@ const handleRemoveItem = async (itemID, state, dispatch) => {
148148
*/
149149
const handleRemoveList = async (listID, state, dispatch) => {
150150
console.log('** remove list ' + listID + ' before **');
151-
console.log(state.items);
151+
// console.log(state.items);
152152
const theList = getListRec(listID, state);
153153
if (!theList) { // check that it still exists in state
154154
alert("Sorry, that list can't be found.");
155-
return;
155+
return 'not found';
156156
}
157157
const delConfirmMsg = 'Are you sure you wnat to delete list ' + theList.listName + '?';
158158
const keepGoing = confirmQuest(delConfirmMsg);
159-
if (!keepGoing) return;
159+
if (!keepGoing) return 'cancelled';
160160
dispatch({
161161
type: 'STARTED_LOADING',
162162
});
@@ -173,9 +173,9 @@ const handleRemoveList = async (listID, state, dispatch) => {
173173
dispatch({
174174
type: 'FINISHED_LOADING',
175175
});
176-
console.log('** remove list after **');
177-
console.log(state.items);
178-
console.log(state.lists);
176+
// console.log('** remove list after **');
177+
// console.log(state.items);
178+
// console.log(state.lists);
179179
return status;
180180
};
181181

0 commit comments

Comments
 (0)