Skip to content

Commit 13fefc4

Browse files
committed
improve
1 parent c051a18 commit 13fefc4

File tree

12 files changed

+55
-65
lines changed

12 files changed

+55
-65
lines changed

.dockerignore

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,7 @@
1-
node_modules
2-
npm-debug.log
1+
node_modules/
2+
.next/
3+
.build/
4+
5+
npm-debug.log*
6+
yarn-debug.log*
7+
yarn-error.log*

.env

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@
33

44
ENV_VARIABLE="server_only_variable"
55
NEXT_PUBLIC_ENV_VARIABLE="public_variable"
6+
DB_LOCAL_URL=mongodb://mongo:27017/denizpaz

.env.production

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@
33

44
PRODUCTION_ENV_VARIABLE="server_only_production_variable"
55
NEXT_PUBLIC_PRODUCTION_ENV_VARIABLE="public_production_variable"
6+
DB_LOCAL_URL=mongodb://mongo:27017/denizpaz

Dockerfile

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,23 @@
1-
# base image
2-
31
FROM node:18-alpine
42

5-
# create & set working directory
6-
73
RUN mkdir -p /usr/src/app
84

95
WORKDIR /usr/src/app
106

11-
# copy source files
12-
13-
COPY . /usr/src/app
14-
15-
# install dependencies
7+
COPY package.json /usr/src/app/
168

179
RUN npm install -g next
18-
RUN npm install -g @heroicons/react
1910

2011
RUN npm install
2112

22-
# start app
13+
COPY . /usr/src/app
2314

2415
RUN npm run build
2516

17+
COPY --chown=10101 ./public /usr/src/app/public
18+
19+
ENV DB_LOCAL_URL=mongodb://mongo:27017/denizpaz
20+
2621
EXPOSE 3000
2722

2823
CMD npm run launch
Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,24 @@
11
import { NextResponse } from "next/server";
22
import { Recipe } from "../../../../models";
33

4+
export const dynamic = 'force-dynamic'
45
// ایجاد درخواست GET برای دریافت رسپی بر اساس آی‌دی
56
export async function GET(req: Request) {
67
try {
78
const { searchParams } = new URL(req.url);
8-
const id = searchParams.get('id');
9-
10-
if (!id) return NextResponse.json({ status: 400, success: false, message: 'Please provide recipe id.' });
9+
const id = searchParams.get('id')
1110

1211
const recipe = await Recipe.findOne({
1312
_id: id
1413
});
1514

16-
if (recipe) {
15+
if (await recipe) {
1716
return NextResponse.json({ status: 200, data: recipe });
1817
} else {
1918
return NextResponse.json({ status: 204, success: false, message: 'No recipe found.' });
2019
}
2120
} catch (error) {
2221
console.log('Error in getting recipe by id:', error);
23-
return NextResponse.json({ status: 500, success: false, message: 'Something went wrong. Please try again!' });
22+
return NextResponse.json({ status: 500, success: false, message: error });
2423
}
2524
}

app/api/recipes/route.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ export async function POST(req: Request) {
5151
console.log("recipe", newRecipe)
5252
const recipe = new Recipe(newRecipe);
5353
const save = await recipe.save();
54-
return NextResponse.json(save);
54+
return NextResponse.json({ status: 200, data: save });
5555
} catch (error) {
5656
console.log(error);
5757
return NextResponse.json('error', {

app/recipes/[id]/page.tsx

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,30 +12,22 @@ const SingleRecipe = () => {
1212
undefined
1313
);
1414

15-
// دریافت رسپی با استفاده از شناسه
15+
useEffect(() => {
16+
// دریافت رسپی با استفاده از شناسه
1617
const get_recipe_by_id = async (id: string) => {
1718
try {
1819
const res = await fetch(`/api/recipes/get-single-recipe?id=${id}`, {
1920
method: "GET",
20-
// headers: {
21-
// "Content-Type": "application/json",
22-
// },
2321
});
24-
2522
const data = await res.json();
2623
setSingleRecipe(data.data);
27-
return data;
2824
} catch (error) {
2925
console.log("Error in getting product by ID (service) =>", error);
3026
}
3127
};
32-
33-
useEffect(() => {
3428
get_recipe_by_id(id); // دریافت رسپی با استفاده از شناسه بعد از بارگذاری کامپوننت
3529
}, []);
3630

37-
console.log(singleRecipe); // نمایش اطلاعات رسپی در کنسول
38-
3931
return (
4032
<>
4133
{/* استفاده از کامپوننت SingleRecipeTopSection برای نمایش بخش بالایی رسپی */}

app/recipes/create/page.tsx

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ export default function CreateRecipe() {
1919
const [singleIngredient, setSingleIngredient] = useState("");
2020
const [ingredients, setIngredients] = useState<Ingredients[]>([]);
2121
const [selectedPhoto, setSelectedPhoto] = useState<File | null>(null);
22+
const [loading, setLoading] = useState(true)
2223

2324
// تابع handlePhotoChange برای مدیریت تغییرات در ورودی عکس
2425
const handlePhotoChange = (event: ChangeEvent<HTMLInputElement>) => {
@@ -48,7 +49,7 @@ export default function CreateRecipe() {
4849
// تابع saveRecipe برای ارسال داده‌ها به سرور و ذخیره رسپی جدید
4950
const saveRecipe = async (event: FormEvent) => {
5051
event.preventDefault();
51-
52+
setLoading(true)
5253
if (selectedPhoto) {
5354
const formData = new FormData();
5455
formData.append("photo", selectedPhoto);
@@ -63,11 +64,13 @@ export default function CreateRecipe() {
6364
};
6465
try {
6566
const saveRecip = await fetch("/api/recipes", options);
66-
console.log(saveRecip);
67+
setLoading(false)
68+
if (saveRecip.status === 200) {
69+
console.log(saveRecip);
70+
}
6771
} catch (error) {
72+
setLoading(false)
6873
console.log(error);
69-
70-
7174
}
7275
}
7376
};
@@ -82,11 +85,10 @@ export default function CreateRecipe() {
8285
<div className="text-center w-full mx-auto py-12 px-4 sm:px-6 lg:py-16 lg:px-8 z-20">
8386
<h2 className="text-3xl font-extrabold text-black dark:text-white sm:text-4xl">
8487
<span className="text-gray-600">
85-
اون رسپی که میخوای نیست؟
86-
</span>
87-
<span className="block text-indigo-500">
88-
خودت اضافه اش کن
88+
اضافه کردن رسپی جدید
8989
</span>
90+
{/* <span className="block text-indigo-500">
91+
</span> */}
9092
</h2>
9193
</div>
9294
</div>
@@ -182,7 +184,7 @@ export default function CreateRecipe() {
182184
type="submit"
183185
className="w-96 py-3 px-4 inline-flex justify-center items-center gap-2 rounded-md border border-transparent font-semibold bg-cyan-700 text-white hover:bg-cyan-500 focus:outline-none focus:ring-2 focus:ring-cyan-500 focus:ring-offset-2 transition-all text-sm"
184186
>
185-
<span>اضافه کن</span>
187+
<span>ساخت رسپی</span>
186188
</Button>
187189
</div>
188190
</form>

components/RecipeCard.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,10 @@ const RecipeCard = ({ recipe }: RecipeCardProps) => {
2626
className="rounded-t-lg w-full h-[220px]"
2727
/>
2828
<div className="relative w-full p-4 bg-white">
29-
<p className="mb-2 text-xl font-medium text-gray-800">
29+
<p className="mb-2 text-lg font-medium text-gray-800">
3030
{recipe?.name}
3131
</p>
32-
<p className="text-xs text-gray-600">{recipe?.description}</p>
32+
<p className="text-xs text-gray-600">{recipe?.description.substring(0, 60)}...</p>
3333
<div className="flex flex-wrap items-center mt-6 justify-starts">
3434
<Button
3535
type="button"

components/SingleRecipeMain.tsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@ const SingleRecipeMain = ({
1717
recipeIngredients,
1818
recipeSteps,
1919
}: SingleRecipeMainProps) => {
20-
// console.log(JSON.parse(recipeIngredients));
21-
2220
return (
2321
<>
2422
<div className="md:container md:mx-auto">

0 commit comments

Comments
 (0)