Skip to content

Commit ed35c35

Browse files
committed
FIX Empty task card for deleted #129tasks
only render `Task` if `task.title` is not empty
1 parent 9b55bbf commit ed35c35

File tree

3 files changed

+26
-11
lines changed

3 files changed

+26
-11
lines changed

README.md

+12
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,18 @@ I also decided not to use a placeholder image for tasks that do not have an imag
6464
as this would create an unnecessary distraction without adding information or a positive UX experience.
6565
instead, the `CardImage` is displayed conditionally only if there is an image.
6666

67+
##### No empty task card for deleted tasks
68+
69+
When manually entering URL of a deleted task into the browser address bar, an empty task card was shown.
70+
71+
![Empty task card shown for deleted tasks](/documentation-assets/readme-assets/empty-task-card.png)
72+
73+
While this is also present in the Moments sample project, it is not good UX, which is why I decided to [change it](https://github.com/blahosyl/task-manager-frontend/issues/129) for the present app.
74+
75+
One of my attempts at a solution was to put all of the rendering in TaskDetail into a conditional clause checking if `task` exists, otherwise render the NotFound page. This failed to work. Similarly, checking for `task.id` failed.
76+
77+
I theorized that this is because these 2 variables are defined in the component, and must exist so that the app knows which task the user wants to see. However, `task.title` is empty if the task has been deleted, and it must not be empty for any existing tasks, since it's a compulsory field. Setting this as the condition for rendering the TaskDetail page received the desired result.
78+
6779
## Project Management | Agile Methodologies
6880

6981
### Themes, Epics, Stories & Tasks
Loading

src/pages/tasks/TaskDetail.js

+14-11
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { axiosReq } from "../../api/axiosDefaults";
99
// import appStyles from "../../App.module.css";
1010
import Task from "./Task";
1111
import ProfileList from "../profiles/ProfileList";
12+
import NotFound from "../../components/NotFound";
1213

1314
function TaskDetail() {
1415
const { id } = useParams();
@@ -31,17 +32,19 @@ function TaskDetail() {
3132
}, [id]);
3233

3334
return (
34-
<Row className="h-100">
35-
<Col className="py-2 p-0 p-lg-2" lg={8}>
36-
<Task {...task.results[0]} setTasks={setTask} taskDetail/>
37-
{/* <Container className={appStyles.Content}>
38-
Comments
39-
</Container> */}
40-
</Col>
41-
<Col md={4} className="d-none d-lg-block p-0 p-lg-2">
42-
<ProfileList />
43-
</Col>
44-
</Row>
35+
task.title
36+
? <Row className="h-100">
37+
<Col className="py-2 p-0 p-lg-2" lg={8}>
38+
<Task {...task.results[0]} setTasks={setTask} taskDetail/>
39+
{/* <Container className={appStyles.Content}>
40+
Comments
41+
</Container> */}
42+
</Col>
43+
<Col md={4} className="d-none d-lg-block p-0 p-lg-2">
44+
<ProfileList />
45+
</Col>
46+
</Row>
47+
: <NotFound />
4548
);
4649
}
4750

0 commit comments

Comments
 (0)