Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Redesign calendar frontend #159

Merged
merged 20 commits into from
Oct 14, 2024
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
30 changes: 30 additions & 0 deletions .github/workflows/lint-frontend.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: Static Analysis (Linting)

# This workflow is triggered on pushes to trunk, and any PRs.
on:
push:
branches: [master]
pull_request:
workflow_dispatch:

jobs:
check:
name: Lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Install NodeJS
uses: actions/setup-node@v4
with:
node-version-file: '.nvmrc'
cache: 'npm'

- name: npm install and build
run: |
npm ci
npm run build

- name: Lint Styles
run: |
npm run lint:css
29 changes: 28 additions & 1 deletion package-lock.json

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

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
"homepage": "https://github.com/Automattic/meeting-calendar#readme",
"devDependencies": {
"@wordpress/env": "9.7.0",
"@wordpress/scripts": "27.9.0"
"@wordpress/scripts": "27.9.0",
"@wordpress/stylelint-config": "21.34.0"
}
}
2 changes: 1 addition & 1 deletion plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ function register_assets() {

wp_register_style(
'wporg-calendar-style',
plugin_dir_url( __FILE__ ) . 'build/calendar.css',
plugin_dir_url( __FILE__ ) . 'build/style-calendar.css',
array( 'wp-components' ),
$frontend_info['version']
);
Expand Down
94 changes: 45 additions & 49 deletions src/frontend/calendar/cell.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,119 +10,115 @@ import { format } from '@wordpress/date';
*/
import { getTeamClass, isToday, isCancelled } from './utils';

function CalendarCell( {
function CalendarCell({
blank = false,
year,
month,
day,
events,
onEventClick,
} ) {
}) {
const MAX_EVENTS = 7;
if ( blank ) {
if (blank) {
return <td className="wporg-meeting-calendar__cell" aria-hidden />;
}

const date = new Date( year, month, day );
const key = format( 'Y-m-d', date );
const dayEvents = events[ key ] || [];
const restOfEvents = dayEvents.slice( MAX_EVENTS );
const date = new Date(year, month, day);
const key = format('Y-m-d', date);
const dayEvents = events[key] || [];
const restOfEvents = dayEvents.slice(MAX_EVENTS);

return (
<td
className={ `wporg-meeting-calendar__cell ${
isToday( date ) ? 'is-today' : ''
}` }
className={`wporg-meeting-calendar__cell ${
isToday(date) ? 'is-today' : ''
}`}
>
<strong>
<span className="screen-reader-text">
{ format( 'F j', date ) }{ ' ' }
{ // translators: %d: Count of all events, ie: 4.
sprintf(
{format('F j', date)}{' '}
{sprintf(
// translators: %d: Count of all events, ie: 4.
Copy link
Collaborator Author

@adamwoodnz adamwoodnz Oct 10, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

eslint caught these problems with comments not being adjacent to translations

_n(
'%d event',
'%d events',
dayEvents.length,
'wporg'
'wporg-meeting-calendar'
),
dayEvents.length
) }
)}
</span>
<span aria-hidden>{ day }</span>
<span aria-hidden>{day}</span>
</strong>
{ dayEvents.slice( 0, MAX_EVENTS ).map( ( event ) => {
{dayEvents.slice(0, MAX_EVENTS).map((event) => {
return (
<Button
key={ event.instance_id }
key={event.instance_id}
isLink
onClick={ () => void onEventClick( event ) }
onClick={() => void onEventClick(event)}
className={
'wporg-meeting-calendar__cell-event ' +
getTeamClass( event.team ) +
( isCancelled( event.status )
? ' is-cancelled'
: '' )
getTeamClass(event.team) +
(isCancelled(event.status) ? ' is-cancelled' : '')
}
>
<div className="wporg-meeting-calendar__cell-event-time">
{ format( 'g:i a: ', event.datetime ) }
{format('g:i a ', event.datetime)}
</div>
<div className="wporg-meeting-calendar__cell-event-title">
{ event.title }
{event.title}
</div>
</Button>
);
} ) }
})}

{ !! restOfEvents.length && (
{!!restOfEvents.length && (
<Dropdown
className="wporg-meeting-calendar__dropdown"
position="bottom center"
renderToggle={ ( { isOpen, onToggle } ) => (
renderToggle={({ isOpen, onToggle }) => (
<Button
isLink
onClick={ onToggle }
aria-expanded={ isOpen }
onClick={onToggle}
aria-expanded={isOpen}
>
{ // translators: %d: Count of hidden events, ie: 4.
sprintf(
{sprintf(
// translators: %d: Count of hidden events, ie: 4.
_n(
'%d more',
'%d more',
restOfEvents.length,
'wporg'
'wporg-meeting-calendar'
),
restOfEvents.length
) }
)}
</Button>
) }
renderContent={ () => (
)}
renderContent={() => (
<MenuGroup>
{ restOfEvents.map( ( event ) => {
{restOfEvents.map((event) => {
return (
<MenuItem
key={ event.instance_id }
key={event.instance_id}
isLink
onClick={ () =>
void onEventClick( event )
}
onClick={() => void onEventClick(event)}
className={
'wporg-meeting-calendar__cell-event ' +
getTeamClass( event.team ) +
( isCancelled( event.status )
getTeamClass(event.team) +
(isCancelled(event.status)
? ' is-cancelled'
: '' )
: '')
}
>
{ format( 'g:i a: ', event.datetime ) }
{ event.title }
{format('g:i a: ', event.datetime)}
{event.title}
</MenuItem>
);
} ) }
})}
</MenuGroup>
) }
)}
/>
) }
)}
</td>
);
}
Expand Down
Loading