Skip to content

Commit

Permalink
Merge remote-tracking branch 'refs/remotes/origin/koni/dev/issue-75' …
Browse files Browse the repository at this point in the history
…into telegram-dev
  • Loading branch information
saltict committed Jul 26, 2024
2 parents 9b84cc8 + 60c44b7 commit f110be0
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 6 deletions.
19 changes: 14 additions & 5 deletions packages/extension-koni-ui/src/Popup/Home/Leaderboard/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const apiSDK = BookaSdk.instance;

enum TabType {
WEEKLY = 'weekly',
DED_PLAYDROP = 'ded_playdrop',
INVITE_TO_PLAY = 'invite_to_play',
VARA_PLAYDROP = 'vara_playdrop',
}

Expand Down Expand Up @@ -91,10 +91,10 @@ const Component = ({ className }: Props): React.ReactElement => {
}
},
{
label: t('DED'),
value: TabType.DED_PLAYDROP,
label: t('Invite to Play'),
value: TabType.INVITE_TO_PLAY,
leaderboardInfo: {
onClickShare: onClickShare(TabType.DED_PLAYDROP)
onClickShare: onClickShare(TabType.INVITE_TO_PLAY)
}
},
{
Expand All @@ -108,13 +108,22 @@ const Component = ({ className }: Props): React.ReactElement => {

return baseItems.map((item) => {
const { end: endDate, start: startDate } = calculateStartAndEnd(item.value);
let type = 'all';
let gameId = 0;

if (item.value === TabType.INVITE_TO_PLAY){
type = 'inviteToPlay';
gameId = 5;
}

return {
...item,
leaderboardInfo: {
...item.leaderboardInfo,
startDate,
endDate
endDate,
type,
gameId
}
};
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export type LeaderboardTabGroupItemType = TabGroupItemType & {
startDate?: string;
endDate?: string;
type?: string;
gameId?: number;
}
}

Expand Down Expand Up @@ -83,7 +84,7 @@ const Component = ({ className, defaultSelectedTab, gameId, tabGroupItems }: Pro
leaderboardSub = apiSDK.subscribeLeaderboard(
currentTabInfo.leaderboardInfo.startDate,
currentTabInfo.leaderboardInfo.endDate,
gameId || 0, 100,
gameId || currentTabInfo.leaderboardInfo.gameId || 0, 100,
currentTabInfo.leaderboardInfo.type).subscribe((data) => {
setLeaderboardItems(data);
});
Expand Down
8 changes: 8 additions & 0 deletions packages/extension-koni-ui/src/utils/date/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,14 @@ export function calculateStartAndEnd (key: string) {
return { start: formatFully(startDate), end: formatFully(endDate) };
}

case 'invite_to_play': {
const dayOfWeek = today.getUTCDay(); // 0 (Chủ Nhật) đến 6 (Thứ Bảy)
const start = new Date(Date.UTC(year, month, day - dayOfWeek + (dayOfWeek === 0 ? -6 : 1))); // Adjust if today is Sunday
const end = new Date(Date.UTC(start.getUTCFullYear(), start.getUTCMonth(), start.getUTCDate() + 6));

return { start: formatDate(start, false), end: formatDate(end, true) };
}

default:
throw new Error('Invalid key. Must be "weekly", "monthly", or "yearly".');
}
Expand Down

0 comments on commit f110be0

Please sign in to comment.