Skip to content
This repository was archived by the owner on Feb 15, 2025. It is now read-only.

Commit 65b57b7

Browse files
committed
optimized component structure
1 parent e90ab8d commit 65b57b7

File tree

36 files changed

+136
-18
lines changed

36 files changed

+136
-18
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import { animated, useSpring } from 'react-spring';
2+
import React, { useEffect, useState } from 'react';
3+
import { useAgile } from '@agile-ts/react';
4+
import core from '../../../../../../core';
5+
import styles from './styles.module.css';
6+
import clsx from 'clsx';
7+
8+
type Props = { className?: string };
9+
10+
const Astronaut: React.FC<Props> = (props) => {
11+
const { className } = props;
12+
const [timing] = useState(200);
13+
const [isRaised, setIsRaised] = React.useState(false);
14+
const animated_Astronaut = useSpring({
15+
transform: isRaised ? `translateY(-${30}px)` : `translateY(0px)`,
16+
config: {
17+
mass: 1,
18+
tension: 400,
19+
friction: 15,
20+
},
21+
});
22+
const dark = useAgile(core.ui.ASTRONAUT_DARK);
23+
24+
useEffect(() => {
25+
if (!isRaised) {
26+
return;
27+
}
28+
29+
const timeoutId = setTimeout(() => {
30+
core.ui.toggleAstronautColor(!dark);
31+
setIsRaised(false);
32+
}, timing);
33+
34+
return () => clearTimeout(timeoutId);
35+
}, [isRaised, timing]);
36+
37+
const trigger = () => setIsRaised(true);
38+
39+
return (
40+
<div className={clsx(styles.Container, className)}>
41+
<animated.img
42+
onMouseEnter={trigger}
43+
style={animated_Astronaut}
44+
className={styles.Image}
45+
src={`img/astronaut-${dark ? 'dark' : 'light'}.svg`}
46+
alt={'Astronaut'}
47+
/>
48+
<div className={styles.Text}>Poke me 👆 to mutate my color State.</div>
49+
</div>
50+
);
51+
};
52+
53+
export default Astronaut;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
.Container {
2+
display: flex;
3+
flex-direction: column;
4+
align-items: flex-end;
5+
}
6+
7+
.Text {
8+
color: var(--ifm-color-on-background-2);
9+
margin-top: 30px;
10+
align-self: center;
11+
}
12+
13+
.Image {
14+
width: 100%;
15+
max-width: 800px;
16+
}

src/_pages/LandingPage/components/HeaderView/index.tsx

+6-8
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
1-
import React, { useState } from 'react';
1+
import React, { useEffect, useState } from 'react';
22
import useDocusaurusContext from '@docusaurus/useDocusaurusContext';
3-
import HeaderTyper from '../../../../components/other/HeaderTyper';
3+
import HeaderTyper from './components/HeaderTyper';
44
import Spacer from '../../../../components/other/Spacer';
55
import PrimaryButton from '../../../../components/buttons/PrimaryButton';
66
import GithubButton from '../../../../components/buttons/GithubButton';
77
import styles from './styles.module.css';
88
import { useWindowSize } from '../../../../hooks/useWindowSize';
9-
import MouseScroller from '../../../../components/other/MouseScroller';
9+
import MouseScroller from './components/MouseScroller';
10+
import { animated, useSpring } from 'react-spring';
11+
import Astronaut from './components/Astronaut';
1012

1113
const HeaderView: React.FC = () => {
1214
const { siteConfig } = useDocusaurusContext();
@@ -52,11 +54,7 @@ const HeaderView: React.FC = () => {
5254
/>
5355
</div>
5456
</div>
55-
<img
56-
className={styles.AstronautImage}
57-
src={'img/astronaut-light.svg'}
58-
alt={'Astronaut'}
59-
/>
57+
<Astronaut className={styles.AstronautImage} />
6058
{windowHeight > 850 && windowHeight < 1200 && <MouseScroller />}
6159
</div>
6260
);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import React from 'react';
2+
import styles from './styles.module.css';
3+
import Spacer from '../../../../components/other/Spacer';
4+
5+
const OtherFeaturesView: React.FC = () => {
6+
return (
7+
<div className={styles.Container}>
8+
<Spacer height={30} />
9+
<div>todo</div>
10+
</div>
11+
);
12+
};
13+
14+
export default OtherFeaturesView;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
.Container {
2+
display: flex;
3+
flex-direction: column;
4+
align-items: center;
5+
width: 95%;
6+
max-width: var(--ifm-container-width);
7+
margin: 0 auto;
8+
padding: 8rem 0;
9+
}

src/components/other/LiveCoder/index.tsx renamed to src/_pages/LandingPage/components/StartCodingView/components/LiveCoder/index.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { useState } from 'react';
66
import LiveCodeNotFound from './components/LiveCodeNotFound';
77
import { FaReact, FaVuejs } from 'react-icons/all';
88
import usePrismTheme from '@theme/hooks/usePrismTheme';
9-
import PlainButton from '../../buttons/PlainButton';
9+
import PlainButton from '../../../../../../components/buttons/PlainButton';
1010
import FrameworkButton from './components/FrameworkButton';
1111

1212
type Props = {

src/_pages/LandingPage/components/StartCodingView/index.tsx

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
import React from 'react';
22
import styles from './styles.module.css';
3-
import LiveCoder from '../../../../components/other/LiveCoder';
3+
import LiveCoder from './components/LiveCoder';
44
import Spacer from '../../../../components/other/Spacer';
5-
import PlainButton from '../../../../components/buttons/PlainButton';
65

76
const reactCode = `// Let's start by creating an Agile Instance
87
const App = new Agile();

src/components/other/StatBadge/index.tsx renamed to src/_pages/LandingPage/components/StatsView/components/StatBadge/index.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React from 'react';
22
import styles from './styles.module.css';
33
import { IconContext } from 'react-icons';
4-
import Icons, { IconTypes } from '../Icons';
4+
import Icons, { IconTypes } from '../../../../../../components/other/Icons';
55
import clsx from 'clsx';
66
import { useHistory } from 'react-router-dom';
77

src/_pages/LandingPage/components/StatsView/index.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import useDocusaurusContext from '@docusaurus/useDocusaurusContext';
44
import Spacer from '../../../../components/other/Spacer';
55
import { useAgile } from '@agile-ts/react';
66
import core from '../../../../core';
7-
import StatBadge from '../../../../components/other/StatBadge';
7+
import StatBadge from './components/StatBadge';
88

99
const StatsView: React.FC = () => {
1010
const { siteConfig } = useDocusaurusContext();

src/components/other/SectionScroller/components/SectionRightItem/index.tsx renamed to src/_pages/LandingPage/components/StraightforwardView/components/SectionScroller/components/SectionRightItem/index.tsx

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
import React from 'react';
22
import styles from './styles.module.css';
33
import clsx from 'clsx';
4-
import Icons, { IconTypes } from '../../../Icons';
4+
import Icons, {
5+
IconTypes,
6+
} from '../../../../../../../../components/other/Icons';
57

68
export type Props = {
79
icon?: IconTypes;

src/components/other/SectionScroller/index.tsx renamed to src/_pages/LandingPage/components/StraightforwardView/components/SectionScroller/index.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import React, { useCallback, useEffect, useRef, useState } from 'react';
22
import styles from './styles.module.css';
3-
import { useWindowSize } from '../../../hooks/useWindowSize';
3+
import { useWindowSize } from '../../../../../../hooks/useWindowSize';
44
import SectionRightItem from './components/SectionRightItem';
55
import SectionLeftItem from './components/SectionLeftItem';
66
import { FiChevronDown, FiChevronUp } from 'react-icons/all';
7-
import { IconTypes } from '../Icons';
7+
import { IconTypes } from '../../../../../../components/other/Icons';
88

99
export interface SectionInterface {
1010
codeWithComment?: string;

src/_pages/LandingPage/components/StraightforwardView/index.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import styles from './styles.module.css';
33
import Spacer from '../../../../components/other/Spacer';
44
import SectionScroller, {
55
SectionInterface,
6-
} from '../../../../components/other/SectionScroller';
6+
} from './components/SectionScroller';
77
import PlainButton from '../../../../components/buttons/PlainButton';
88

99
const sections: SectionInterface[] = [

src/components/other/Cards/index.tsx

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import React from 'react';
2+
3+
export interface CardInterface {
4+
title: string;
5+
description: string;
6+
imagePath: string;
7+
}
8+
9+
export type Props = { cards: CardInterface[]; startIndex?: number };
10+
11+
const Cards: React.FC<CardInterface> = (props) => {
12+
return (
13+
<div>
14+
<div>much todo</div>
15+
</div>
16+
);
17+
};
18+
19+
export default Cards;

src/core/entities/ui/ui.actions.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
1-
import { THEME_TYPE } from './ui.controller';
1+
import { ASTRONAUT_DARK, THEME_TYPE } from './ui.controller';
22
import { ThemeInterface } from './ui.interface';
33

44
export const toggleTheme = (dark: boolean): void => {
55
THEME_TYPE.set(dark ? 'dark' : 'light');
66
};
77

8+
export const toggleAstronautColor = (dark: boolean): void => {
9+
ASTRONAUT_DARK.set(dark);
10+
};
11+
812
export const mutateThemeCssProperties = (theme: ThemeInterface): void => {
913
document.documentElement.style.setProperty(
1014
'--ifm-background-color',

src/core/entities/ui/ui.controller.ts

+4
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,7 @@ export const THEME = App.createState<ThemeInterface>(
1818
).watch('mutateColor', (value) => {
1919
mutateThemeCssProperties(value);
2020
});
21+
22+
export const ASTRONAUT_DARK = App.createState<boolean>(false).persist(
23+
'astronaut-color'
24+
);

0 commit comments

Comments
 (0)