|
|
@ -24,10 +24,29 @@ export const VideoList: FC<Props> = ({categoryKey, ready}) => { |
|
|
|
const [page, setPage] = useState(1) |
|
|
|
const [page, setPage] = useState(1) |
|
|
|
const [records, setRecords] = useState<LearnRecord[]>([]) |
|
|
|
const [records, setRecords] = useState<LearnRecord[]>([]) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function screen(oldData: Curriculum[], data: Curriculum[]): Curriculum[] { |
|
|
|
|
|
|
|
return data.reduce((pre, cur) => { |
|
|
|
|
|
|
|
const index = pre.findIndex(d => d.id === cur.id) |
|
|
|
|
|
|
|
if (index === -1) { |
|
|
|
|
|
|
|
pre.push(cur) |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
pre.splice(index, 1, cur) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return pre |
|
|
|
|
|
|
|
}, oldData) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
async function getData() { |
|
|
|
async function getData() { |
|
|
|
try { |
|
|
|
try { |
|
|
|
const res = await publicApi.course({page: 1, pageSize: 10 * page}) |
|
|
|
const res = await publicApi.course({page: page, pageSize: 10}) |
|
|
|
setData(res) |
|
|
|
|
|
|
|
|
|
|
|
const old: Courses = JSON.parse(JSON.stringify(data)) |
|
|
|
|
|
|
|
setData({ |
|
|
|
|
|
|
|
is_finished: screen(old.is_finished, res.is_finished || []), |
|
|
|
|
|
|
|
is_required: screen(old.is_required, res.is_required || []), |
|
|
|
|
|
|
|
is_not_finished: screen(old.is_not_finished, res.is_not_finished || []), |
|
|
|
|
|
|
|
is_not_required: screen(old.is_not_required, res.is_not_required || []), |
|
|
|
|
|
|
|
}) |
|
|
|
} catch (e) { |
|
|
|
} catch (e) { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -64,6 +83,7 @@ export const VideoList: FC<Props> = ({categoryKey, ready}) => { |
|
|
|
}) |
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
eventsIndex.on(({id}) => { |
|
|
|
eventsIndex.on(({id}) => { |
|
|
|
|
|
|
|
if (id == null) return; |
|
|
|
for (const [index, notFinished] of data.is_not_finished.entries()) { |
|
|
|
for (const [index, notFinished] of data.is_not_finished.entries()) { |
|
|
|
if (notFinished.id === id) { |
|
|
|
if (notFinished.id === id) { |
|
|
|
data.is_finished.push(notFinished) |
|
|
|
data.is_finished.push(notFinished) |
|
|
@ -75,6 +95,7 @@ export const VideoList: FC<Props> = ({categoryKey, ready}) => { |
|
|
|
|
|
|
|
|
|
|
|
useDidShow(() => { |
|
|
|
useDidShow(() => { |
|
|
|
if (ready) { |
|
|
|
if (ready) { |
|
|
|
|
|
|
|
getData().then() |
|
|
|
getRecords().then() |
|
|
|
getRecords().then() |
|
|
|
} |
|
|
|
} |
|
|
|
}) |
|
|
|
}) |
|
|
|