Skip to content

Commit

Permalink
Merge pull request #30 from duoctvd/feature/5/apply_pagination
Browse files Browse the repository at this point in the history
Feature/5/apply pagination
  • Loading branch information
duoctvd committed Aug 23, 2021
2 parents bee8cd7 + 80d9c82 commit 8205062
Show file tree
Hide file tree
Showing 27 changed files with 443 additions and 393 deletions.
2 changes: 1 addition & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,4 @@ module.exports = {
version: "detect",
},
},
};
};
7 changes: 0 additions & 7 deletions firestore/news/deleteNewsById.ts

This file was deleted.

11 changes: 0 additions & 11 deletions firestore/news/insertNews.ts

This file was deleted.

28 changes: 0 additions & 28 deletions firestore/news/retrieveNews.ts

This file was deleted.

34 changes: 0 additions & 34 deletions firestore/news/retrieveNewsById.ts

This file was deleted.

8 changes: 0 additions & 8 deletions models/news.ts

This file was deleted.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"start": "next start",
"eslint": "eslint pages --ext .ts,.tsx,.js,.jsx --ignore-path ./.gitignore . --max-warnings=0",
"eslint:fix": "yarn eslint --fix",
"prettier": "prettier --write \"{,pages/**/,components/**}*.{js,jsx,ts,tsx,json,yaml,md}\""
"prettier": "prettier --write \"{,src/**/}*.{js,jsx,ts,tsx,json,yaml,md}\""
},
"dependencies": {
"firebase": "^8.7.1",
Expand Down
3 changes: 1 addition & 2 deletions src/components/CaptionProduct.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import styled from "styled-components";
import {News} from "../../models/news";

import { News } from "../models/news";

export default function CaptionProduct({ news }: { news: News }) {
return (
Expand Down
6 changes: 2 additions & 4 deletions src/components/Product.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import styled from "styled-components";
import Image from "next/image";
import Link from "next/link";
import {News} from "../../models/news";
import { News } from "../models/news";
export default function Product({ news }: { news: News }) {
return (
<Container>
Expand All @@ -14,9 +14,7 @@ export default function Product({ news }: { news: News }) {
width={200}
height={200}
/>
<Description>
{news.description}
</Description>
<Description>{news.description}</Description>
</Container>
);
}
Expand Down
7 changes: 2 additions & 5 deletions src/components/ThumnailProduct.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import styled from "styled-components";
import CaptionProduct from "./CaptionProduct";
import Image from "next/image";
import {News} from "../../models/news";
import { News } from "../models/news";

export default function ThumnailProduct({ news }: { news: News }) {
return (
Expand All @@ -12,14 +12,11 @@ export default function ThumnailProduct({ news }: { news: News }) {
width={200}
height={200}
/>
<CaptionProduct news={news}/>
<CaptionProduct news={news} />
</Container>
);
}




const Container = styled.div`
display: block;
padding: 4px;
Expand Down
166 changes: 82 additions & 84 deletions src/components/templates/admin/news/form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,33 +3,32 @@ import Head from "next/head";
import styled from "styled-components";
import Footer from "../../../../components/Footer";
import Link from "next/link";
import {News} from "../../../../../models/news";
import { News } from "../../../../models/news";
import { useForm, SubmitHandler } from "react-hook-form";
import { firebase } from "../../../../../firebase";
import "firebase/firestore";
import { InsertNews } from '../../../../../firestore/news/insertNews';
import { UpdateNews } from '../../../../../firestore/news/updateNews';
import { InsertNews } from "../../../../firestore/news/insertNews";
import { UpdateNews } from "../../../../firestore/news/updateNews";

interface Props {
news: News;
};
news: News;
}

export default function NewsFormTemplate({ news }: Props) {
const {
register,
handleSubmit,
formState: { errors },
} = useForm<News>();
const onSubmit: SubmitHandler<News> = data => {
const {
register,
handleSubmit,
formState: { errors },
} = useForm<News>();

const onSubmit: SubmitHandler<News> = (data) => {
const db = firebase.firestore();
if(!news.id)
{
const insertData:News = {
if (!news.id) {
const insertData: News = {
title: data.title,
description: data.description,
openFlag: true,
delFlag: false
delFlag: false,
};
const insertId = InsertNews(insertData);

Expand All @@ -50,78 +49,77 @@ export default function NewsFormTemplate({ news }: Props) {
// console.error("Error adding document: ", error);
// });
} else {
// To update age and favorite color:
// To update age and favorite color:

const updateData:News = {
id: news.id,
title: data.title,
description: data.description,
};
const updateData: News = {
id: news.id,
title: data.title,
description: data.description,
};

UpdateNews(updateData);
UpdateNews(updateData);

alert("Document successfully updated!");
alert("Document successfully updated!");

// db.collection("news").doc(news.id).update()
// .then(() => {
// alert("Document successfully updated!");
// });
// db.collection("news").doc(news.id).update()
// .then(() => {
// alert("Document successfully updated!");
// });
}

};
return (
<>
<Head>
<Title>News Edit Form</Title>
</Head>
<Heading>News Edit Form</Heading>

<Container>
<FormGroup onSubmit={handleSubmit(onSubmit)}>
<InputHiden
defaultValue={news.id}
/>
<Label htmlFor="title">Title</Label>
<Input
defaultValue={news.title}
{...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
defaultValue={news.description}
{...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: false, message: "Photo is required" },
})}
id="photo"
type="file"
/>
{errors.photo && <PValidation>{errors.photo.message}</PValidation>}

<InputButton type="submit">Submit</InputButton>

<Link href={`/admin/news/list`} passHref>
<Button>Back</Button>
</Link>
</FormGroup>
</Container>
<Footer />
</>
);
};
return (
<>
<Head>
<Title>News Edit Form</Title>
</Head>
<Heading>News Edit Form</Heading>

<Container>
<FormGroup onSubmit={handleSubmit(onSubmit)}>
<InputHiden defaultValue={news.id} />
<Label htmlFor="title">Title</Label>
<Input
defaultValue={news.title}
{...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
defaultValue={news.description}
{...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: false, message: "Photo is required" },
})}
id="photo"
type="file"
/>
{errors.photo && <PValidation>{errors.photo.message}</PValidation>}

<InputButton type="submit">Submit</InputButton>

<Link href={`/admin/news/list`} passHref>
<Button>Back</Button>
</Link>
</FormGroup>
</Container>
<Footer />
</>
);
}

const Heading = styled.h1`
Expand Down Expand Up @@ -191,4 +189,4 @@ const Button = styled.button`
cursor: pointer;
`;

const InputButton = styled(Button)``;
const InputButton = styled(Button)``;
Loading

1 comment on commit 8205062

@vercel
Copy link

@vercel vercel bot commented on 8205062 Aug 23, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.