fix(mobile): drive learning search from assignments
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
export interface LearningTopicAssignment {
|
||||
source?: string | null;
|
||||
status?: string | null;
|
||||
scenarioName?: string | null;
|
||||
}
|
||||
|
||||
const normalized = (value?: string | null) => value?.trim() || '';
|
||||
|
||||
export const selectLearningTopic = (
|
||||
assignments: readonly LearningTopicAssignment[],
|
||||
fallbackTopic: string
|
||||
) => {
|
||||
const scenarioAssignments = assignments.filter((item) =>
|
||||
normalized(item.source) !== 'daily' && Boolean(normalized(item.scenarioName))
|
||||
);
|
||||
const selected = scenarioAssignments.find((item) => normalized(item.status) !== '已完成')
|
||||
|| scenarioAssignments[0];
|
||||
|
||||
return normalized(selected?.scenarioName) || fallbackTopic;
|
||||
};
|
||||
|
||||
export const buildLearningTopics = (
|
||||
assignments: readonly LearningTopicAssignment[],
|
||||
fallbackTopic: string,
|
||||
quickQuestions: readonly string[]
|
||||
) => {
|
||||
const values = [
|
||||
fallbackTopic,
|
||||
...assignments
|
||||
.filter((item) => normalized(item.source) !== 'daily')
|
||||
.map((item) => normalized(item.scenarioName)),
|
||||
...quickQuestions
|
||||
];
|
||||
const topics: string[] = [];
|
||||
|
||||
values.forEach((value) => {
|
||||
const topic = normalized(value);
|
||||
if (topic && !topics.includes(topic)) {
|
||||
topics.push(topic);
|
||||
}
|
||||
});
|
||||
|
||||
return topics;
|
||||
};
|
||||
@@ -13,3 +13,18 @@ export const resetPageScroll = () => {
|
||||
setTimeout(scrollTop, 80);
|
||||
setTimeout(scrollTop, 240);
|
||||
};
|
||||
|
||||
const switchToToday = () => {
|
||||
uni.switchTab({ url: '/pages/user/today/index' });
|
||||
};
|
||||
|
||||
export const navigateBackToToday = () => {
|
||||
if (getCurrentPages().length <= 1) {
|
||||
switchToToday();
|
||||
return;
|
||||
}
|
||||
uni.navigateBack({
|
||||
delta: 1,
|
||||
fail: switchToToday
|
||||
});
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user