Skip to content

Commit

Permalink
Update Task sorting
Browse files Browse the repository at this point in the history
  • Loading branch information
saltict committed Jun 26, 2024
1 parent 48ba966 commit 337a799
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 26 deletions.
72 changes: 47 additions & 25 deletions packages/extension-koni-ui/src/Popup/Home/Mission/TaskList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { TaskCategory, TaskCategoryInfo } from '@subwallet/extension-koni-ui/con
import { useTranslation } from '@subwallet/extension-koni-ui/hooks';
import TaskItem from '@subwallet/extension-koni-ui/Popup/Home/Mission/TaskItem';
import { ThemeProps } from '@subwallet/extension-koni-ui/types';
import React from 'react';
import React, { useMemo } from 'react';
import styled from 'styled-components';

type Props = ThemeProps & {
Expand All @@ -17,36 +17,58 @@ type Props = ThemeProps & {
const Component = ({ actionReloadPoint, className, taskCategoryInfoMap, taskCategoryMap }: Props): React.ReactElement => {
const { t } = useTranslation();

const taskCategoryInfoList = useMemo(() => {
const checkInCatId = Object.values(taskCategoryMap).find((tci) => tci.slug === 'check_in')?.id;

if (!checkInCatId) {
return Object.values(taskCategoryInfoMap);
}

return Object.values(taskCategoryInfoMap).sort((a, b) => {
if (a.id === checkInCatId) {
return -1;
}

if (b.id === checkInCatId) {
return 1;
}

return 0;
});
}, [taskCategoryInfoMap, taskCategoryMap]);

return (
<div className={className}>
{
Object.values(taskCategoryInfoMap).map((tci) => (
<div
className={'__task-category-item'}
key={tci.id}
>
<div className='__task-category-info'>
<div className='__task-category-name'>
{taskCategoryMap[tci.id]?.name}
</div>
taskCategoryInfoList.map((tci) => (
tci.tasks.length > 0 && (
<div
className={'__task-category-item'}
key={tci.id}
>
<div className='__task-category-info'>
<div className='__task-category-name'>
{taskCategoryMap[tci.id]?.name}
</div>

<div className='__complete-missions'>
{`${tci.completeCount}/${tci.tasks.length}`} {t('missions')}
<div className='__complete-missions'>
{`${tci.completeCount}/${tci.tasks.length}`} {t('missions')}
</div>
</div>
<div className='__tasks-container'>
{
tci.tasks.map((t) => (
<TaskItem
actionReloadPoint={actionReloadPoint}
className={'__task-item'}
key={t.id}
task={t}
/>
))
}
</div>
</div>
<div className='__tasks-container'>
{
tci.tasks.map((t) => (
<TaskItem
actionReloadPoint={actionReloadPoint}
className={'__task-item'}
key={t.id}
task={t}
/>
))
}
</div>
</div>
)
))
}
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ function getTaskCategoryInfoMap (tasks: Task[]): Record<number, TaskCategoryInfo
};
}

if (!t.completedAt && t.endTime && new Date(t.endTime).getTime() < now) {
if (t.endTime && new Date(t.endTime).getTime() < now) {
return;
}

Expand Down

0 comments on commit 337a799

Please sign in to comment.