|
|
@ -1,5 +1,5 @@ |
|
|
|
import { httpGet, httpPost } from './http'; |
|
|
|
|
|
|
|
import Cookies from 'js-cookie'; |
|
|
|
import Cookies from 'js-cookie'; |
|
|
|
|
|
|
|
import { httpGet, httpPost } from './http'; |
|
|
|
import { TOKEN_COOKIE_NAME } from './jwt'; |
|
|
|
import { TOKEN_COOKIE_NAME } from './jwt'; |
|
|
|
import Element = astroHTML.JSX.Element; |
|
|
|
import Element = astroHTML.JSX.Element; |
|
|
|
|
|
|
|
|
|
|
@ -14,13 +14,10 @@ type TopicMeta = { |
|
|
|
|
|
|
|
|
|
|
|
export async function isTopicDone(topic: TopicMeta): Promise<boolean> { |
|
|
|
export async function isTopicDone(topic: TopicMeta): Promise<boolean> { |
|
|
|
const { topicId, resourceType, resourceId } = topic; |
|
|
|
const { topicId, resourceType, resourceId } = topic; |
|
|
|
const progressResult = await getResourceProgress(resourceType, resourceId); |
|
|
|
const { done = [] } = |
|
|
|
|
|
|
|
(await getResourceProgress(resourceType, resourceId)) || {}; |
|
|
|
if (!progressResult.done) { |
|
|
|
|
|
|
|
return false; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return progressResult.done.includes(topicId); |
|
|
|
return done?.includes(topicId); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
export async function getTopicStatus( |
|
|
|
export async function getTopicStatus( |
|
|
@ -29,11 +26,11 @@ export async function getTopicStatus( |
|
|
|
const { topicId, resourceType, resourceId } = topic; |
|
|
|
const { topicId, resourceType, resourceId } = topic; |
|
|
|
const progressResult = await getResourceProgress(resourceType, resourceId); |
|
|
|
const progressResult = await getResourceProgress(resourceType, resourceId); |
|
|
|
|
|
|
|
|
|
|
|
if (progressResult.done.includes(topicId)) { |
|
|
|
if (progressResult?.done.includes(topicId)) { |
|
|
|
return 'done'; |
|
|
|
return 'done'; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (progressResult.learning.includes(topicId)) { |
|
|
|
if (progressResult?.learning.includes(topicId)) { |
|
|
|
return 'learning'; |
|
|
|
return 'learning'; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -152,9 +149,10 @@ export function setResourceProgress( |
|
|
|
|
|
|
|
|
|
|
|
export function renderTopicProgress( |
|
|
|
export function renderTopicProgress( |
|
|
|
topicId: string, |
|
|
|
topicId: string, |
|
|
|
isDone: boolean, |
|
|
|
topicProgress: ResourceProgressType |
|
|
|
isLearning: boolean |
|
|
|
|
|
|
|
) { |
|
|
|
) { |
|
|
|
|
|
|
|
const isLearning = topicProgress === 'learning'; |
|
|
|
|
|
|
|
const isDone = topicProgress === 'done'; |
|
|
|
const matchingElements: Element[] = []; |
|
|
|
const matchingElements: Element[] = []; |
|
|
|
|
|
|
|
|
|
|
|
// Elements having sort order in the beginning of the group id
|
|
|
|
// Elements having sort order in the beginning of the group id
|
|
|
@ -202,13 +200,14 @@ export async function renderResourceProgress( |
|
|
|
resourceType: ResourceType, |
|
|
|
resourceType: ResourceType, |
|
|
|
resourceId: string |
|
|
|
resourceId: string |
|
|
|
) { |
|
|
|
) { |
|
|
|
const progress = await getResourceProgress(resourceType, resourceId); |
|
|
|
const { done = [], learning = [] } = |
|
|
|
|
|
|
|
(await getResourceProgress(resourceType, resourceId)) || {}; |
|
|
|
|
|
|
|
|
|
|
|
progress.done.forEach((topicId) => { |
|
|
|
done.forEach((topicId) => { |
|
|
|
renderTopicProgress(topicId, true, false); |
|
|
|
renderTopicProgress(topicId, 'done'); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
progress.learning.forEach((topicId) => { |
|
|
|
learning.forEach((topicId) => { |
|
|
|
renderTopicProgress(topicId, false, true); |
|
|
|
renderTopicProgress(topicId, 'learning'); |
|
|
|
}); |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|