Skip to content

Commit

Permalink
Update table component's skeleton look
Browse files Browse the repository at this point in the history
Not only does it now resemble the other skeleton components, but it now
also actually works
  • Loading branch information
ivarnakken committed Feb 10, 2024
1 parent 1602d93 commit 59df0ce
Show file tree
Hide file tree
Showing 8 changed files with 55 additions and 45 deletions.
18 changes: 17 additions & 1 deletion app/components/Table/Table.css
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,22 @@

.wrapper tr:nth-child(even) {
background-color: rgba(var(--rgb-min), var(--rgb-min), var(--rgb-min), 3%);

& .loader {
animation: skeleton-loading 1s linear infinite alternate;
}
}

@keyframes skeleton-loading {
0% {
background-color: var(--color-gray-1);
}
50% {
background-color: var(--color-gray-2);
}
100% {
background-color: var(--color-gray-3);
}
}

.checkbox {
Expand All @@ -35,7 +51,7 @@
}

.loader {
border-bottom: none;
height: 40.797px;
}

.overlay {
Expand Down
22 changes: 13 additions & 9 deletions app/components/Table/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { LoadingIndicator } from '@webkom/lego-bricks';
import cx from 'classnames';
import { debounce, isEmpty, get } from 'lodash';
import { useEffect, useMemo, useState } from 'react';
Expand Down Expand Up @@ -176,12 +175,14 @@ const Table: React.FC<TableProps> = ({
}
};

const visibleColumns = columns.filter(isVisible);

return (
<div className={cx(styles.wrapper, className)}>
<table>
<thead>
<tr>
{columns.filter(isVisible).map((column, index) => (
{visibleColumns.map((column, index) => (
<HeadCell
key={column.dataIndex + column.title}
column={column}
Expand Down Expand Up @@ -217,13 +218,16 @@ const Table: React.FC<TableProps> = ({
))}
</tr>
))}
{loading && (
<tr>
<td className={styles.loader} colSpan={columns.length}>
<LoadingIndicator loading={loading} />
</td>
</tr>
)}
{loading &&
Array.from({ length: 10 }).map((_, index) => (
<tr key={index}>
{Array.from({ length: visibleColumns.length }).map(
(_, index) => (
<td key={index} className={styles.loader} />
)
)}
</tr>
))}
</InfiniteScroll>
</table>
</div>
Expand Down
20 changes: 9 additions & 11 deletions app/routes/admin/groups/components/GroupMembersList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -171,17 +171,15 @@ const GroupMembersList = ({
].filter(Boolean);

return (
<>
<Table
onChange={setQuery}
columns={columns}
hasMore={hasMore}
loading={fetching}
data={memberships}
filters={query}
className={styles.list}
/>
</>
<Table
onChange={setQuery}
columns={columns}
hasMore={hasMore}
loading={fetching}
data={memberships}
filters={query}
className={styles.list}
/>
);
};

Expand Down
2 changes: 1 addition & 1 deletion app/routes/events/components/EventAdministrate/Abacard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ const Abacard = () => {
<div>
<Validator handleSelect={handleSelect} validateAbakusGroup={false} />
<div className={styles.counter}>
{registerCount}/{event.registrationCount} har møtt opp
{registerCount}/{event.registrationCount || '?'} har møtt opp
</div>
</div>
);
Expand Down
3 changes: 2 additions & 1 deletion app/routes/events/components/EventAdministrate/Allergies.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Button, Flex, Icon, LoadingIndicator } from '@webkom/lego-bricks';
import { usePreparedEffect } from '@webkom/react-prepare';
import { isEmpty } from 'lodash';
import { Link, useParams } from 'react-router-dom';
import { fetchAllergies } from 'app/actions/EventActions';
import Table from 'app/components/Table';
Expand All @@ -16,7 +17,7 @@ export const canSeeAllergies = (
currentUser?: CurrentUser,
event?: AdministrateEvent
) => {
if (!currentUser || !event) {
if (!currentUser || !event || isEmpty(event)) {
return false;
}
return (
Expand Down
16 changes: 6 additions & 10 deletions app/routes/events/components/EventAdministrate/Attendees.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,6 @@ const Attendees = () => {
unreg.paymentStatus === 'succeeded' || unreg.paymentStatus === 'manual'
).length;

if (loading || !event) {
return <LoadingIndicator loading={loading} />;
}

// Not showing the presence column until 1 day before start or if someone has been given set to presence
const showPresence =
moment().isAfter(moment(event.startTime).subtract(1, 'day')) ||
Expand Down Expand Up @@ -129,14 +125,14 @@ const Attendees = () => {
</Flex>
<Flex column>
<div>
<strong>Påmeldte:</strong>
<strong>Påmeldte</strong>
<div className={styles.attendeeStatistics}>
{`${registerCount}/${event.registrationCount} ${
{`${registerCount}/${event.registrationCount || '?'} ${
eventHasEnded ? 'møtte opp' : 'har møtt opp'
}`}
</div>
<div className={styles.attendeeStatistics}>
{`${adminRegisterCount}/${event.registrationCount} ${
{`${adminRegisterCount}/${event.registrationCount || '?'} ${
eventHasEnded ? 'ble' : 'er'
} adminpåmeldt`}
</div>
Expand All @@ -155,7 +151,7 @@ const Attendees = () => {
: ''}
</div>
</div>
{registered.length === 0 ? (
{registered.length === 0 && !loading ? (
<span className="secondaryFontColor">Ingen påmeldte</span>
) : (
<RegisteredTable
Expand All @@ -172,9 +168,9 @@ const Attendees = () => {
marginTop: '10px',
}}
>
Avmeldte:
Avmeldte
</strong>
{unregistered.length === 0 ? (
{unregistered.length === 0 && !loading ? (
<span className="secondaryFontColor">Ingen avmeldte</span>
) : (
<UnregisteredTable
Expand Down
9 changes: 1 addition & 8 deletions app/routes/events/components/EventAdministrate/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,6 @@ const EventAdministrateIndex = () => {

const base = `/events/${eventId}/administrate`;

if (!event) {
return (
<Content>
<LoadingIndicator loading={fetching} />
</Content>
);
}

return (
<Content>
<NavigationTab
Expand All @@ -49,6 +41,7 @@ const EventAdministrateIndex = () => {
label: 'Tilbake',
path: '/events/' + event.slug,
}}
skeleton={fetching}
>
<NavigationLink to={`${base}/attendees`}>Påmeldinger</NavigationLink>
{event && canSeeAllergies(currentUser, event) && (
Expand Down
10 changes: 6 additions & 4 deletions app/routes/users/components/UserSettingsOAuth2.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -196,8 +196,8 @@ const UserSettingsOAuth2 = () => {
<Link to="/users/me/settings/oauth2/new">Ny applikasjon</Link>
</Button>
)}
{applications.length === 0 ? (
<span>Du har ingen applikasjoner</span>
{applications.length === 0 && !fetchingApplications ? (
<span className="secondaryFontColor">Du har ingen applikasjoner</span>
) : (
<Table
columns={applicationColumns}
Expand All @@ -209,8 +209,10 @@ const UserSettingsOAuth2 = () => {
</Flex>

<h3>Aksepterte applikasjoner</h3>
{grants.length === 0 ? (
<span>Du har ikke logget på en app enda.</span>
{grants.length === 0 && !fetchingGrants ? (
<span className="secondaryFontColor">
Du har ikke logget på en app enda
</span>
) : (
<Table
columns={acceptedApplicationcolumns}
Expand Down

0 comments on commit 59df0ce

Please sign in to comment.