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
make news list layout #23
Merged
Merged
Changes from 4 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"presets": ["next/babel"], | ||
"plugins": [["styled-components", { "ssr": true }]] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
{ | ||
"extends": "next" | ||
} | ||
"extends": "next" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import Document from "next/document"; | ||
import { ServerStyleSheet } from "styled-components"; | ||
|
||
export default class MyDocument extends Document { | ||
static async getInitialProps(ctx) { | ||
const sheet = new ServerStyleSheet(); | ||
const originalRenderPage = ctx.renderPage; | ||
|
||
try { | ||
ctx.renderPage = () => | ||
originalRenderPage({ | ||
enhanceApp: (App) => (props) => | ||
sheet.collectStyles(<App {...props} />), | ||
}); | ||
|
||
const initialProps = await Document.getInitialProps(ctx); | ||
return { | ||
...initialProps, | ||
styles: ( | ||
<> | ||
{initialProps.styles} | ||
{sheet.getStyleElement()} | ||
</> | ||
), | ||
}; | ||
} finally { | ||
sheet.seal(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
import React from "react"; | ||
import Head from "next/head"; | ||
import styled from "styled-components"; | ||
import Footer from "../../../components/Footer"; | ||
import "firebase/auth"; | ||
import { useForm, SubmitHandler } from "react-hook-form"; | ||
|
||
type FormValues = { | ||
title: string; | ||
description: string; | ||
photo: string; | ||
}; | ||
|
||
export default function Form() { | ||
const { | ||
register, | ||
handleSubmit, | ||
formState: { errors }, | ||
} = useForm<FormValues>(); | ||
const onSubmit: SubmitHandler<FormValues> = data => console.log(data); | ||
|
||
return ( | ||
<> | ||
<Head> | ||
<Title>News Form</Title> | ||
</Head> | ||
<Heading>News Form</Heading> | ||
|
||
<Container> | ||
<FormGroup onSubmit={handleSubmit(onSubmit)}> | ||
<Label htmlFor="title">Title</Label> | ||
<Input | ||
{...register("title", { | ||
required: { value: true, message: "Title is required" }, | ||
})} | ||
id="title" | ||
placeholder="please input title" | ||
/> | ||
{errors.title && <PValidation>{errors.title.message}</PValidation>} | ||
|
||
<Label htmlFor="description">Description</Label> | ||
<Textarea | ||
{...register("description", { | ||
required: { value: true, message: "Desciption is required" }, | ||
})} | ||
id="description" | ||
/> | ||
{errors.description && <PValidation>{errors.description.message}</PValidation>} | ||
|
||
<Label htmlFor="photo">Photo</Label> | ||
<Input | ||
{...register("photo", { | ||
required: { value: true, message: "Photo is required" }, | ||
})} | ||
id="photo" | ||
type="file" | ||
/> | ||
{errors.photo && <PValidation>{errors.photo.message}</PValidation>} | ||
|
||
<Input type="submit" /> | ||
</FormGroup> | ||
</Container> | ||
<Footer /> | ||
</> | ||
); | ||
} | ||
|
||
const Heading = styled.h1` | ||
font-size: 2em; | ||
text-align: center; | ||
color: palevioletred; | ||
`; | ||
|
||
const Title = styled.title``; | ||
|
||
const Container = styled.div` | ||
text-align: center; | ||
padding: 0 0.5rem; | ||
align-items: center; | ||
`; | ||
|
||
const FormGroup = styled.form` | ||
`; | ||
|
||
const Input = styled.input` | ||
display: block; | ||
box-sizing: border-box; | ||
width: 100%; | ||
border-radius: 4px; | ||
border: 1px solid black; | ||
padding: 10px 15px; | ||
margin-bottom: 10px; | ||
font-size: 14px; | ||
`; | ||
|
||
const Label = styled.label` | ||
line-height: 2; | ||
text-align: left; | ||
display: block; | ||
margin-bottom: 13px; | ||
margin-top: 20px; | ||
color: black; | ||
font-size: 20px; | ||
font-weight: 200; | ||
`; | ||
const Textarea = styled.textarea` | ||
display: block; | ||
box-sizing: border-box; | ||
width: 100%; | ||
height: 100px; | ||
border-radius: 4px; | ||
border: 1px solid black; | ||
padding: 10px 15px; | ||
margin-bottom: 10px; | ||
font-size: 14px; | ||
`; | ||
|
||
const PValidation = styled.p` | ||
color: red; | ||
text-align: left; | ||
`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,161 @@ | ||
import React from "react"; | ||
import Head from "next/head"; | ||
import styled from "styled-components"; | ||
import Footer from "../../../components/Footer"; | ||
import "firebase/auth"; | ||
import Image from "next/image"; | ||
|
||
export default function List() { | ||
return ( | ||
<> | ||
<Head> | ||
<Title>News List</Title> | ||
</Head> | ||
<Heading>News List</Heading> | ||
|
||
<Container> | ||
<TotalCount> | ||
<B>Total: 20 news</B> | ||
</TotalCount> | ||
<StyledTable> | ||
<THead> | ||
<TR> | ||
<TH>Photo</TH> | ||
<TH>Title</TH> | ||
<TH>Descrption</TH> | ||
<TH>Edit</TH> | ||
<TH>Delete</TH> | ||
</TR> | ||
</THead> | ||
<TBody> | ||
<TR> | ||
<TD> | ||
<Image | ||
src="/images/photo1.jpg" | ||
alt="Picture of the product" | ||
width={80} | ||
height={80} | ||
/> | ||
</TD> | ||
<TD>News 1</TD> | ||
<TD>News 1 description</TD> | ||
<TD> | ||
{" "} | ||
<Button>Edit</Button> | ||
</TD> | ||
<TD> | ||
{" "} | ||
<Button>Delete</Button> | ||
</TD> | ||
</TR> | ||
|
||
<TR> | ||
<TD> | ||
<Image | ||
src="/images/photo1.jpg" | ||
alt="Picture of the product" | ||
width={80} | ||
height={80} | ||
/> | ||
</TD> | ||
<TD>News 2</TD> | ||
<TD>News 2 description</TD> | ||
<TD> | ||
{" "} | ||
<Button>Edit</Button> | ||
</TD> | ||
<TD> | ||
{" "} | ||
<Button>Delete</Button> | ||
</TD> | ||
</TR> | ||
</TBody> | ||
</StyledTable> | ||
<Pagination> | ||
<PaginationStep>«</PaginationStep> | ||
<PaginationStep>1</PaginationStep> | ||
<PaginationStep>2</PaginationStep> | ||
<PaginationStep>3</PaginationStep> | ||
<PaginationStep>4</PaginationStep> | ||
<PaginationStep>»</PaginationStep> | ||
</Pagination> | ||
</Container> | ||
<Footer /> | ||
</> | ||
); | ||
} | ||
|
||
const Heading = styled.h1` | ||
font-size: 2em; | ||
text-align: center; | ||
color: palevioletred; | ||
`; | ||
|
||
const Title = styled.title``; | ||
|
||
const Container = styled.div` | ||
text-align: center; | ||
padding: 0 0.5rem; | ||
align-items: center; | ||
`; | ||
|
||
const TotalCount = styled.p` | ||
text-align: left; | ||
color: red; | ||
`; | ||
const StyledTable = styled.table` | ||
// custom css goes here | ||
width: 100%; | ||
border: 1px solid black; | ||
border-collapse: collapse; | ||
`; | ||
|
||
const THead = styled.thead` | ||
// custom css goes here | ||
`; | ||
|
||
const TFoot = styled.tfoot` | ||
// custom css goes here | ||
`; | ||
|
||
const TBody = styled.tbody` | ||
// custom css goes here | ||
`; | ||
|
||
const TR = styled.tr` | ||
// custom css goes here | ||
`; | ||
|
||
const TH = styled.th` | ||
// custom css goes here | ||
border: 1px solid black; | ||
border-collapse: collapse; | ||
`; | ||
|
||
export const TD = styled.td` | ||
// custom css goes here | ||
border: 1px solid black; | ||
border-collapse: collapse; | ||
`; | ||
|
||
const Pagination = styled.div` | ||
display: inline-block; | ||
`; | ||
|
||
const PaginationStep = styled.a` | ||
color: black; | ||
float: left; | ||
padding: 8px 16px; | ||
text-decoration: none; | ||
`; | ||
|
||
const Button = styled.button` | ||
background: white; | ||
color: palevioletred; | ||
font-size: 1em; | ||
padding: 0.25em 1em; | ||
border: 2px solid palevioletred; | ||
border-radius: 3px; | ||
`; | ||
|
||
const B = styled.b``; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@duoctvd
Trong phần code tham khảo của react-hook-form có chọn ngôn ngữ JS và TS, em chọn vào TS (typescript) để xem và làm theo nha.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@bit-thuynt ah dạ! hôm nay em refer theo source đính kèm dưới video này https://gyazo.com/c4801108834acc463cc6f0bbfe955135 https://codesandbox.io/s/pensive-jepsen-lqyk7 , nên có 1 số chỗ nó chưa thật sự đúng TS
mai em sẽ compare lại và fix
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@bit-thuynt : DONE