♻️ 使用 NextJS 重构 #1

Merged
LittleSheep merged 12 commits from refactor/v2 into master 2024-02-24 14:19:52 +00:00
5 changed files with 119 additions and 62 deletions
Showing only changes of commit 05ae2783cf - Show all commits

View File

@ -1 +0,0 @@
export const SITE_NAME = "Goatshed";

19
app/consts.tsx Normal file
View File

@ -0,0 +1,19 @@
import { ReactNode } from "react";
import GitHubIcon from "@mui/icons-material/GitHub";
import TwitterIcon from "@mui/icons-material/Twitter";
import CoffeeIcon from "@mui/icons-material/Coffee";
export interface RelatedAccount {
icon: ReactNode;
platform: string;
accountName: string;
link: string;
}
export const SITE_NAME = "Goatshed";
export const RELATED_ACCOUNTS: RelatedAccount[] = [
{ icon: <GitHubIcon />, platform: "GitHub", accountName: "@smartsheep-hq", link: "https://github.com/smartsheep-hq" },
{ icon: <TwitterIcon />, platform: "Twitter", accountName: "@littlesheepovo", link: "https://twitter.com/littlesheepovo" },
{ icon: <CoffeeIcon />, platform: "Ko-fi", accountName: "@littlesheep2code", link: "https://ko-fi.com/littlesheep2code" },
];

View File

@ -1,35 +1,74 @@
import { Container, Typography } from "@mui/material"; import {
Avatar,
Box,
Button,
Card, colors,
Container,
Grid,
List,
ListItemAvatar,
ListItemButton,
ListItemText,
Typography
} from "@mui/material";
import { RELATED_ACCOUNTS } from "@/app/consts";
import Image from "next/image";
import Link from "next/link";
export default function Home() { export default function Home() {
return ( return (
<Container> <Container sx={{ scrollBehavior: "smooth", px: 5 }}>
<Typography paragraph> <Grid
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod container
tempor incididunt ut labore et dolore magna aliqua. Rhoncus dolor purus non id="introduce"
enim praesent elementum facilisis leo vel. Risus at ultrices mi tempus alignItems="center"
imperdiet. Semper risus in hendrerit gravida rutrum quisque non tellus. sx={{ height: "calc(100vh - 64px)" }}
Convallis convallis tellus id interdum velit laoreet id donec ultrices. >
Odio morbi quis commodo odio aenean sed adipiscing. Amet nisl suscipit <Grid item xs={12} md={6} sx={{ textAlign: { xs: "center", md: "initial" } }}>
adipiscing bibendum est ultricies integer quis. Cursus euismod quis viverra <Typography variant="h3" component="h1" gutterBottom> 👋</Typography>
nibh cras. Metus vulputate eu scelerisque felis imperdiet proin fermentum <Typography paragraph>
leo. Mauris commodo quis imperdiet massa tincidunt. Cras tincidunt lobortis SmartSheep Studio
feugiat vivamus at augue. At augue eget arcu dictum varius duis at
consectetur lorem. Velit sed ullamcorper morbi tincidunt. Lorem donec massa </Typography>
sapien faucibus et molestie ac. <Button variant="contained" href="#about-us" size="large"></Button>
</Typography> </Grid>
<Typography paragraph> <Grid item xs={12} md={6} sx={{ display: "flex", justifyContent: "end" }}>
Consequat mauris nunc congue nisi vitae suscipit. Fringilla est ullamcorper <Box>
eget nulla facilisi etiam dignissim diam. Pulvinar elementum integer enim <Image src="smartsheep.svg" alt="Logo" width={256} height={256} />
neque volutpat ac tincidunt. Ornare suspendisse sed nisi lacus sed viverra </Box>
tellus. Purus sit amet volutpat consequat mauris. Elementum eu facilisis </Grid>
sed odio morbi. Euismod lacinia at quis risus sed vulputate odio. Morbi </Grid>
tincidunt ornare massa eget egestas purus viverra accumsan in. In hendrerit
gravida rutrum quisque non tellus orci ac. Pellentesque nec nam aliquam sem <Grid
et tortor. Habitant morbi tristique senectus et. Adipiscing elit duis container
tristique sollicitudin nibh sit. Ornare aenean euismod elementum nisi quis id="about-us"
eleifend. Commodo viverra maecenas accumsan lacus vel facilisis. Nulla alignItems="center"
posuere sollicitudin aliquam ultrices sagittis orci a. sx={{ height: "calc(100vh - 64px)" }}
</Typography> >
<Grid item xs={12} md={6} sx={{ display: "flex", justifyContent: "start" }}>
<Card sx={{ flexGrow: 1, mr: { xs: 0, md: 8 } }}>
<List sx={{ width: "100%", bgcolor: "background.paper" }}>
{RELATED_ACCOUNTS.map((item, idx) => (
<Link key={idx} href={item.link} target="_blank" passHref>
<ListItemButton>
<ListItemAvatar>
<Avatar sx={{ bgcolor: colors.blueGrey[700] }}>{item.icon}</Avatar>
</ListItemAvatar>
<ListItemText primary={item.platform} secondary={item.accountName} />
</ListItemButton>
</Link>
))}
</List>
</Card>
</Grid>
<Grid item xs={12} md={6} sx={{ textAlign: { xs: "center", md: "initial" } }}>
<Typography variant="h3" component="h1" gutterBottom></Typography>
<Typography paragraph>
2019
</Typography>
</Grid>
</Grid>
</Container> </Container>
); );
} }

View File

@ -64,7 +64,6 @@ const AppMain = styled("main", { shouldForwardProp: (prop) => prop !== "open" })
return ({ return ({
flexGrow: 1, flexGrow: 1,
padding: theme.spacing(3),
transition: theme.transitions.create("margin", { transition: theme.transitions.create("margin", {
easing: theme.transitions.easing.sharp, easing: theme.transitions.easing.sharp,
duration: theme.transitions.duration.leavingScreen duration: theme.transitions.duration.leavingScreen
@ -92,19 +91,19 @@ export default function AppShell({ children }: {
useEffect(() => { useEffect(() => {
documentWindow = window; documentWindow = window;
}) });
return ( return (
<Box sx={{ display: "flex" }}> <>
<HideOnScroll window={() => documentWindow}> <HideOnScroll window={() => documentWindow}>
<ShellAppBar open={open}> <ShellAppBar open={open} position="fixed">
<Toolbar> <Toolbar sx={{ height: 64 }}>
<IconButton <IconButton
size="large" size="large"
edge="start" edge="start"
color="inherit" color="inherit"
aria-label="menu" aria-label="menu"
sx={{ mr: 2 }} sx={{ ml: isMobile ? 0.5 : 0, mr: 2 }}
> >
<Image src="smartsheep.svg" alt="Logo" width={32} height={32} /> <Image src="smartsheep.svg" alt="Logo" width={32} height={32} />
</IconButton> </IconButton>
@ -127,12 +126,15 @@ export default function AppShell({ children }: {
</ShellAppBar> </ShellAppBar>
</HideOnScroll> </HideOnScroll>
<AppMain open={open}> <Box sx={{ display: "flex" }}>
<AppNavigationHeader /> <AppMain open={open}>
{children} <AppNavigationHeader />
</AppMain>
<NavigationDrawer open={open} onClose={() => setOpen(false)} /> {children}
</Box> </AppMain>
<NavigationDrawer open={open} onClose={() => setOpen(false)} />
</Box>
</>
); );
} }

View File

@ -18,14 +18,27 @@ import {
useMediaQuery useMediaQuery
} from "@mui/material"; } from "@mui/material";
import { theme } from "@/app/theme"; import { theme } from "@/app/theme";
import { ReactNode } from "react";
import HomeIcon from "@mui/icons-material/Home";
import Link from "next/link";
export interface NavigationItem {
icon: ReactNode;
title: string;
link: string;
}
export const DRAWER_WIDTH = 320; export const DRAWER_WIDTH = 320;
export const NAVIGATION_ITEMS: NavigationItem[] = [
{ icon: <HomeIcon />, title: "首页", link: "/" }
];
export const AppNavigationHeader = styled("div")(({ theme }) => ({ export const AppNavigationHeader = styled("div")(({ theme }) => ({
display: "flex", display: "flex",
alignItems: "center", alignItems: "center",
padding: theme.spacing(0, 1), padding: theme.spacing(0, 1),
justifyContent: "flex-start", justifyContent: "flex-start",
height: 64,
...theme.mixins.toolbar ...theme.mixins.toolbar
})); }));
@ -45,28 +58,13 @@ export function AppNavigation({ showClose, onClose }: {
</AppNavigationHeader> </AppNavigationHeader>
<Divider /> <Divider />
<List> <List>
{["Inbox", "Starred", "Send email", "Drafts"].map((text, index) => ( {NAVIGATION_ITEMS.map((item, idx) => (
<ListItem key={text} disablePadding> <Link key={idx} href={item.link} passHref>
<ListItemButton> <ListItemButton>
<ListItemIcon> <ListItemIcon>{item.icon}</ListItemIcon>
{index % 2 === 0 ? <InboxIcon /> : <MailIcon />} <ListItemText primary={item.title} />
</ListItemIcon>
<ListItemText primary={text} />
</ListItemButton> </ListItemButton>
</ListItem> </Link>
))}
</List>
<Divider />
<List>
{["All mail", "Trash", "Spam"].map((text, index) => (
<ListItem key={text} disablePadding>
<ListItemButton>
<ListItemIcon>
{index % 2 === 0 ? <InboxIcon /> : <MailIcon />}
</ListItemIcon>
<ListItemText primary={text} />
</ListItemButton>
</ListItem>
))} ))}
</List> </List>
</> </>