Make Github stars dynamic and improve database init (#5000)

I extracted the init database logic into its own file. 
You can now run it with yarn database:init.
Added database entry for GitHub stars. 

Do you want me to remove the init route or is it used for something else
?

---------

Co-authored-by: Ady Beraud <a.beraud96@gmail.com>
Co-authored-by: Félix Malfait <felix.malfait@gmail.com>
This commit is contained in:
Ady Beraud
2024-04-24 10:44:44 +03:00
committed by GitHub
parent fda0c3c93c
commit 0a7f82333b
27 changed files with 237 additions and 118 deletions

View File

@ -11,8 +11,13 @@ import {
LogoContainer,
} from '@/app/_components/ui/layout/header/styled';
import { Logo } from '@/app/_components/ui/layout/Logo';
import { formatNumberOfStars } from '@/shared-utils/formatNumberOfStars';
export const HeaderDesktop = () => {
type Props = {
numberOfStars: number;
};
export const HeaderDesktop = ({ numberOfStars }: Props) => {
return (
<DesktopNav>
<LogoContainer>
@ -26,7 +31,9 @@ export const HeaderDesktop = () => {
Docs <ExternalArrow />
</ListItem>
<ListItem href="https://github.com/twentyhq/twenty">
<GithubIcon color="rgb(71,71,71)" /> 8.3k <ExternalArrow />
<GithubIcon color="rgb(71,71,71)" />
{formatNumberOfStars(numberOfStars)}
<ExternalArrow />
</ListItem>
</LinkList>
<CallToAction />

View File

@ -18,6 +18,7 @@ import {
NavOpen,
} from '@/app/_components/ui/layout/header/styled';
import { Logo } from '@/app/_components/ui/layout/Logo';
import { formatNumberOfStars } from '@/shared-utils/formatNumberOfStars';
const IBMPlexMono = IBM_Plex_Mono({
weight: '500',
@ -25,7 +26,11 @@ const IBMPlexMono = IBM_Plex_Mono({
display: 'swap',
});
export const HeaderMobile = () => {
type Props = {
numberOfStars: number;
};
export const HeaderMobile = ({ numberOfStars }: Props) => {
const isTwentyDev = false;
const [menuOpen, setMenuOpen] = useState(false);
@ -64,7 +69,8 @@ export const HeaderMobile = () => {
Docs <ExternalArrow />
</ListItem>
<ListItem href="https://github.com/twentyhq/twenty">
<GithubIcon color="rgb(71,71,71)" /> 8.3k <ExternalArrow />
<GithubIcon color="rgb(71,71,71)" />{' '}
{formatNumberOfStars(numberOfStars)} <ExternalArrow />
</ListItem>
</MobileLinkList>
<CallToAction />

View File

@ -1,13 +1,20 @@
'use client';
import { desc } from 'drizzle-orm';
import { HeaderDesktop } from '@/app/_components/ui/layout/header/HeaderDesktop';
import { HeaderMobile } from '@/app/_components/ui/layout/header/HeaderMobile';
import { findOne } from '@/database/database';
import { githubStarsModel } from '@/database/model';
export const AppHeader = async () => {
const githubStars = await findOne(
githubStarsModel,
desc(githubStarsModel.timestamp),
);
export const AppHeader = () => {
return (
<>
<HeaderDesktop />
<HeaderMobile />
<HeaderDesktop numberOfStars={githubStars?.[0]?.numberOfStars} />
<HeaderMobile numberOfStars={githubStars?.[0]?.numberOfStars} />
</>
);
};