Skip to content

Commit d789a22

Browse files
committed
Implement subtasks of subtasks
1 parent 8cfe665 commit d789a22

12 files changed

Lines changed: 94 additions & 63 deletions

File tree

components/Jotting/jotting.module.css

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,14 @@
9292
flex-direction: column;
9393
}
9494

95+
.subtaskTitle {
96+
background: none;
97+
border: none;
98+
font-size: 1em;
99+
font-family:'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
100+
text-align: left;
101+
}
102+
95103
.subtaskHeading {
96104
margin: 0 0 3px 0;
97105
}

components/Jotting/jottingDetails.js

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,12 @@ export default function JottingDetails({ jottingInfo, jotType }) {
2424
};
2525

2626
// Request the body if not passed by parent component
27-
if (jottingInfo.body == null) {
28-
useCancelableRequest(
29-
getBody, // Request function
30-
setBody, // State dispatcher
31-
[jottingInfo.id, jotType], // Parameters of request function
32-
[jottingInfo.id] // Dependency list
33-
);
34-
}
27+
useCancelableRequest(
28+
getBody, // Request function
29+
setBody, // State dispatcher
30+
[jottingInfo.id, jotType], // Parameters of request function
31+
[jottingInfo.id] // Dependency list
32+
);
3533

3634
// Display body if the body was successfully received
3735
if (typeof body == "string") {

components/Jotting/subtaskList.js

Lines changed: 53 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,28 @@
1-
import { useEffect, useState } from "react";
2-
import { useRecurringRequest } from "../../libs/Datastore/requestHelpers";
3-
import { deleteTask, getSubtasks } from "../../libs/Datastore/requests";
4-
import ProgressSpinner from "../ProgressSpinner/progressSpinner";
1+
import useSWR from "swr";
2+
import { deleteTask, getSubtasksRequest } from "../../libs/Datastore/requests";
53
import FetchError from "../FetchError/fetchError";
4+
import ProgressSpinner from "../ProgressSpinner/progressSpinner";
65
import RemoveableListItem from "../RemoveableListItem/removeableListItem";
76
import StyledCheckbox from "../StyledCheckbox/styledCheckbox";
87
import jotting from "./jotting.module.css";
8+
import Link from "next/link";
9+
import Jotting from "../../libs/Jotting";
10+
import { useRouter } from "next/router";
11+
12+
const fetcher = (id) => getSubtasksRequest(id).makeRequest(new AbortController());
913

1014
/**
1115
* @param { {id : number } } props The info about the task
1216
* @param {number} props.id The id of the parent task
1317
*/
1418
export default function SubtaskList({ id, subtasksState }) {
1519
const [subtasks, setSubtasks] = subtasksState;
20+
const { data, error } = useSWR(id, fetcher);
21+
const router = useRouter();
1622

17-
// componentDidUpdate() - recur subtasks
18-
useRecurringRequest(() => {
19-
getSubtasks(id)
20-
.then((response) => {
21-
if (response != subtasks)
22-
setSubtasks(response);
23-
})
24-
.catch(() => {});
25-
});
23+
if (error) return <FetchError itemName="subtasks" />;
24+
if (!data)
25+
return <ProgressSpinner />;
2626

2727
const handleRemoveClick = (e) => {
2828
const itemId = e.target.parentElement.id.substring(2);
@@ -41,28 +41,45 @@ export default function SubtaskList({ id, subtasksState }) {
4141
.catch(alert);
4242
};
4343

44-
if (subtasks instanceof Array)
45-
return (
46-
<ul className={jotting.subtasks}>
47-
{subtasks.map((item) => {
48-
return (
49-
<RemoveableListItem
50-
key={item.id}
51-
handleRemoveClick={handleRemoveClick}
52-
removeText="X"
53-
id={"s-" + item.id}
54-
content={item.title}
44+
return (
45+
<ul className={jotting.subtasks}>
46+
{data.data.map((item) => {
47+
return (
48+
<li key={item.id} className="removeableListItem">
49+
<StyledCheckbox
50+
id={item.id}
51+
prefix="subtask-completion-box-"
52+
completed={item.completed == 1}
53+
/>
54+
<button className={jotting.subtaskTitle} onClick={() => Jotting.openJotting(router, "task", item)}>{item.title}</button>
55+
<button
56+
onClick={handleRemoveClick}
57+
className="removeItemButton"
5558
>
56-
<StyledCheckbox
57-
id={item.id}
58-
prefix="subtask-completion-box-"
59-
completed={item.completed == 1}
60-
/>
61-
</RemoveableListItem>
62-
);
63-
})}
64-
</ul>
65-
);
66-
else if (subtasks != null) return <FetchError itemName="subtasks" />;
67-
else return <ProgressSpinner />;
59+
X
60+
</button>
61+
<ul className={jotting.subsubtasks}>
62+
{item.subtasks.map(grandchild => (
63+
<li key={grandchild.id}>
64+
<StyledCheckbox
65+
id={grandchild.id}
66+
prefix="subtask-completion-box-"
67+
completed={grandchild.completed == 1}
68+
/>
69+
<button className={jotting.subtaskTitle} onClick={() => Jotting.openJotting(router, "task", grandchild)}>{grandchild.title}</button>
70+
<button
71+
className="removeItemButton"
72+
>X</button>
73+
</li>
74+
))}
75+
</ul>
76+
</li>
77+
78+
);
79+
})}
80+
</ul>
81+
);
82+
83+
84+
6885
}

components/JottingsControls/jottingsControl.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,6 @@ export default function JottingsControl(props) {
9292
useEffect(() => {
9393
makeLabelsRequest();
9494
makeJottingsRequests();
95-
console.log(router.asPath);
9695
}, []);
9796

9897
const showList = list => router.asPath.includes(`list=${list}`)

components/JottingsControls/jottingsControl.module.css

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -44,20 +44,11 @@
4444
.fullJotting {
4545
display: grid;
4646
grid-row: 2 / 5;
47-
grid-column-end: -1;
4847
justify-self: flex-start;
4948
overflow: auto;
5049
grid-template-columns: 255px repeat(6, 175px);
5150
}
5251

53-
.taskControl {
54-
grid-column-start: 1;
55-
}
56-
57-
.noteControl {
58-
grid-column-start: 2;
59-
}
60-
6152
.jottingContent {
6253
grid-row: 1 / 2;
6354
grid-column: 1 / -3;

libs/Datastore/BorumRequest.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
export default class BorumRequest extends Request {
2-
private commonHeaders: HeadersInit = {};
2+
commonHeaders: HeadersInit = {};
33
private init: RequestInit = {};
44

55
constructor(input: RequestInfo, init?: RequestInit) {

libs/Datastore/requests.js

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,13 @@ export async function getSharedJottings(abortController = null) {
6666
return response;
6767
}
6868

69+
export async function getTask(id, abortController = null) {
70+
const queryString = `id=${id}`;
71+
return await BorumJotRequest.initialize(`task?${queryString}`)
72+
.authorize()
73+
.makeRequest(abortController);
74+
}
75+
6976
/**
7077
* Makes GET request to API to get body of the note
7178
* @param {number} id The id of the note whose body is getting fetched
@@ -179,14 +186,16 @@ export async function createSubtask(id, jotName) {
179186
}
180187

181188
export async function getSubtasks(id) {
182-
const queryString = `id=${id}`;
183-
const { data } = await BorumJotRequest.initialize(`subtasks?${queryString}`)
184-
.authorize()
185-
.makeRequest();
189+
const { data } = await getSubtasksRequest(id).makeRequest();
186190

187191
return data;
188192
}
189193

194+
export function getSubtasksRequest(id) {
195+
const queryString = `id=${id}&subsubtasks`;
196+
return BorumJotRequest.initialize(`subtasks?${queryString}`).authorize();
197+
}
198+
190199
/**
191200
*
192201
* @param {number} id id of the note

libs/Datastore/responseHelpers.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ export function useCancelableRequest(
2929
props,
3030
dependencyList = []
3131
) {
32-
// componentDidMount(), componentDidUpdate(), componentWillUmmount()
3332
useEffect(() => {
3433
const abortController = new AbortController();
3534

libs/UrlService.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,7 @@ export default class UrlService {
6161
if (!this.queryHasJottingInfo(jotType)) return;
6262

6363
this.router.query = {
64-
type: jotType,
65-
jotType: jotType,
64+
type: jotType, jotType,
6665
id: parseInt(query[1]),
6766
title: query[2],
6867
};

pages/Home/home.module.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
@media only screen and (min-width: 800px) {
1313
.main {
1414
grid-template-rows: auto 100px repeat(2, 200px) 30px;
15-
grid-template-columns: 255px 15% 15%;
15+
grid-template-columns: 255px repeat(6, 13%);
1616
}
1717
}
1818

0 commit comments

Comments
 (0)