Skip to content

Commit 8a7ef67

Browse files
author
Daveed
committed
created a separatre component for the pages
1 parent 4055fca commit 8a7ef67

File tree

2 files changed

+93
-69
lines changed

2 files changed

+93
-69
lines changed

src/App.tsx

Lines changed: 18 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -3,25 +3,20 @@ import { Store } from './api/store';
33
import { StrapiClient } from './api/api.strapi';
44
import {
55
Container,
6-
Title,
7-
Image,
86
Text,
9-
Stack,
10-
Paper,
11-
Group,
12-
Button,
137
MantineProvider,
148
Skeleton
159
} from '@mantine/core';
16-
import { IconWorld } from '@tabler/icons-react';
17-
import ReactMarkdown from 'react-markdown';
1810
import '@mantine/core/styles.css';
1911
import './styles/blocks.scss';
2012
import { Page } from './api/page';
21-
import PageContent from './components/page.content';
2213
import config from './config';
2314
import { PostHogProvider } from 'posthog-js/react'
2415

16+
import HomePage from './components/home.page';
17+
18+
const POSTHOG_API_KEY = process.env.REACT_APP_POSTHOG_KEY as string;
19+
2520
/**
2621
* Landing page component
2722
* - Displays store basics, and home page content
@@ -81,67 +76,21 @@ function App() {
8176
);
8277
}
8378

79+
if (POSTHOG_API_KEY) {
80+
return (
81+
<PostHogProvider apiKey={POSTHOG_API_KEY}>
82+
<MantineProvider>
83+
<HomePage homePage={homePage} store={store} />
84+
</MantineProvider>
85+
</PostHogProvider>
86+
);
87+
}
88+
8489
return (
8590
<MantineProvider>
86-
<PostHogProvider apiKey={process.env.REACT_APP_POSTHOG_KEY as string}>
87-
<>
88-
<Container size="md" py="xl" id={window.location.hash?.replace('#', '')}>
89-
<Paper shadow="md" radius="md" p="xl" mb="xl">
90-
<Stack align="center">
91-
{store.Logo && (
92-
<Image
93-
src={store.Logo.formats?.small?.url || store.Logo.url}
94-
alt={store.title}
95-
width={200}
96-
height={200}
97-
fit="contain"
98-
/>
99-
)}
100-
101-
<Title order={1}>
102-
{store.title}
103-
</Title>
104-
105-
{store.Description && (
106-
<div className="blocks-content">
107-
<ReactMarkdown >
108-
{store.Description}
109-
</ReactMarkdown>
110-
</div>
111-
)}
112-
113-
{store.URLS && store.URLS.length > 0 && (
114-
<Group mt="md">
115-
{store.URLS.map((url) => (
116-
<Button
117-
key={url.id}
118-
component="a"
119-
href={url.URL}
120-
target="_blank"
121-
variant="light"
122-
>
123-
<IconWorld size={18} />{` `}
124-
{url.Label}
125-
</Button>
126-
))}
127-
</Group>
128-
)}
129-
</Stack>
130-
</Paper>
131-
132-
</Container >
133-
134-
<Container>
135-
<div className="blocks-content">
136-
{homePage && (
137-
<PageContent params={{ page: homePage }} />
138-
)}
139-
</div>
140-
</Container>
141-
</>
142-
</PostHogProvider>
143-
</MantineProvider >
144-
);
145-
}
91+
<HomePage homePage={homePage} store={store} />
92+
</MantineProvider>
93+
)
94+
};
14695

14796
export default App;

src/components/home.page.tsx

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
import React from 'react'
2+
import { Container, Paper, Stack, Image, Title, Button, Group } from '@mantine/core'
3+
import { IconHeartbeat } from '@tabler/icons-react'
4+
import ReactMarkdown from 'react-markdown'
5+
import PageContent from './page.content'
6+
import { Page } from '../api/page'
7+
import { Store } from '../api/store'
8+
9+
interface PageProps {
10+
homePage: Page | null;
11+
store: Store | null;
12+
}
13+
14+
15+
const PageComponent = ({homePage, store} : PageProps) => {
16+
return (
17+
<>
18+
<Container size="md" py="xl" id={window.location.hash?.replace('#', '')}>
19+
<Paper shadow="md" radius="md" p="xl" mb="xl">
20+
<Stack align="center">
21+
{store?.Logo && (
22+
<Image
23+
src={store.Logo.formats?.small?.url || store.Logo.url}
24+
alt={store.title}
25+
width={200}
26+
height={200}
27+
fit="contain"
28+
/>
29+
)}
30+
31+
<Title order={1}>
32+
{store?.title}
33+
</Title>
34+
35+
{store?.Description && (
36+
<div className="blocks-content">
37+
<ReactMarkdown >
38+
{store.Description}
39+
</ReactMarkdown>
40+
</div>
41+
)}
42+
43+
{store?.URLS?.length && (
44+
<Group mt="md">
45+
{store.URLS.map((url) => (
46+
<Button
47+
key={url.id}
48+
component="a"
49+
href={url.URL}
50+
target="_blank"
51+
variant="light"
52+
>
53+
<IconHeartbeat size={18} />{` `}
54+
{url.Label}
55+
</Button>
56+
))}
57+
</Group>
58+
)}
59+
</Stack>
60+
</Paper>
61+
62+
</Container >
63+
64+
<Container>
65+
<div className="blocks-content">
66+
{homePage && (
67+
<PageContent params={{ page: homePage }} />
68+
)}
69+
</div>
70+
</Container>
71+
</>
72+
)
73+
};
74+
75+
export default PageComponent;

0 commit comments

Comments
 (0)