A platform for community discussion. Free, open, simple.
UX: add placeholders for even category calendars (#44539)
Krisb43a076bedee
diff --git a/plugins/discourse-events/assets/javascripts/discourse/components/calendar-placeholder.gjs b/plugins/discourse-events/assets/javascripts/discourse/components/calendar-placeholder.gjsnew file mode 100644index 00000000000..69013cd8864--- /dev/null+++ b/plugins/discourse-events/assets/javascripts/discourse/components/calendar-placeholder.gjs@@ -0,0 +1,207 @@+import Component from "@glimmer/component";+import { trustHTML } from "@ember/template";+import DSkeleton from "discourse/ui-kit/d-skeleton";++const MONTH_WEEKS = 6;+const TIME_GRID_SLOTS = 10;+const LIST_GROUPS = [2, 1, 3, 2, 1, 2];++// Fixed rather than random so the placeholder doesn't reshuffle on rerender.+const MONTH_EVENT_PATTERN = [0, 1, 0, 0, 2, 0, 1, 0, 0, 1, 0, 0, 0, 2];+const TIME_GRID_EVENTS = [+ { column: 0, top: 10, height: 15 },+ { column: 0, top: 50, height: 20 },+ { column: 1, top: 35, height: 20 },+ { column: 2, top: 20, height: 10 },+ { column: 3, top: 55, height: 25 },+ { column: 4, top: 15, height: 20 },+ { column: 5, top: 45, height: 10 },+ { column: 6, top: 30, height: 15 },+];++function positionStyle({ top, height }) {+ return trustHTML(`top: ${top}%; height: ${height}%`);+}++export default class CalendarPlaceholder extends Component {+ get columnCount() {+ if (this.args.view === "timeGridDay") {+ return 1;+ }+ return this.args.weekends === false ? 5 : 7;+ }++ get viewType() {+ switch (this.args.view) {+ case "timeGridDay":+ case "timeGridWeek":+ return "time-grid";+ case "listYear":+ return "list";+ default:+ return "month";+ }+ }++ get isMonth() {+ return this.viewType === "month";+ }++ get isTimeGrid() {+ return this.viewType === "time-grid";+ }++ get isList() {+ return this.viewType === "list";+ }++ get style() {+ const declarations = [+ `--calendar-placeholder-columns: ${this.columnCount}`,+ ];+ const { height } = this.args;++ if (height && CSS.supports("height", height)) {+ declarations.push(`height: ${height}`);+ }++ return trustHTML(declarations.join("; "));+ }++ get columns() {+ return Array.from({ length: this.columnCount }, (_, index) => index);+ }++ get monthCells() {+ return Array.from(+ { length: MONTH_WEEKS * this.columnCount },+ (_, index) => ({+ events: Array.from({+ length: MONTH_EVENT_PATTERN[index % MONTH_EVENT_PATTERN.length],+ }),+ })+ );+ }++ get timeSlots() {+ return Array.from({ length: TIME_GRID_SLOTS }, (_, index) => index);+ }++ get timeGridColumns() {+ return this.columns.map((column) => ({+ events: TIME_GRID_EVENTS.filter((event) => event.column === column).map(+ positionStyle+ ),+ }));+ }++ get listGroups() {+ return LIST_GROUPS.map((count) => Array.from({ length: count }));+ }++ <template>+ <div+ aria-hidden="true"+ class="calendar-placeholder --{{this.viewType}}"+ style={{this.style}}+ >+ <div class="calendar-placeholder__toolbar">+ <div class="calendar-placeholder__toolbar-chunk">+ <DSkeleton+ class="calendar-placeholder__button"+ @variant="rect"+ @width="5.2em"+ />+ <DSkeleton+ class="calendar-placeholder__button --today"+ @variant="rect"+ @width="4.3em"+ />+ </div>+ <div class="calendar-placeholder__title">+ <DSkeleton @width="7em" />+ </div>+ <div class="calendar-placeholder__toolbar-chunk">+ <DSkeleton+ class="calendar-placeholder__button"+ @variant="rect"+ @width="15em"+ />+ </div>+ </div>++ {{#if this.isMonth}}+ <div class="calendar-placeholder__grid">+ {{#each this.columns}}+ <div class="calendar-placeholder__header-cell">+ <DSkeleton @width="2em" />+ </div>+ {{/each}}+ {{#each this.monthCells as |cell|}}+ <div class="calendar-placeholder__day">+ <DSkeleton+ class="calendar-placeholder__day-number"+ @width="1.25em"+ />+ {{#each cell.events}}+ <DSkeleton+ class="calendar-placeholder__event"+ @height="1.25em"+ @variant="rect"+ />+ {{/each}}+ </div>+ {{/each}}+ </div>+ {{else if this.isTimeGrid}}+ <div class="calendar-placeholder__time-grid">+ <div class="calendar-placeholder__header-row">+ <div class="calendar-placeholder__gutter"></div>+ {{#each this.columns}}+ <div class="calendar-placeholder__header-cell">+ <DSkeleton @width="4em" />+ </div>+ {{/each}}+ </div>+ <div class="calendar-placeholder__body">+ <div class="calendar-placeholder__gutter">+ {{#each this.timeSlots}}+ <div class="calendar-placeholder__slot-label">+ <DSkeleton @width="2.5em" />+ </div>+ {{/each}}+ </div>+ {{#each this.timeGridColumns as |column|}}+ <div class="calendar-placeholder__column">+ {{#each column.events as |style|}}+ <div+ class="calendar-placeholder__timed-event"+ style={{style}}+ >+ <DSkeleton @height="100%" @variant="rect" @width="100%" />+ </div>+ {{/each}}+ </div>+ {{/each}}+ </div>+ </div>+ {{else}}+ <div class="calendar-placeholder__list">+ {{#each this.listGroups as |rows|}}+ <div class="calendar-placeholder__list-heading">+ <DSkeleton @width="8em" />+ <DSkeleton @width="5em" />+ </div>+ {{#each rows}}+ <div class="calendar-placeholder__list-row">+ <DSkeleton @width="6em" />+ <DSkeleton @size="0.6em" @variant="circle" />+ <DSkeleton @width="40%" />+ </div>+ {{/each}}+ {{/each}}+ </div>+ {{/if}}+ </div>+ </template>+}diff --git a/plugins/discourse-events/assets/javascripts/discourse/components/category-calendar.gjs b/plugins/discourse-events/assets/javascripts/discourse/components/category-calendar.gjsindex 866db58bc4f..2d1eb34ce0a 100644--- a/plugins/discourse-events/assets/javascripts/discourse/components/category-calendar.gjs+++ b/plugins/discourse-events/assets/javascripts/discourse/components/category-calendar.gjs@@ -176,6 +176,7 @@ export default class CategoryCalendar extends Component {@initialView={{this.categorySetting.defaultView}}@onDateClick={{if this.canCreateEvent this.onDateClick}}@onLoadEvents={{this.loadEvents}}+ @placeholder={{true}}@refreshKey={{this.refreshKey}}@weekends={{this.renderWeekends}}/>diff --git a/plugins/discourse-events/assets/javascripts/discourse/components/full-calendar.gjs b/plugins/discourse-events/assets/javascripts/discourse/components/full-calendar.gjsindex 9c9275620f2..c79c5cb0af3 100644--- a/plugins/discourse-events/assets/javascripts/discourse/components/full-calendar.gjs+++ b/plugins/discourse-events/assets/javascripts/discourse/components/full-calendar.gjs@@ -1,4 +1,5 @@import Component from "@glimmer/component";+import { tracked } from "@glimmer/tracking";import { inject as controller } from "@ember/controller";import { action } from "@ember/object";import didInsert from "@ember/render-modifiers/modifiers/did-insert";@@ -17,6 +18,7 @@ import {getCurrentBcp47Locale,} from "../lib/calendar-locale";import { normalizeViewForCalendar } from "../lib/calendar-view-helper";+import CalendarPlaceholder from "./calendar-placeholder";const PostEventMenu = <template><DiscoursePostEvent@@ -38,6 +40,8 @@ export default class FullCalendar extends Component {@controller topic;+ @tracked isRendered = false;+calendar = null;// TODO: remove this workaround when updating to fullcalendar v7@@ -86,6 +90,10 @@ export default class FullCalendar extends Component {};}+ get showPlaceholder() {+ return this.args.placeholder && !this.isRendered;+ }+get initialView() {const normalizedView = normalizeViewForCalendar(this.args.initialView);@@ -206,6 +214,7 @@ export default class FullCalendar extends Component {});this.calendar.render();+ this.isRendered = true;}@action@@ -217,7 +226,15 @@ export default class FullCalendar extends Component {}<template>+ {{#if this.showPlaceholder}}+ <CalendarPlaceholder+ @height={{@height}}+ @view={{this.initialView}}+ @weekends={{@weekends}}+ />+ {{/if}}<div+ aria-busy={{if this.showPlaceholder "true"}}...attributes{{didInsert this.setupCalendar}}{{didUpdatediff --git a/plugins/discourse-events/assets/stylesheets/common/calendar-placeholder.scss b/plugins/discourse-events/assets/stylesheets/common/calendar-placeholder.scssnew file mode 100644index 00000000000..31c89b0100c--- /dev/null+++ b/plugins/discourse-events/assets/stylesheets/common/calendar-placeholder.scss@@ -0,0 +1,171 @@+@use "lib/viewport";++.calendar-placeholder {+ --calendar-placeholder-gutter: 4em;+ display: flex;+ flex-direction: column;+ gap: 1.5em;+ box-sizing: border-box;+ min-height: 20em;+ padding-bottom: 5px;+ overflow: hidden;++ &__toolbar {+ display: flex;+ justify-content: space-between;+ align-items: center;+ gap: 0.5rem;+ font-size: var(--font-0);++ @include viewport.from(md) {+ font-size: var(--font-down-1);+ }+ }++ &__toolbar-chunk {+ display: flex;+ gap: 0.75em;+ }++ &__button {+ --d-skeleton-item-height: calc(2.3em + 2px);++ &.--today {+ @include viewport.until(md) {+ display: none;+ }+ }+ }++ &__title {+ line-height: 1.4;+ }++ // the real title is an h2, which picks up this spacing inside the topic list+ #list-area &__title {+ margin: var(--space-5) 0 var(--space-3);+ }++ &__grid,+ &__time-grid,+ &__list {+ flex: 1;+ min-height: 0;+ border: 1px solid var(--fc-border-color);+ }++ &__header-cell {+ display: flex;+ justify-content: center;+ padding: 0.2rem 4px;+ font-size: var(--font-down-2);+ }++ // month+ &__grid {+ display: grid;+ grid-template-columns: repeat(var(--calendar-placeholder-columns), 1fr);+ grid-template-rows: auto repeat(6, minmax(0, 1fr));+ border-width: 1px 0 0 1px;++ .calendar-placeholder__header-cell,+ .calendar-placeholder__day {+ border-right: 1px solid var(--fc-border-color);+ border-bottom: 1px solid var(--fc-border-color);+ }+ }++ &__day {+ display: flex;+ flex-direction: column;+ gap: 0.25em;+ min-height: 0;+ padding: 0.25em;+ overflow: hidden;+ }++ &__day-number {+ align-self: center;+ }++ // week and day+ &__time-grid {+ display: flex;+ flex-direction: column;+ }++ &__header-row,+ &__body {+ display: grid;+ grid-template-columns:+ var(--calendar-placeholder-gutter)+ repeat(var(--calendar-placeholder-columns), 1fr);+ }++ &__header-row {+ border-bottom: 1px solid var(--fc-border-color);+ }++ &__body {+ flex: 1;+ min-height: 0;++ // one line per slot, matching the slot labels' 10% height+ background: linear-gradient(+ to bottom,+ transparent calc(100% - 1px),+ var(--fc-border-color) 0+ )+ 0 0 / 100% 10%;+ }++ &__header-row .calendar-placeholder__header-cell,+ &__column {+ border-left: 1px solid var(--fc-border-color);+ }++ &__slot-label {+ display: flex;+ justify-content: flex-end;+ height: 10%;+ padding: 0.25em;+ box-sizing: border-box;+ }++ &__column {+ position: relative;+ }++ &__timed-event {+ position: absolute;+ inset-inline: 2px;++ .d-skeleton {+ height: 100%;+ }+ }++ &__list {+ display: flex;+ flex-direction: column;+ }++ &__list-heading {+ --d-skeleton-fill: var(--primary-low);+ --d-skeleton-shimmer: var(--primary-low-mid);+ display: flex;+ justify-content: space-between;+ padding: 0.5em 0.75em;+ background: var(--primary-very-low);+ border-bottom: 1px solid var(--fc-border-color);+ }++ &__list-row {+ display: grid;+ grid-template-columns: 8em auto 1fr;+ align-items: center;+ gap: 0.75em;+ padding: 0.6em 0.75em;+ border-bottom: 1px solid var(--fc-border-color);+ }+}diff --git a/plugins/discourse-events/plugin.rb b/plugins/discourse-events/plugin.rbindex 759f010ebc7..eb03b53e146 100644--- a/plugins/discourse-events/plugin.rb+++ b/plugins/discourse-events/plugin.rb@@ -20,6 +20,7 @@ enabled_site_setting :discourse_events_enabledregister_svg_icon "calendar-days"register_asset "stylesheets/common/event-calendar-prompt.scss"register_asset "stylesheets/common/full-calendar-ext.scss"+register_asset "stylesheets/common/calendar-placeholder.scss"register_asset "stylesheets/common/discourse-calendar.scss"register_asset "stylesheets/common/discourse-calendar-holidays.scss"register_asset "stylesheets/common/discourse-post-event.scss"diff --git a/plugins/discourse-events/test/javascripts/integration/components/calendar-placeholder-test.gjs b/plugins/discourse-events/test/javascripts/integration/components/calendar-placeholder-test.gjsnew file mode 100644index 00000000000..4f7d89deb82--- /dev/null+++ b/plugins/discourse-events/test/javascripts/integration/components/calendar-placeholder-test.gjs@@ -0,0 +1,63 @@+import { render } from "@ember/test-helpers";+import { module, test } from "qunit";+import { setupRenderingTest } from "discourse/tests/helpers/component-test";+import CalendarPlaceholder from "discourse/plugins/discourse-events/discourse/components/calendar-placeholder";++module("Integration | Component | CalendarPlaceholder", function (hooks) {+ setupRenderingTest(hooks);++ test("month view renders six weeks of day cells", async function (assert) {+ await render(+ <template><CalendarPlaceholder @view="dayGridMonth" /></template>+ );++ assert.dom(".calendar-placeholder.--month").exists();+ assert.dom(".calendar-placeholder__day").exists({ count: 42 });+ });++ test("month view drops weekend columns when weekends are hidden", async function (assert) {+ await render(+ <template>+ <CalendarPlaceholder @view="dayGridMonth" @weekends={{false}} />+ </template>+ );++ assert.dom(".calendar-placeholder__day").exists({ count: 30 });+ });++ test("week view renders a time grid with a column per day", async function (assert) {+ await render(+ <template><CalendarPlaceholder @view="timeGridWeek" /></template>+ );++ assert.dom(".calendar-placeholder.--time-grid").exists();+ assert.dom(".calendar-placeholder__column").exists({ count: 7 });+ });++ test("day view renders a single time grid column", async function (assert) {+ await render(+ <template><CalendarPlaceholder @view="timeGridDay" /></template>+ );++ assert.dom(".calendar-placeholder__column").exists({ count: 1 });+ });++ test("list view renders list rows", async function (assert) {+ await render(<template><CalendarPlaceholder @view="listYear" /></template>);++ assert.dom(".calendar-placeholder.--list").exists();+ assert.dom(".calendar-placeholder__list-row").exists();+ });++ test("applies a valid height and ignores an invalid one", async function (assert) {+ await render(<template><CalendarPlaceholder @height="650px" /></template>);+ assert.dom(".calendar-placeholder").hasStyle({ height: "650px" });++ await render(+ <template><CalendarPlaceholder @height="650px; color: red" /></template>+ );+ assert+ .dom(".calendar-placeholder")+ .hasAttribute("style", "--calendar-placeholder-columns: 7");+ });+});