Skip to content

Commit

Permalink
Make sure the loader has the colors and preven CLS
Browse files Browse the repository at this point in the history
  • Loading branch information
Jean-Philippe Green committed Apr 22, 2024
1 parent 92b45ce commit ff7dcae
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 45 deletions.
8 changes: 0 additions & 8 deletions packages/app/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,11 @@ import { WCJ } from './types';
import { canStoreSelection } from './services/cookies';

type Props = WCJ.Context & {
colors: Record<string, string>;
parent: HTMLElement;
isLoading: boolean;
};

export function App(props: Props) {
useEffect(() => {
for (const color in props.colors) {
const colorVal = props.colors[color];
props.parent.style.setProperty(`--cw-color-${color}`, colorVal);
}
}, [props.colors, props.parent]);

const [eventModal, setEventModal] = useState<string>();
const [checkedEvents, setCheckedEvents] = useCheckedEvents(
props.events.map((x) => x.id),
Expand Down
17 changes: 11 additions & 6 deletions packages/app/src/AppInit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { Loader } from './shared/Loader';
import { CW } from './types';
import { MaybeArray } from './types/utils';
import { WpCwfc } from '@cwfc/shared';
import { useState } from 'react';
import { useEffect, useState } from 'react';
import useSwr from 'swr';

type Props = WpCwfc;
Expand All @@ -22,15 +22,19 @@ export default function AppInit(props: Props) {
}

function AppContent(props: Props & { rootRef: HTMLElement | null }) {
useEffect(() => {
for (const color in props.colors) {
const colorVal = props.colors[color];
props.rootRef?.style.setProperty(`--cw-color-${color}`, colorVal);
}
}, [props.colors, props.rootRef]);

const formData = new FormData();
formData.append('action', 'cwfc_fetch');
formData.append('org', props.org);
formData.append('pw_hash', props.pwHash);

const { isLoading, error, data, isValidating } = useSwr<
MaybeArray<CW.Event>,
string
>(
const swrResponse = useSwr<MaybeArray<CW.Event>, string>(
'cwfc_fetch',
async () => {
const res = await fetch(props.ajaxUrl, {
Expand All @@ -49,6 +53,8 @@ function AppContent(props: Props & { rootRef: HTMLElement | null }) {
},
);

const { isLoading, error, data, isValidating } = swrResponse;

if (isLoading) {
return <Loader />;
} else if (error && !data) {
Expand All @@ -63,7 +69,6 @@ function AppContent(props: Props & { rootRef: HTMLElement | null }) {
events={events}
categories={categories}
selectedEventIds={selectedEventIds}
colors={props.colors}
parent={props.rootRef}
isLoading={isValidating}
/>
Expand Down
2 changes: 1 addition & 1 deletion packages/wordpress/src/cw-filter-calendar.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* Plugin URI: https://github.com/WestCoastJitterbugsOrg/Interactive-CogWork-Calendar
* Plugin Name: Interactive Calendar for CogWork data
* Description: Calendar using data from cogwork that allows filtering, reading event information and registration
* Version: 2.2.0
* Version: 2.3.1
* Requires at least: 5.0
* Requires PHP: 7.3
* Author: Jean-Philippe Green
Expand Down
31 changes: 1 addition & 30 deletions packages/wordpress/src/view.scss
Original file line number Diff line number Diff line change
Expand Up @@ -3,40 +3,11 @@
.wp-block-cw-addons-cw-filter-calendar {
font-family: Raleway, ui-sans-serif, system-ui;
font-size: 16px;
min-height: calc(100vh - 128px);

* {
box-sizing: border-box;
}

.loader-container {
display: flex;
height: calc(100vh - 128px);
background: #fff;
}

.loader {
width: 100%;
height: 100%;
background: linear-gradient(0.25turn, transparent, #fff, transparent),
linear-gradient(#ddd, #ddd);
background-repeat: no-repeat;
background-position:
min(-100vw, 1200px) 0,
0 0,
15px 140px,
65px 145px;
animation: loading 1.5s infinite;
}

@keyframes loading {
to {
background-position:
max(-100vw, 1200px) 0,
0 0,
15px 140px,
65px 145px;
}
}
}

.cwfc-modal-open {
Expand Down

0 comments on commit ff7dcae

Please sign in to comment.