Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .github/workflows/quality.yml
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,14 @@ jobs:
shell: pwsh
run: npm run validate:data

- name: Check offline event ordering
shell: pwsh
run: npm run check:offline-events-order

- name: Test offline event sorter
shell: pwsh
run: npm run test:offline-events

- name: Test rating providers
shell: pwsh
run: npm run test:ratings
Expand Down
2 changes: 1 addition & 1 deletion assets/index-CUDjpWEJ.css → assets/index-9DMxuBBi.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion assets/index-DJ0luez0.js → assets/index-DkY6aSAc.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
<meta property="og:title" content="IECSE Comp Team" />
<meta property="og:description" content="IECSE's Official Competitive Programming Team at MIT Manipal" />
<title>IECSE Comp Team</title>
<script type="module" crossorigin src="/CompTeam/assets/index-DJ0luez0.js"></script>
<link rel="stylesheet" crossorigin href="/CompTeam/assets/index-CUDjpWEJ.css">
<script type="module" crossorigin src="/CompTeam/assets/index-DkY6aSAc.js"></script>
<link rel="stylesheet" crossorigin href="/CompTeam/assets/index-9DMxuBBi.css">
</head>
<body>
<div id="root"></div>
Expand Down
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@
"fetch:ratings": "node scripts/refresh-ratings.mjs",
"test:ratings": "node --test scripts/refresh-ratings.test.mjs",
"check:deprecated": "node scripts/check-deprecated-dependencies.mjs",
"validate:data": "node scripts/validate-data.mjs"
"validate:data": "node scripts/validate-data.mjs",
"sort:offline-events": "node scripts/sort-offline-events.mjs",
"check:offline-events-order": "node scripts/sort-offline-events.mjs --check",
"test:offline-events": "node --test scripts/sort-offline-events.test.mjs"
},
"dependencies": {
"react": "^19.2.8",
Expand Down
64 changes: 64 additions & 0 deletions scripts/sort-offline-events.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import fs from 'node:fs';
import path from 'node:path';
import { fileURLToPath } from 'node:url';

const ROOT_DIR = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..');
const EVENTS_PATH = path.join(ROOT_DIR, 'src', 'data', 'offline-events.json');

function dateValue(date, index) {
if (typeof date !== 'string' || !/^\d{4}-\d{2}-\d{2}$/.test(date)) {
throw new Error(`Event at index ${index} must have an ISO date in YYYY-MM-DD format`);
}

const timestamp = Date.parse(`${date}T00:00:00Z`);
if (!Number.isFinite(timestamp) || new Date(timestamp).toISOString().slice(0, 10) !== date) {
throw new Error(`Event at index ${index} has an invalid ISO date: ${date}`);
}
return timestamp;
}

export function sortOfflineEvents(events) {
if (!Array.isArray(events)) throw new Error('offline-events.json must be an array');

return events
.map((event, index) => ({ event, index, timestamp: dateValue(event?.date, index) }))
.sort((a, b) => b.timestamp - a.timestamp || a.index - b.index)
.map(({ event }) => event);
}

export function isSortedNewestFirst(events) {
const sorted = sortOfflineEvents(events);
return events.every((event, index) => event === sorted[index]);
}

function main() {
const checkOnly = process.argv.includes('--check');
const unexpectedArgs = process.argv.slice(2).filter(arg => arg !== '--check');
if (unexpectedArgs.length) throw new Error(`Unknown argument: ${unexpectedArgs[0]}`);

const source = fs.readFileSync(EVENTS_PATH, 'utf8');
const events = JSON.parse(source);
const sorted = sortOfflineEvents(events);

if (checkOnly) {
if (!isSortedNewestFirst(events)) {
console.error('offline-events.json is not sorted newest to oldest; run npm run sort:offline-events');
process.exitCode = 1;
return;
}
console.log('offline-events.json is sorted newest to oldest');
return;
}

fs.writeFileSync(EVENTS_PATH, `${JSON.stringify(sorted, null, 2)}\n`);
console.log('Sorted offline-events.json newest to oldest');
}

if (process.argv[1] && path.resolve(process.argv[1]) === fileURLToPath(import.meta.url)) {
try {
main();
} catch (error) {
console.error('Could not sort offline-events.json:', error.message);
process.exitCode = 1;
}
}
21 changes: 21 additions & 0 deletions scripts/sort-offline-events.test.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import test from 'node:test';
import assert from 'node:assert/strict';
import { isSortedNewestFirst, sortOfflineEvents } from './sort-offline-events.mjs';

test('sorts events newest first, retaining complete records and stable ties', () => {
const older = { date: '2024-01-01', event: 'older', extra: { keep: true } };
const sameDateA = { date: '2025-06-30', event: 'first same day' };
const sameDateB = { date: '2025-06-30', event: 'second same day' };
const newest = { date: '2026-02-01', event: 'newest' };

const sorted = sortOfflineEvents([older, sameDateA, sameDateB, newest]);
assert.deepEqual(sorted, [newest, sameDateA, sameDateB, older]);
assert.equal(sorted[3].extra.keep, true);
assert.equal(isSortedNewestFirst(sorted), true);
assert.equal(isSortedNewestFirst([older, newest]), false);
});

test('rejects malformed and impossible ISO dates', () => {
assert.throws(() => sortOfflineEvents([{ date: '2025-2-01' }]), /YYYY-MM-DD/);
assert.throws(() => sortOfflineEvents([{ date: '2025-02-30' }]), /invalid ISO date/);
});
2 changes: 1 addition & 1 deletion scripts/validate-data.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ function validateOfflineEvents() {
}

for (const e of data) {
if (!e.date || !e.event || !e.position || !e.eventDescription) {
if (!e.date || !e.event || !e.position || !e.eventDescription || typeof e.location !== 'string' || !e.location.trim()) {
console.error(`Invalid event record: ${JSON.stringify(e)}`);
process.exit(1);
}
Expand Down
19 changes: 18 additions & 1 deletion src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,24 @@ function RatingCell({ ratingObj, platformName }: { ratingObj: RatingValue, platf
);
}

function formatUpdatedAt(value: string) {
const parts = new Intl.DateTimeFormat('en-GB', {
timeZone: 'Asia/Kolkata',
day: '2-digit',
month: '2-digit',
year: 'numeric',
hour: '2-digit',
minute: '2-digit',
second: '2-digit',
hourCycle: 'h23',
}).formatToParts(new Date(value));
const getPart = (type: Intl.DateTimeFormatPartTypes) => parts.find((part) => part.type === type)?.value ?? '';

return `${getPart('day')}/${getPart('month')}/${getPart('year')} ${getPart('hour')}:${getPart('minute')}:${getPart('second')} IST`;
}

function OnlineStats() {
const updatedAt = ratingsData.length > 0 && ratingsData[0].updatedAt ? new Date(ratingsData[0].updatedAt).toLocaleString() : 'Never';
const updatedAt = ratingsData.length > 0 && ratingsData[0].updatedAt ? formatUpdatedAt(ratingsData[0].updatedAt) : 'Never';

const [sortKey, setSortKey] = useState<SortKey>('name');
const [sortOrder, setSortOrder] = useState<SortOrder>('asc');
Expand Down Expand Up @@ -209,6 +225,7 @@ function OfflineStats() {
<article key={i} className="event-card">
<div className="event-meta">
<span>{new Date(ev.date).toLocaleDateString(undefined, { year: 'numeric', month: 'long', day: 'numeric' })}</span>
<span className="event-location">Location: {ev.location || 'Location not specified'}</span>
</div>
<h3 className="event-title">{ev.event}</h3>
<div className="event-position">{ev.position}</div>
Expand Down
3 changes: 2 additions & 1 deletion src/data/offline-events.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
[
{
"date": "2026-04-25",
"event": "MIT ACM Chapter's Codentine",
"event": "MIT ACM Chapter's Codentine 7.0",
"location": "Manipal, Karnataka",
"position": "1st",
"eventDescription": "Roonil03 participated and attained first position in the event Codentine.",
"postUrl": null
Expand Down
12 changes: 12 additions & 0 deletions src/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -327,12 +327,24 @@ tr:hover td {
.event-meta {
display: flex;
justify-content: space-between;
align-items: center;
flex-wrap: wrap;
gap: 0.5rem 1rem;
margin-bottom: 0.5rem;
color: var(--text-muted);
font-size: 0.85rem;
text-transform: uppercase;
}

.event-location {
display: inline-flex;
align-items: center;
border: 1px solid var(--border-color);
padding: 0.15rem 0.5rem;
color: var(--text-primary);
font-size: 0.75rem;
}

.event-title {
font-size: 1.25rem;
margin-bottom: 0.25rem;
Expand Down
Loading