Skip to content

Commit b9d540b

Browse files
Resolve clicking bug when deleting apps
1 parent 679022d commit b9d540b

2 files changed

Lines changed: 13 additions & 11 deletions

File tree

app/components/Applications.tsx

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { useContext, useEffect, useState } from 'react';
1+
import React, { useContext, useEffect, useState, useRef } from 'react';
22
import {
33
IconButton,
44
Grid,
@@ -20,23 +20,26 @@ const Applications = () => {
2020
const [open, setOpen] = useState<boolean>(false);
2121
const [index, setIndex] = useState<number>(0);
2222
const [app, setApp] = useState<string>('');
23+
const delRef = useRef<any>(null);
24+
const appRef = useRef<any>(null);
2325

2426
useEffect(() => {
2527
getApplications();
2628
}, []);
2729

2830
// Ask user for deletetion confirmation
29-
const confirmDelete = (app: string, i: number) => {
31+
const confirmDelete = (event: React.MouseEvent<HTMLElement>, app: string, i: number) => {
3032
const message = `The application '${app}' will be permanently deleted. Continue?`;
3133
if (confirm(message)) deleteApp(i);
3234
};
3335

3436
// Handle clicks on Application cards
35-
const handleClick = (selectedApp: string, i: number) => {
36-
setIndex(i);
37-
setApp(selectedApp);
38-
console.log('handle', selectedApp);
39-
setOpen(true);
37+
const handleClick = (event: React.MouseEvent<HTMLElement>, selectedApp: string, i: number) => {
38+
if (!delRef.current.contains(event.target)) {
39+
setIndex(i);
40+
setApp(selectedApp);
41+
setOpen(true);
42+
}
4043
};
4144

4245
const useStyles = makeStyles(theme => ({
@@ -80,17 +83,18 @@ const Applications = () => {
8083
<Grid item lg={4} md={6} sm={12} key={i}>
8184
<div id="card-hover">
8285
<Card
86+
ref={appRef}
8387
className={classes.paper}
8488
variant="outlined"
85-
onClick={(event: React.MouseEvent<HTMLElement>) => handleClick(app[0], i)}
89+
onClick={event => handleClick(event, app[0], i)}
8690
>
8791
<CardHeader
8892
avatar={
8993
<IconButton
9094
ref={delRef}
9195
className={classes.hover}
9296
aria-label="Delete"
93-
onClick={(event: React.MouseEvent<HTMLElement>) => confirmDelete(app[0], i)}
97+
onClick={event => confirmDelete(event, app[0], i)}
9498
>
9599
<DeleteForeverOutlinedIcon />
96100
</IconButton>

app/context/DashboardContext.tsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,6 @@ const DashboardContextProvider = ({ children }: Props) => {
5555
*/
5656
const deleteApp = (index: number) => {
5757
const result = ipcRenderer.sendSync('deleteApp', index);
58-
console.log('what is the res', result);
59-
console.log('what is the string', JSON.stringify(result));
6058
setApplications(result);
6159
};
6260

0 commit comments

Comments
 (0)