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
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,16 @@ var tsml_react_config = {
};
```

### Filter to current day

You can link directly to today's meetings using the special `today` keyword:

```
https://tsml-ui.code4recovery.org/tests/aasanjose.html#/?weekday=today
```

This automatically filters to the current day of the week.

### Use kilometers

Distances can be calculated in miles (`mi`) or kilometers (`km`).
Expand Down
2 changes: 1 addition & 1 deletion public/app.js

Large diffs are not rendered by default.

7 changes: 6 additions & 1 deletion src/helpers/validate-input.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,15 @@ export const validateInput = (
>)
: defaultInput.time;

const weekday = params.has('weekday')
let weekday = params.has('weekday')
? `${params.get('weekday')}`.split('/')
: defaultInput.weekday;

if (weekday.includes('today')) {
const today = settings.weekdays[new Date().getDay()];
weekday = weekday.map(day => day === 'today' ? today : day);
}

const type = params.has('type')
? `${params.get('type')}`.split('/')
: defaultInput.type;
Expand Down
25 changes: 25 additions & 0 deletions test/__tests__/validate-input-today.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { validateInput } from '../../src/helpers/validate-input';
import { defaults } from '../../src/hooks/settings';

describe('validateInput with weekday=today', () => {
it('should convert "today" to the current weekday name', () => {
const params = new URLSearchParams('weekday=today');
const result = validateInput(params, defaults);

const weekdays = ['sunday', 'monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday'];
const expectedDay = weekdays[new Date().getDay()];

expect(result.weekday).toEqual([expectedDay]);
});

it('should handle "today" mixed with other days', () => {
const params = new URLSearchParams('weekday=today/friday');
const result = validateInput(params, defaults);

const weekdays = ['sunday', 'monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday'];
const expectedDay = weekdays[new Date().getDay()];

expect(result.weekday).toContain(expectedDay);
expect(result.weekday).toContain('friday');
});
});