Skip to content

Commit 864bf83

Browse files
authored
fix: use better state management and some small tweaks to colors and styles (#83)
* im stupid * jesus * clean up * fix alignment * change face on hover tree * set revalidate to 5 mins
1 parent a0e39c3 commit 864bf83

39 files changed

+595
-641
lines changed

package-lock.json

Lines changed: 16 additions & 28 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
"type-check": "tsc --noEmit",
1010
"analyze": "ANALYZE=true npm run build",
1111
"build": "next build",
12-
"vercel-build": "yum install libuuid-devel libmount-devel && cp /lib64/{libuuid,libmount,libblkid}.so.1 node_modules/canvas/build/Release/ && npm run build",
13-
"serve": "next start"
12+
"serve": "next start",
13+
"vercel-build": "yum install libuuid-devel libmount-devel && cp /lib64/{libuuid,libmount,libblkid}.so.1 node_modules/canvas/build/Release/ && npm run build"
1414
},
1515
"devDependencies": {
1616
"@types/ioredis": "^4.17.8",
@@ -40,6 +40,6 @@
4040
"react-dom": "npm:@preact/compat@0.0.3",
4141
"react-ssr-prepass": "npm:preact-ssr-prepass@^1.1.2",
4242
"react-text-loop": "^2.3.0",
43-
"storeon": "^3.1.2"
43+
"zustand": "^3.2.0"
4444
}
4545
}

src/components/Bio/About.tsx

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
1-
import { FC } from 'react';
2-
3-
import { useStore } from 'services/store';
41
import { Link, Text } from 'components/core';
52
import DynamicTime from 'components/DynamicTime';
63
import DynamicTagline from 'components/DynamicTagline';
74
import DynamicCurrentStatus from 'components/DynamicCurrentStatus';
5+
import { useInitialProps } from 'services/context/initial-props';
6+
import { getRandomItem } from 'services/utils';
7+
import { TALKING_POINTS } from 'services/copy';
8+
9+
const talkingPoint = getRandomItem(TALKING_POINTS);
810

9-
const About: FC = () => {
10-
const { talkingPoint, currentCity } = useStore('talkingPoint', 'currentCity');
11+
const About = () => {
12+
const { currentCity } = useInitialProps();
1113

1214
return (
1315
<>

src/components/Bio/Work.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@ import { FC, memo } from 'react';
22

33
import { Link, Text } from 'components/core';
44
import { PAST_EXPERIENCE } from 'services/copy';
5-
import { useStore } from 'services/store';
5+
import { useInitialProps } from 'services/context/initial-props';
66

77
const Work: FC = memo(() => {
8-
const { githubStats } = useStore('githubStats');
8+
const { githubStats } = useInitialProps();
99
const latestRepo = githubStats?.reposCommittedTo[0] ?? null;
1010

1111
return (

src/components/Bio/index.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { FC } from 'react';
22
import { styled } from 'goober';
33

4-
import { useStore } from 'services/store';
54
import { screen } from 'services/style';
5+
import { useSiteStore } from 'services/store';
66

77
import About from './About';
88
import Work from './Work';
@@ -31,7 +31,7 @@ const Subcontainer = styled('div')`
3131
`;
3232

3333
const Bio: FC = () => {
34-
const { displayedSection } = useStore('displayedSection');
34+
const displayedSection = useSiteStore((state) => state.displayedSection);
3535

3636
return (
3737
<Container>

src/components/CoverArt.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { css, keyframes } from 'goober';
22
import { FC, memo } from 'react';
3-
import { TNowPlayingData } from 'services/now-playing';
43

5-
import { useStoreFocusListeners } from 'services/store/utils';
4+
import { TNowPlayingData } from 'services/api';
5+
import { useStoreFocusListeners } from 'services/utils';
66
import { screen } from 'services/style';
77

88
type TCoverArtProps = Pick<TNowPlayingData, 'link' | 'coverArtSrc'> & {

src/components/DynamicCurrentStatus.tsx

Lines changed: 58 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
1-
import { memo, FC, useCallback, useEffect } from 'react';
1+
import { memo, FC, useState, useCallback } from 'react';
22
import TextLoop from 'react-text-loop';
33

4-
import { useStore } from 'services/store';
5-
import { TNowPlayingData, isNowPlayingData } from 'services/now-playing';
4+
import { TNowPlayingData, isNowPlayingData, getNowPlaying } from 'services/api';
65
import {
6+
getRandomItem,
77
textLoopIntervals,
88
TVisibilityChangeHandler,
99
useVisibilityChange,
1010
} from 'services/utils';
1111
import CoverArt from 'components/CoverArt';
1212
import { Text } from 'components/core';
13+
import { useInitialProps } from 'services/context/initial-props';
14+
import { ACTIVITIES, PREFIXES } from 'services/copy';
1315

1416
const clamp = (v: number, min: number, max: number) =>
1517
Math.max(Math.min(v, max), min);
@@ -58,22 +60,64 @@ const nowPlayingMarkup = ({
5860
];
5961
};
6062

61-
const DynamicCurrentStatus: FC = memo(() => {
62-
const { dispatch, statuses } = useStore('statuses');
63-
const statusesMarkup = statuses.map((status) =>
64-
isNowPlayingData(status) ? nowPlayingMarkup(status) : status.split(' ')
65-
);
63+
const getInitialStatus = (initialStatus: string | null) => {
64+
const prefix = getRandomItem(PREFIXES);
65+
const activity = getRandomItem([
66+
...ACTIVITIES,
67+
...(initialStatus
68+
? new Array(ACTIVITIES.length).fill(initialStatus) // larger weight for custom status
69+
: []),
70+
]);
71+
72+
return `${prefix} ${activity}.`;
73+
};
74+
75+
const useStatuses = () => {
76+
const {
77+
initialNowPlayingData,
78+
customStatus,
79+
spotifyToken,
80+
} = useInitialProps();
81+
82+
const [statuses, setStatuses] = useState([
83+
initialNowPlayingData ?? getInitialStatus(customStatus),
84+
]);
6685

67-
const visibilityChangeHandler = useCallback<TVisibilityChangeHandler>(
68-
(isHidden) => {
69-
if (!isHidden) dispatch('data/refresh');
86+
const updateNowPlaying = useCallback<TVisibilityChangeHandler>(
87+
async (isHidden) => {
88+
if (!isHidden) {
89+
const updatedNowPlayingData = await getNowPlaying(spotifyToken);
90+
const lastStatus = statuses[statuses.length - 1];
91+
const lastNowPlayingData = isNowPlayingData(lastStatus)
92+
? lastStatus
93+
: null;
94+
95+
if (
96+
!!updatedNowPlayingData &&
97+
updatedNowPlayingData.uri !== lastNowPlayingData?.uri
98+
) {
99+
console.log(
100+
`Now playing: ${
101+
updatedNowPlayingData.podcastName ?? updatedNowPlayingData.name
102+
}`
103+
);
104+
setStatuses((prev) => [...prev, updatedNowPlayingData]);
105+
}
106+
}
70107
},
71-
[dispatch]
108+
[spotifyToken, statuses]
72109
);
73110

74-
useVisibilityChange(visibilityChangeHandler);
111+
useVisibilityChange(updateNowPlaying);
112+
113+
return statuses;
114+
};
75115

76-
useEffect(() => dispatch('data/refresh'), []); //eslint-disable-line react-hooks/exhaustive-deps
116+
const DynamicCurrentStatus: FC = memo(() => {
117+
const statuses = useStatuses();
118+
const statusesMarkup = statuses.map((status) =>
119+
isNowPlayingData(status) ? nowPlayingMarkup(status) : status.split(' ')
120+
);
77121

78122
return (
79123
<span>

src/components/DynamicFavicon.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,14 @@ const DynamicFavicon: FC<{ face?: 'smile' | 'mad' }> = ({ face }) => {
88
useVisibilityChange(setAway);
99

1010
const dynamicFace = face ?? isAway ? 'mad' : 'smile';
11-
const href = dynamicFace === 'mad' ? '/favicon-away.png' : '/favicon.png';
1211

1312
return (
1413
<Head>
15-
<link rel="shortcut icon" type="image/png" href={href} />
14+
<link
15+
rel="shortcut icon"
16+
type="image/png"
17+
href={dynamicFace === 'mad' ? '/favicon-mad.png' : '/favicon.png'}
18+
/>
1619
</Head>
1720
);
1821
};

src/components/DynamicTagline.tsx

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
1-
import { memo, FC } from 'react';
1+
import { memo } from 'react';
22
import TextLoop from 'react-text-loop';
33

4-
import { useStore } from 'services/store';
4+
import { TAGLINES } from 'services/copy';
5+
import { getShuffledArray } from 'services/utils';
56

6-
const DynamicTagline: FC = memo(() => {
7-
const { taglines } = useStore('taglines');
7+
const taglines = getShuffledArray(TAGLINES);
88

9-
return <TextLoop children={taglines} />;
10-
});
9+
const DynamicTagline = memo(() => <TextLoop children={taglines} />);
1110

1211
export default DynamicTagline;

0 commit comments

Comments
 (0)