Skip to content

Commit 24732c5

Browse files
ErwanDecosterPierreJeanjacquot
authored andcommitted
feat: replace inline recent timestamp calculation with getRecentFromTimestamp utility function
1 parent f3e400a commit 24732c5

File tree

5 files changed

+16
-12
lines changed

5 files changed

+16
-12
lines changed

src/modules/apps/AppsPreviewTable.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import AppIcon from '@/components/icons/AppIcon';
1010
import { Button } from '@/components/ui/button';
1111
import useUserStore from '@/stores/useUser.store';
1212
import { createPlaceholderDataFn } from '@/utils/createPlaceholderDataFnForQueryKey';
13+
import { getRecentFromTimestamp } from '@/utils/format';
1314
import { ErrorAlert } from '../ErrorAlert';
1415
import { appsQuery } from './appsQuery';
1516
import { columns } from './appsTable/columns';
@@ -18,7 +19,7 @@ export function AppsPreviewTable({ className }: { className?: string }) {
1819
const { chainId } = useUserStore();
1920

2021
// Pertinent ordering: usageCount desc + recent usage constraint (last 14 days)
21-
const recentFrom = Math.floor(Date.now() / 1000) - 14 * 24 * 60 * 60;
22+
const recentFrom = getRecentFromTimestamp();
2223
const orderBy: App_OrderBy = App_OrderBy.UsageCount;
2324
const orderDirection: OrderDirection = OrderDirection.Desc;
2425
const queryKey = [

src/modules/workerpools/WorkerpoolsPreviewTable.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import WorkerpoolIcon from '@/components/icons/WorkerpoolIcon';
1010
import { Button } from '@/components/ui/button';
1111
import useUserStore from '@/stores/useUser.store';
1212
import { createPlaceholderDataFn } from '@/utils/createPlaceholderDataFnForQueryKey';
13+
import { getRecentFromTimestamp } from '@/utils/format';
1314
import { ErrorAlert } from '../ErrorAlert';
1415
import { workerpoolsQuery } from './workerpoolsQuery';
1516
import { columns } from './workerpoolsTable/columns';
@@ -18,7 +19,7 @@ export function WorkerpoolsPreviewTable({ className }: { className?: string }) {
1819
const { chainId } = useUserStore();
1920

2021
// Pertinent ordering: usageCount desc + recent usage constraint (last 14 days)
21-
const recentFrom = Math.floor(Date.now() / 1000) - 14 * 24 * 60 * 60;
22+
const recentFrom = getRecentFromTimestamp();
2223
const orderBy: Workerpool_OrderBy = Workerpool_OrderBy.UsageCount;
2324
const orderDirection: OrderDirection = OrderDirection.Desc;
2425
const queryKey = [

src/routes/$chainSlug/_layout/apps.tsx

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import { columns } from '@/modules/apps/appsTable/columns';
2323
import { SearcherBar } from '@/modules/search/SearcherBar';
2424
import useUserStore from '@/stores/useUser.store';
2525
import { createPlaceholderDataFn } from '@/utils/createPlaceholderDataFnForQueryKey';
26-
import { getAdditionalPages } from '@/utils/format';
26+
import { getAdditionalPages, getRecentFromTimestamp } from '@/utils/format';
2727

2828
export const Route = createFileRoute('/$chainSlug/_layout/apps')({
2929
component: AppsRoute,
@@ -37,10 +37,7 @@ function useAppsData(currentPage: number, orderFilter: string) {
3737

3838
const orderBy = orderFilter === 'pertinent' ? 'usageCount' : 'timestamp';
3939
const orderDirection = orderFilter === 'oldest' ? 'asc' : 'desc';
40-
const recentFrom =
41-
orderFilter === 'pertinent'
42-
? Math.floor(Date.now() / 1000) - 14 * 24 * 60 * 60
43-
: 0;
40+
const recentFrom = orderFilter === 'pertinent' ? getRecentFromTimestamp() : 0;
4441

4542
const queryKey = [
4643
chainId,

src/routes/$chainSlug/_layout/workerpools.tsx

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import { workerpoolsQuery } from '@/modules/workerpools/workerpoolsQuery';
2323
import { columns } from '@/modules/workerpools/workerpoolsTable/columns';
2424
import useUserStore from '@/stores/useUser.store';
2525
import { createPlaceholderDataFn } from '@/utils/createPlaceholderDataFnForQueryKey';
26-
import { getAdditionalPages } from '@/utils/format';
26+
import { getAdditionalPages, getRecentFromTimestamp } from '@/utils/format';
2727

2828
export const Route = createFileRoute('/$chainSlug/_layout/workerpools')({
2929
component: WorkerpoolsRoute,
@@ -36,10 +36,7 @@ function useWorkerpoolsData(currentPage: number, orderFilter: string) {
3636
const nextNextSkip = skip + 2 * TABLE_LENGTH;
3737
const orderBy = orderFilter === 'pertinent' ? 'usageCount' : 'timestamp';
3838
const orderDirection = orderFilter === 'oldest' ? 'asc' : 'desc';
39-
const recentFrom =
40-
orderFilter === 'pertinent'
41-
? Math.floor(Date.now() / 1000) - 14 * 24 * 60 * 60
42-
: 0;
39+
const recentFrom = orderFilter === 'pertinent' ? getRecentFromTimestamp() : 0;
4340

4441
const queryKey = [
4542
chainId,

src/utils/format.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11
import { multiaddr } from '@multiformats/multiaddr';
22
import { Buffer } from 'buffer';
33

4+
/**
5+
* Returns a unix timestamp (in seconds) for 14 days ago from now.
6+
* Used for recency filtering ("pertinent" mode).
7+
*/
8+
export function getRecentFromTimestamp(days = 14): number {
9+
return Math.floor(Date.now() / 1000) - days * 24 * 60 * 60;
10+
}
11+
412
export const multiaddrHexToHuman = (hexString: string): string => {
513
if (hexString.substring(0, 2) !== '0x') return hexString;
614
let res: string;

0 commit comments

Comments
 (0)