Skip to content

Commit

Permalink
More skeleton loading work but will stop until working on plane
Browse files Browse the repository at this point in the history
  • Loading branch information
AnselmMarie committed Sep 29, 2024
1 parent 610bdf0 commit bccd534
Show file tree
Hide file tree
Showing 13 changed files with 67 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ import { PokemonListApi } from '@pokemon-pet-shop/typing';

export interface CardProps {
data: PokemonListApi;
isLoading: boolean;
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,25 @@ import { CardProps } from './pokemon.card.interface';
import { styles } from './pokemon.card.module';
import usePokemonCardLogic from './use.pokemon.card.logic';

const PokemonCard = ({ data }: CardProps): ReactElement => {
const PokemonCard = ({ data, isLoading }: CardProps): ReactElement => {
const { getThemeClass, onHandleOpenDetailModalClick } = usePokemonCardLogic(data);

const capitalizeName = useMemo((): string => {
return capitalizeNameUtil(data?.name);
}, [data?.name]);

return (
<UiCard className={classNamesUtil(styles.cardWrapper, styles?.[`${getThemeClass}Wrapper`])}>
<UiCard
className={classNamesUtil(styles.cardWrapper, styles?.[`${getThemeClass}Wrapper`])}
isLoading={isLoading}
>
<UiElementLayout className={styles.imgCardWrapper}>
<UiImage
src={data?.sprites?.other?.['official-artwork']?.front_default}
className={styles.image}
alt={`${data?.name} Image`}
mobSrcType={mobSrcTypeEnum.URI}
isLoading={isLoading}
/>
</UiElementLayout>

Expand Down
16 changes: 7 additions & 9 deletions libs/features/src/lib/pokemon/pokemon.list/pokemon.list.view.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,12 @@ const PokemonList = (): ReactElement => {
onFetchNextPage,
} = usePokemonList();

console.log('data', data);
const newData = useMemo(() => {
const template = { abilities: [{}, {}] };
return skeletonLoadDataUtil(data, isLoading, template, true);
}, [data, isLoading]);

// const newData = useMemo(() => {
// const template = { abilities: [{}, {}] };
// return skeletonLoadDataUtil(data, isLoading, template, true);
// }, [data, isLoading]);

if (data?.length === 0 && !hasNextPage) {
if (newData?.length === 0 && !hasNextPage) {
return (
<UiElementLayout className={styles.failureWrapper}>
<UiTypography>No Pets are available at the moment. Please check back again.</UiTypography>
Expand All @@ -39,11 +37,11 @@ const PokemonList = (): ReactElement => {
return (
<>
<UiElementLayout className={styles.cardListWrapper}>
{(data || []).map((arr: PokemonListApi[], i: number): ReactElement => {
{(newData || []).map((arr: PokemonListApi[], i: number): ReactElement => {
return (
<Fragment key={i}>
{arr.map((el: PokemonListApi, i: number) => (
<UiPokemonCard key={el?.name || i} data={el} />
<UiPokemonCard key={el?.name || i} data={el} isLoading={isLoading} />
))}
</Fragment>
);
Expand Down
1 change: 1 addition & 0 deletions libs/ui/src/lib-base/styles/css/global.css
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
@import url('reset.css');
@import url('_variables.css');
@import url('react-loading-skeleton/dist/skeleton.css');

html[data-theme='dark'] {
--theme-netural-100: var(--theme-netural-100-dark);
Expand Down
1 change: 1 addition & 0 deletions libs/ui/src/lib-base/ui/card/card.interface.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export interface CardProps {
className?: any;
isLoading?: boolean;
}
5 changes: 5 additions & 0 deletions libs/ui/src/lib-base/ui/card/card.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,8 @@
background: var(--theme-netural-100);
border-radius: var(--theme-radius-8);
}

.cardLoading {
background: var(--theme-netural-400);
border-radius: var(--theme-radius-8);
}
9 changes: 7 additions & 2 deletions libs/ui/src/lib-base/ui/card/card.view.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,14 @@ import { UiElementLayout } from '../element.layout';
import { CardProps } from './card.interface';
import { styles } from './card.module';

const Card = ({ className = '', children = null }: PropsWithChildren<CardProps>): ReactElement => {
const Card = ({
className = '',
isLoading = false,
children = null,
}: PropsWithChildren<CardProps>): ReactElement => {
const cardStyle = isLoading ? styles.cardLoading : styles.card;
return (
<UiElementLayout className={classNamesUtil(className, styles.card)}>{children}</UiElementLayout>
<UiElementLayout className={classNamesUtil(className, cardStyle)}>{children}</UiElementLayout>
);
};

Expand Down
1 change: 1 addition & 0 deletions libs/ui/src/lib-base/ui/image/image.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@ export interface ImageProps {
alt?: string;
width?: string;
className?: any;
isLoading?: boolean;
mobSrcType?: mobSrcTypeEnum;
}
13 changes: 12 additions & 1 deletion libs/ui/src/lib-base/ui/image/image.view.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,19 @@
import { ReactElement } from 'react';

import { UiSkeleton } from '../skeleton';

import { ImageProps } from './image.interface';

const Image = ({ src = '', alt = '', width = '', className = null }: ImageProps): ReactElement => {
const Image = ({
src = '',
alt = '',
width = '',
className = null,
isLoading,
}: ImageProps): ReactElement => {
if (isLoading) {
return <UiSkeleton circle />;
}
return <img src={src} alt={alt} width={width} className={className} />;
};

Expand Down
4 changes: 2 additions & 2 deletions libs/ui/src/lib-base/ui/skeleton/skeleton.view.native.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { UiElementLayout } from '../element.layout';
import { styles } from './shkeleon.module.native';
import { SkeletonProps } from './skeleton.interface';

const Skeleton = ({
const SkeletonView = ({
count = 1,
width = '100%',
height = 15,
Expand Down Expand Up @@ -48,4 +48,4 @@ const Skeleton = ({
);
};

export default Skeleton;
export default SkeletonView;
19 changes: 14 additions & 5 deletions libs/ui/src/lib-base/ui/skeleton/skeleton.view.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
import { ReactElement } from 'react';

import Skeleton from 'react-loading-skeleton';

import { THEME_RADIUS_8, THEME_RADIUS_CIRCLE } from '../../styles/ts/variables';
import { UiElementLayout } from '../element.layout';

import { SkeletonProps } from './skeleton.interface';

const Skeleton = ({
const SkeletonView = ({
count = 1,
width = '100%',
height = 15,
circle = false,
}: SkeletonProps): ReactElement => {
const borderRadiusStyle = circle ? 100 : 5;
let newCount;

if (circle) {
Expand All @@ -25,11 +27,18 @@ const Skeleton = ({

return (
<>
{arr.map((el: any, i: number): ReactElement => {
return <UiElementLayout key={i}>loading</UiElementLayout>;
{arr.map((_, i: number): ReactElement => {
return (
<Skeleton
key={i}
height={circle ? '100%' : height}
borderRadius={THEME_RADIUS_8}
circle={circle}
/>
);
})}
</>
);
};

export default Skeleton;
export default SkeletonView;
9 changes: 9 additions & 0 deletions package-lock.json

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

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
"react-dom": "18.3.1",
"react-error-boundary": "^4.0.13",
"react-hook-form": "^7.52.2",
"react-loading-skeleton": "^3.5.0",
"react-native": "0.74.5",
"react-native-dotenv": "^3.4.11",
"react-native-error-boundary": "^1.2.4",
Expand Down

0 comments on commit bccd534

Please sign in to comment.