Skip to content

Twitterの共有ボタン && トップページのデザイン #84

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Mar 26, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
135 changes: 131 additions & 4 deletions pages/index.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,58 @@
import { Box, Container, useMediaQuery, useTheme } from '@material-ui/core';
import {
Box,
Button,
Container,
Typography,
useTheme,
useMediaQuery,
} from '@material-ui/core';
import { makeStyles, createStyles, Theme } from '@material-ui/core/styles';
import { NextPage } from 'next';
import PostCard from '../components/PostCard';
import { Grid } from '@material-ui/core';
import { Pagination } from '@material-ui/lab';
import React, { useState, useEffect } from 'react';
import axios from '../utils/axios';

import TwitterIcon from '@material-ui/icons/Twitter';
import AddIcon from '@material-ui/icons/Add';
import DefaultHead from '../components/DefaultHead';

const useStyles = makeStyles((theme: Theme) =>
createStyles({
topHeader: {
[theme.breakpoints.only('xs')]: {
height: '256px',
},
[theme.breakpoints.only('sm')]: {
height: '384px',
},
[theme.breakpoints.up('md')]: {
height: '640px',
},
[theme.breakpoints.down('md')]: {
textAlign: 'center',
},
},
firstLetter: {
color: theme.palette.primary.main,
},
loginButton: {
backgroundColor: theme.palette.primary.main,
color: '#ffffff',
},
twitterShareButton: {
backgroundColor: '#55acee',
color: '#ffffff',
},
})
);

const Home: NextPage = () => {
const styles = useStyles();
const theme = useTheme();
const isXsSmMd = useMediaQuery(theme.breakpoints.down('md'));
const isXsSm = useMediaQuery(theme.breakpoints.down('sm'));
const isXs = useMediaQuery(theme.breakpoints.only('xs'));

const cardsPerPage = 6;
const cardsPerRow = isXsSm ? 1 : 2;
Expand All @@ -21,7 +63,7 @@ const Home: NextPage = () => {
(async () => {
try {
const res = await axios.get('/post');
setPosts(res.data);
setPosts(res.data.reverse());
} catch (err) {
console.log(err);
}
Expand All @@ -46,8 +88,93 @@ const Home: NextPage = () => {
return (
<>
<DefaultHead pageName="" />
<Box
style={{
height: isXs ? '256px' : isXsSm ? '384px' : '640px',
backgroundColor: '#ffffff',
}}>
<Container>
<Grid
container
justify="center"
alignContent="center"
alignItems="center">
<Grid
container
item
xs={12}
md={6}
justify="center"
alignItems="center"
className={styles.topHeader}>
<Grid container direction="column">
<Grid item xs={12}>
<Typography variant={isXs ? 'h5' : 'h4'}>
みんなのコード共有SNS
</Typography>
</Grid>
<Grid item xs={12}>
<Typography
variant={isXs ? 'h3' : isXsSm ? 'h2' : 'h1'}
style={{ borderBottom: '1px solid black' }}>
<span className={styles.firstLetter}>O</span>mnis
<span className={styles.firstLetter}>C</span>ode
</Typography>
</Grid>
<Grid
item
xs={12}
style={{ marginLeft: '8px', marginTop: '16px' }}>
<Grid
container
spacing={2}
justify={isXsSmMd ? 'center' : 'flex-start'}>
<Grid item>
<Button
href="/login"
variant="contained"
className={styles.loginButton}
startIcon={<AddIcon />}>
登録する
</Button>
</Grid>
<Grid item>
<Button
href={`http://twitter.com/share?url=${
process.env.baseUrl
}%0A&text=${encodeURIComponent(
'「みんなのコード共有SNS」OmnisCode'
)}%0A&hashtags=OmnisCode`}
target="_blank"
variant="contained"
className={styles.twitterShareButton}
startIcon={<TwitterIcon />}>
共有する
</Button>
</Grid>
</Grid>
</Grid>
</Grid>
</Grid>
{!isXsSm && (
<Grid
container
item
alignContent="center"
xs={6}
style={{ marginTop: '4vh', height: '52vh' }}>
<img
alt="headerImage"
src="https://user-images.githubusercontent.com/45159150/112662896-8eb16e80-8e9b-11eb-93c7-b41b1d5a7a56.png"
height="512px"
/>
</Grid>
)}
</Grid>
</Container>
</Box>
<Box m={4}>
<Container style={{ marginTop: '30px' }}>
<Container style={{ marginTop: '60px' }}>
<h1>投稿一覧</h1>
<Box display="flex" justifyContent="center">
<Pagination
Expand Down
23 changes: 22 additions & 1 deletion pages/post/[postid].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import fetcher from '../../utils/fetcher';
import { useRouter } from 'next/router';
import axios from '../../utils/axios';
import UserIcon from '../../components/UserIcon';
import TwitterIcon from '@material-ui/icons/Twitter';

import CustomHead from '../../components/CustomHead';

Expand Down Expand Up @@ -104,6 +105,10 @@ const useStyles = makeStyles((theme: Theme) =>
height: '48px',
fontSize: '18px',
},
twitterShareButton: {
backgroundColor: '#55ACEE',
color: '#FFFFFF',
},
})
);

Expand Down Expand Up @@ -480,9 +485,25 @@ const PostDetail: NextPage = () => {
/>
<Box m={4}>
<Container style={{ marginTop: '30px' }} disableGutters={isXsSm}>
<h1 style={{ textAlign: 'center', marginBottom: '60px' }}>
<h1 style={{ textAlign: 'center', marginBottom: '0px' }}>
{post.title}
</h1>
<p style={{ textAlign: 'center', marginBottom: '60px' }}>
<Button
href={`http://twitter.com/share?url=${process.env.baseUrl}${
router.asPath
}%0A&text=${
post.title.length > 70
? post.title.slice(0, 70) + '...'
: post.title
}%0A&hashtags=OmnisCode`}
target="_blank"
variant="contained"
className={styles.twitterShareButton}
startIcon={<TwitterIcon />}>
共有する
</Button>
</p>
{/* TODO: isXsSmならCommentCardにavatar_urlを追加する */}
{isXsSm ? (
<>
Expand Down