Skip to content

Commit 154ce8c

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

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()
@@ -246,7 +249,7 @@ export const useApi = () => {
246249
updatedAt: d.updatedAt
247250
}
248251

249-
// console.log(metadata, d.data)
252+
// console.log(metadata, d.data, todos)
250253
return {
251254
title: d.title,
252255
data: d.data,
@@ -255,11 +258,15 @@ export const useApi = () => {
255258
}
256259
})
257260

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

apps/webapp/src/Stores/useTodoStore.ts

+7-6
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ import {
1111
PriorityType,
1212
TodoStatus,
1313
TodosType,
14-
TodoType} from '@mexit/core'
14+
TodoType
15+
} from '@mexit/core'
1516

1617
import { getTodoMetadata } from '../Editor/Plugins/todoUtils'
1718

@@ -36,8 +37,8 @@ export const createTodo = (
3637
},
3738
mentions,
3839
tags,
39-
createdAt: Date.now(),
40-
updatedAt: Date.now()
40+
createdAt: metaData?.createdAt ?? Date.now(),
41+
updatedAt: metaData?.updatedAt ?? Date.now()
4142
}
4243
}
4344

@@ -158,9 +159,9 @@ const useTodoStore = create<TodoStoreType>(
158159
const tags = getTagsFromContent([content])
159160
const mentions = getMentionsFromContent([content])
160161
// mog('replaceContent', { nodeid, tags, mentions, todosContent, nodeTodos, todo, content })
161-
return todo
162-
? { ...todo, mentions, tags, content: [content] }
163-
: createTodo(nodeid, content.id, [content], mentions, tags)
162+
163+
// Currently nothing as todo id, it is same as block id for now
164+
return createTodo(nodeid, content.id, [content], mentions, tags)
164165
})
165166

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

0 commit comments

Comments
 (0)