Skip to content

Commit

Permalink
Merge pull request #9 from white-label-loyalty/task/exportTypes
Browse files Browse the repository at this point in the history
Export types
  • Loading branch information
iamgraeme authored Oct 15, 2024
2 parents d7e98e3 + 6e90dc9 commit b886c23
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 34 deletions.
4 changes: 2 additions & 2 deletions lib/components/molecules/Carousel/Carousel.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Meta, StoryFn } from '@storybook/react';
import React from 'react';
import { Section, SectionType } from '../../../types/section';
import { SectionType, TSection } from '../../../types/section';
import {
BannerTileConfig,
Tile,
Expand Down Expand Up @@ -41,7 +41,7 @@ const createMockSection = (
title: string,
description: string,
tiles: Tile[]
): Section => ({
): TSection => ({
id: Math.random().toString(36).substr(2, 9),
title,
type: SectionType.Banner,
Expand Down
4 changes: 2 additions & 2 deletions lib/components/molecules/Carousel/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ import {
View,
} from 'react-native';
import { useWllSdk } from '../../../context/WllSdkContext';
import { Section } from '../../../types/section';
import { TSection } from '../../../types/section';
import { Tile, TileType } from '../../../types/tile';
import { Icon } from '../../atoms';
import { SectionHeader } from '../../molecules';
import { BannerTile } from '../../organisms';

type CarouselProps = {
section: Section;
section: TSection;
};

const Carousel: React.FC<CarouselProps> = ({ section }) => {
Expand Down
2 changes: 1 addition & 1 deletion lib/components/molecules/Grid/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as React from 'react';
import { StyleSheet, useWindowDimensions, View } from 'react-native';
import { Section as SectionData } from '../../../types/section';
import { TSection as SectionData } from '../../../types/section';
import { Tile, TileHeight, TileType } from '../../../types/tile';
import { TileContainer } from '../../atoms';
import { SectionHeader } from '../../molecules';
Expand Down
34 changes: 9 additions & 25 deletions lib/components/organisms/Section/index.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,9 @@
import { useWllSdk } from '../../../context/WllSdkContext';
import {
Section as SectionData,
SectionType,
} from '../../../types/section';
import { TSection as SectionData, SectionType } from '../../../types/section';
import { Icon } from '../../atoms';
import { Carousel, Grid } from '../../molecules';

import React, {
createContext,
useContext,
useEffect,
useState,
} from 'react';
import React, { createContext, useContext, useEffect, useState } from 'react';
import { StyleSheet, Text, View } from 'react-native';

type SectionContextType = {
Expand All @@ -20,9 +12,9 @@ type SectionContextType = {
error: Error | null;
};

export const SectionContext = createContext<
SectionContextType | undefined
>(undefined);
export const SectionContext = createContext<SectionContextType | undefined>(
undefined
);

type SectionProviderProps = {
sectionId: string;
Expand All @@ -33,9 +25,7 @@ export const SectionProvider: React.FC<SectionProviderProps> = ({
sectionId,
children,
}) => {
const [sectionData, setSectionData] = useState<SectionData | null>(
null
);
const [sectionData, setSectionData] = useState<SectionData | null>(null);
const [loading, setLoading] = useState(true);
const [error, setError] = useState<Error | null>(null);
const { getSectionByID } = useWllSdk();
Expand All @@ -60,9 +50,7 @@ export const SectionProvider: React.FC<SectionProviderProps> = ({
}
} catch (err) {
setError(
err instanceof Error
? err
: new Error('An unknown error occurred')
err instanceof Error ? err : new Error('An unknown error occurred')
);
} finally {
setLoading(false);
Expand All @@ -81,9 +69,7 @@ export const SectionProvider: React.FC<SectionProviderProps> = ({
export const useSectionContext = () => {
const context = useContext(SectionContext);
if (context === undefined) {
throw new Error(
'useSectionContext must be used within a SectionProvider'
);
throw new Error('useSectionContext must be used within a SectionProvider');
}
return context;
};
Expand All @@ -101,9 +87,7 @@ const SectionContent: React.FC = () => {
]}
>
<Icon name="AlertTriangle" size={24} color="#967132" />
<Text style={styles.sectionContentText}>
Error: {error.message}
</Text>
<Text style={styles.sectionContentText}>Error: {error.message}</Text>
</View>
);

Expand Down
6 changes: 3 additions & 3 deletions lib/context/WllSdkContext.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
import { Section } from '../types/section';
import { TSection } from '../types/section';
import { BaseThemeObject, ThemeContextType, ThemeObject } from '../types/theme';
import { Tile } from '../types/tile';
import { defaultTheme, sizes } from '../utils/styling';
Expand All @@ -22,7 +22,7 @@ type APIResponse<T> = {
};

type WllSdkContextType = ThemeContextType & {
getSectionByID: (id: string) => Promise<APIResponse<Section>>;
getSectionByID: (id: string) => Promise<APIResponse<TSection>>;
getTileByID: (id: string) => Promise<APIResponse<Tile>>;
};

Expand Down Expand Up @@ -81,7 +81,7 @@ export const WllSdkProvider: React.FC<WllSdkProviderProps> = ({
const makeRequest = async (
endpoint: string,
options: RequestInit = {}
): Promise<Tile | Section> => {
): Promise<Tile | TSection> => {
const { proxyEndpoint, baseUrl, apiKey } = config;
const url = `${proxyEndpoint || baseUrl}${endpoint}`;
const headers = new Headers(options.headers);
Expand Down
7 changes: 7 additions & 0 deletions lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,10 @@ export * from './components/organisms';

// Export contexts
export * from './context/WllSdkContext';

// type exports
export * from './types/common';
export * from './types/section';
export * from './types/theme';
export * from './types/tile';
export * from './types/wll';
2 changes: 1 addition & 1 deletion lib/types/section.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export enum SectionType {
Banner = 'BANNER',
}

export type Section = {
export type TSection = {
id: string;
type: SectionType;
createdAt: string;
Expand Down

0 comments on commit b886c23

Please sign in to comment.