Skip to content

Commit 9aa969b

Browse files
committed
get todo status and priority from content for public view;
Signed-off-by: Sahil Shubham <[email protected]>
1 parent f0da3de commit 9aa969b

File tree

3 files changed

+20
-10
lines changed

3 files changed

+20
-10
lines changed

apps/webapp/src/Editor/Plugins/todoUtils.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,13 @@ export const getTodoMetadata = (content: NodeEditorContent) => {
1818
const block = content[0]
1919

2020
if (block && block.type === ELEMENT_TODO_LI) {
21-
const { priority, status, ...rest } = block
21+
const { priority, status, metadata, ...rest } = block
2222

2323
return {
2424
priority,
25-
status
25+
status,
26+
createdAt: metadata?.createdAt,
27+
updatedAt: metadata?.updatedAt
2628
}
2729
}
2830
}

apps/webapp/src/Hooks/API/useNodeAPI.ts

+9-2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
extractMetadata,
77
GET_REQUEST_MINIMUM_GAP_IN_MS,
88
getTagsFromContent,
9+
getTodosFromContent,
910
mog,
1011
NodeEditorContent,
1112
removeNulls
@@ -15,6 +16,7 @@ import { useAuthStore } from '../../Stores/useAuth'
1516
import { useContentStore } from '../../Stores/useContentStore'
1617
import { useDataStore } from '../../Stores/useDataStore'
1718
import { useSnippetStore } from '../../Stores/useSnippetStore'
19+
import { useTodoStore } from '../../Stores/useTodoStore'
1820
import { deserializeContent, serializeContent } from '../../Utils/serializer'
1921
import { WorkerRequestType } from '../../Utils/worker'
2022
import { runBatchWorker } from '../../Workers/controller'
@@ -30,6 +32,7 @@ export const useApi = () => {
3032
const setMetadata = useContentStore((store) => store.setMetadata)
3133
const setContent = useContentStore((store) => store.setContent)
3234
const { getTitleFromNoteId } = useLinks()
35+
const updateNodeTodos = useTodoStore((store) => store.replaceContentOfTodos)
3336
const { updateILinksFromAddedRemovedPaths } = useInternalLinks()
3437
const { setNodePublic, setNodePrivate, checkNodePublic } = useDataStore()
3538
const { updateFromContent } = useUpdater()
@@ -245,7 +248,7 @@ export const useApi = () => {
245248
updatedAt: d.updatedAt
246249
}
247250

248-
// console.log(metadata, d.data)
251+
// console.log(metadata, d.data, todos)
249252
return {
250253
title: d.title,
251254
data: d.data,
@@ -254,11 +257,15 @@ export const useApi = () => {
254257
}
255258
})
256259

260+
const content = deserializeContent(res.data)
261+
const todos = getTodosFromContent(content)
262+
updateNodeTodos(nodeId, todos)
263+
257264
if (res) {
258265
return {
259266
id: nodeId,
260267
title: res.title ?? '',
261-
content: deserializeContent(res.data),
268+
content: content,
262269
metadata: res.metadata ?? undefined,
263270
version: res.version
264271
}

apps/webapp/src/Stores/useTodoStore.ts

+7-6
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ import {
88
PriorityType,
99
TodoStatus,
1010
TodosType,
11-
TodoType} from '@mexit/core'
11+
TodoType
12+
} from '@mexit/core'
1213

1314
import { getTodoMetadata } from '../Editor/Plugins/todoUtils'
1415
import { useReminderStore } from './useReminderStore'
@@ -34,8 +35,8 @@ export const createTodo = (
3435
},
3536
mentions,
3637
tags,
37-
createdAt: Date.now(),
38-
updatedAt: Date.now()
38+
createdAt: metaData?.createdAt ?? Date.now(),
39+
updatedAt: metaData?.updatedAt ?? Date.now()
3940
}
4041
}
4142

@@ -156,9 +157,9 @@ const useTodoStore = create<TodoStoreType>(
156157
const tags = getTagsFromContent([content])
157158
const mentions = getMentionsFromContent([content])
158159
// mog('replaceContent', { nodeid, tags, mentions, todosContent, nodeTodos, todo, content })
159-
return todo
160-
? { ...todo, mentions, tags, content: [content] }
161-
: createTodo(nodeid, content.id, [content], mentions, tags)
160+
161+
// Currently nothing as todo id, it is same as block id for now
162+
return createTodo(nodeid, content.id, [content], mentions, tags)
162163
})
163164

164165
const leftOutTodos = nTodo.filter((todo) => !nodeTodos.find((t) => t.id === todo.id && nodeid === t.nodeid))

0 commit comments

Comments
 (0)