Skip to content

Commit 2dbec23

Browse files
authored
Merge pull request #140 from CodeSpace-Academy/main
bringing over changes from old repo
2 parents acd7659 + c7540e7 commit 2dbec23

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+9088
-1027
lines changed

.github/workflows/linting.yml

Lines changed: 27 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -13,30 +13,32 @@ jobs:
1313
strategy:
1414
matrix:
1515
node-version: [18.x, 20.x, 22.x]
16-
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/
1716

18-
steps:
19-
- uses: actions/checkout@v4
20-
21-
- name: Use Node.js ${{ matrix.node-version }}
22-
uses: actions/setup-node@v4
23-
with:
24-
node-version: ${{ matrix.node-version }}
25-
cache: 'npm'
26-
27-
- name: Cache node modules
28-
uses: actions/[email protected]
29-
with:
30-
path: node_modules
31-
key: node-modules-${{ runner.os }}-node-${{ matrix.node-version }}-${{ hashFiles('package-lock.json') }}
32-
restore-keys: |
33-
node-modules-${{ runner.os }}-node-${{ matrix.node-version }}
17+
env: # Set environment variables at the job level
18+
MONGODB_URI: ${{ secrets.MONGODB_URI }} # Ensure this is correctly set
3419

35-
# Install dependencies with --legacy-peer-deps to avoid peer conflict issues
36-
- run: npm ci --legacy-peer-deps
37-
38-
# Linting step
39-
- run: npm run lint
40-
41-
# Build step
42-
- run: npm run build --if-present
20+
steps:
21+
- uses: actions/checkout@v4
22+
- name: Use Node.js ${{ matrix.node-version }}
23+
uses: actions/setup-node@v4
24+
with:
25+
node-version: ${{ matrix.node-version }}
26+
cache: 'npm'
27+
- name: Debug MongoDB URI
28+
run: echo "MONGODB_URI is set to: $MONGODB_URI" # Use the env variable instead of the secret directly
29+
env:
30+
MONGODB_URI: ${{ secrets.MONGODB_URI }}
31+
- name: Cache node modules
32+
uses: actions/[email protected]
33+
with:
34+
path: node_modules
35+
key: node-modules-${{ runner.os }}-node-${{ matrix.node-version }}-${{ hashFiles('package-lock.json') }}
36+
restore-keys: |
37+
node-modules-${{ runner.os }}-node-${{ matrix.node-version }}
38+
- run: npm ci --legacy-peer-deps
39+
- run: npm run lint
40+
- run: npm run build --if-present
41+
- name: Run tests
42+
run: |
43+
cd backend
44+
npx mocha --config .mocharc.json

.storybook/main.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import type { StorybookConfig } from "@storybook/nextjs";
2+
3+
const config: StorybookConfig = {
4+
stories: [
5+
"../app/components/**/*.mdx",
6+
"../app/components/**/*.stories.@(js|jsx|mjs|ts|tsx)",
7+
"../app/components/**/**/*.mdx",
8+
"../app/components/**/**/*.stories.@(js|jsx|mjs|ts|tsx)",
9+
"../app/components/stories/**/*.mdx",
10+
"../app/components/stories/**/*.stories.@(js|jsx|mjs|ts|tsx)",
11+
"../app/components/stories/*.mdx",
12+
"../app/components/stories/*.stories.@(js|jsx|mjs|ts|tsx)",
13+
],
14+
addons: [
15+
"@storybook/addon-onboarding",
16+
"@storybook/addon-links",
17+
"@storybook/addon-essentials",
18+
"@chromatic-com/storybook",
19+
"@storybook/addon-interactions",
20+
"@storybook/addon-styling-webpack"
21+
],
22+
framework: {
23+
name: "@storybook/nextjs",
24+
options: {},
25+
},
26+
};
27+
export default config;

.storybook/preview.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// .storybook/preview.js
2+
3+
import type { Preview } from "@storybook/react";
4+
import '../app/global.css';
5+
6+
const preview: Preview = {
7+
parameters: {
8+
controls: {
9+
matchers: {
10+
color: /(background|color)$/i,
11+
date: /Date$/i,
12+
},
13+
},
14+
},
15+
};
16+
17+
export default preview;
18+

Public/ArejengLogo.png

29.3 KB
Loading

Public/apple-touch-icon.png

9.96 KB
Loading

Public/favicon-48x48.png

1.52 KB
Loading

Public/favicon.ico

14.7 KB
Binary file not shown.

Public/favicon.svg

Lines changed: 3 additions & 0 deletions
Loading

Public/site.webmanifest

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"name": "MyWebSite",
3+
"short_name": "MySite",
4+
"icons": [
5+
{
6+
"src": "/web-app-manifest-192x192.png",
7+
"sizes": "192x192",
8+
"type": "image/png",
9+
"purpose": "maskable"
10+
},
11+
{
12+
"src": "/web-app-manifest-512x512.png",
13+
"sizes": "512x512",
14+
"type": "image/png",
15+
"purpose": "maskable"
16+
}
17+
],
18+
"theme_color": "#ffffff",
19+
"background_color": "#ffffff",
20+
"display": "standalone"
21+
}

Public/web-app-manifest-192x192.png

11.1 KB
Loading

Public/web-app-manifest-512x512.png

50.3 KB
Loading

app/api/categories/route.js

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
import clientPromise from "../../../lib/mongodb";
2+
3+
/**
4+
* API route handler for fetching all unique categories from the recipes collection.
5+
* File location: app/api/categories/route.js
6+
*
7+
* @async
8+
* @function
9+
* @returns {Promise<void>} Sends a JSON response containing all unique categories or an error message.
10+
*/
11+
export async function GET() {
12+
try {
13+
// Connect to MongoDB
14+
const client = await clientPromise;
15+
const db = client.db("devdb");
16+
17+
// Fetch all unique categories
18+
const categories = await db.collection("recipes").distinct("category");
19+
20+
// Log the results for debugging
21+
console.log('\n=== Categories Fetch Results ===');
22+
console.log('Total categories found:', categories.length);
23+
console.log('Categories:', categories);
24+
25+
// Return successful response
26+
return new Response(
27+
JSON.stringify({
28+
success: true,
29+
categories,
30+
total: categories.length
31+
}),
32+
{
33+
status: 200,
34+
headers: {
35+
'Content-Type': 'application/json'
36+
}
37+
}
38+
);
39+
40+
} catch (error) {
41+
// Log any errors
42+
console.error('Failed to fetch categories:', error);
43+
44+
// Return error response
45+
return new Response(
46+
JSON.stringify({
47+
success: false,
48+
error: "Failed to fetch categories",
49+
details: process.env.NODE_ENV === 'development' ? error.message : undefined
50+
}),
51+
{
52+
status: 500,
53+
headers: {
54+
'Content-Type': 'application/json'
55+
}
56+
}
57+
);
58+
}
59+
}

app/api/recipes/route.js

Lines changed: 15 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,30 @@
11
import clientPromise from "../../../lib/mongodb";
22

33
/**
4-
* API route handler for fetching paginated recipes from the 'recipes' collection in MongoDB.
4+
* API route handler for fetching all recipes from the 'recipes' collection in MongoDB.
55
*
66
* @async
77
* @function
8-
* @param {Object} req - The request object containing query parameters for pagination.
9-
* @returns {Promise<void>} Sends a JSON response containing the paginated recipes or an error message.
8+
* @param {Object} _req - The request object (not used in this case).
9+
* @param {Object} res - The response object used to send back the result.
10+
* @returns {Promise<void>} Sends a JSON response containing the fetched recipes or an error message.
1011
*/
11-
export async function GET(req) {
12+
export async function GET (req) {
1213
try {
1314
// Await the MongoDB client connection
1415
const client = await clientPromise;
15-
const db = client.db("devdb"); // Connect to the 'devdb' database
16+
const db = client.db('devdb'); // Connect to the 'devdb' database
1617

17-
// Parse the 'page' and 'limit' query parameters from the URL, with defaults
18-
const url = new URL(req.url);
19-
const page = parseInt(url.searchParams.get("page") || "1", 10);
20-
const limit = parseInt(url.searchParams.get("limit") || "20", 10);
21-
22-
// Calculate the number of documents to skip for pagination
23-
const skip = (page - 1) * limit;
24-
25-
// Fetch the paginated recipes from the collection
26-
const recipes = await db.collection("recipes")
27-
.find({})
28-
.skip(skip)
29-
.limit(limit)
30-
.toArray();
18+
// Fetch all documents from the 'recipes' collection and convert them to an array
19+
const recipes = await db.collection('recipes').find({}).limit(100).toArray();
3120

3221
// Send a 200 (OK) response with the fetched recipes in JSON format
33-
return new Response(JSON.stringify({ recipes }), { status: 200 });
22+
return new Response(JSON.stringify({ recipes}), { status: 200 });
3423
} catch (e) {
35-
36-
37-
return new Response(JSON.stringify({ error: "Failed to fetch data" }), { status: 500 });
24+
// Log the error to the console for debugging
25+
console.error(e);
26+
27+
// Send a 500 (Internal Server Error) response with an error message
28+
return new Response(JSON.stringify({error: 'Failed to fetch data'}), { status: 500 });
3829
}
39-
}
30+
};

app/components/CookTimeIcon.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
export function CookTimeIcon() {
2+
return (
3+
<svg fill="#000000" width="25px" height="25px" viewBox="0 0 512.853 512.853" xmlns="http://www.w3.org/2000/svg">
4+
<g>
5+
{/* Your SVG path data here */}
6+
</g>
7+
</svg>
8+
);
9+
}
10+

app/components/PrepTimeIcon.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
export function PrepTimeIcon() {
2+
return (
3+
<svg fill="#000000" width="25px" height="25px" viewBox="0 0 128 128" xmlns="http://www.w3.org/2000/svg">
4+
<g>
5+
{/* Your SVG path data here */}
6+
</g>
7+
</svg>
8+
);
9+
}
10+

app/components/RecipeCard.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import Link from "next/link";
22
import Carousel from "./Carousel";
33

4-
export default function RecipeCard({ recipe }) {
4+
export default function RecipeCard(recipe) {
55
const formatDate = (dateString) => {
66
const options = { year: "numeric", month: "long", day: "numeric" };
77
const date = new Date(dateString);
@@ -113,4 +113,4 @@ export default function RecipeCard({ recipe }) {
113113
</div>
114114
</div>
115115
);
116-
}
116+
}

app/components/RecipeCard.stories.js

Lines changed: 27 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,39 @@
1-
import { RecipeCard } from './RecipeCard';
1+
// RecipeCard.stories.js
2+
import RecipeCard from "./RecipeCard";
23

3-
// More on how to set up stories at: https://storybook.js.org/docs/writing-stories#default-export
4-
export default {
5-
title: 'Example/RecipeCard',
4+
// Mock data for the RecipeCard
5+
const mockRecipe = {
6+
title: "Classic Spaghetti Carbonara",
7+
prep: 15,
8+
cook: 30,
9+
images: [
10+
"https://images.unsplash.com/photo-1481931098730-318b6f776db0?q=80&w=2790&auto=format&fit=crop&ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D",
11+
],
12+
published: "2023-09-15",
13+
};
14+
15+
16+
const meta = {
17+
title: "RecipeCard/RecipeCard",
618
component: RecipeCard,
719
parameters: {
8-
// Optional parameter to center the component in the Canvas. More info: https://storybook.js.org/docs/configure/story-layout
9-
layout: 'centered',
20+
layout: "centered",
1021
},
11-
// This component will have an automatically generated Autodocs entry: https://storybook.js.org/docs/writing-docs/autodocs
12-
tags: ['autodocs'],
13-
// More on argTypes: https://storybook.js.org/docs/api/argtypes
22+
tags: ["autodocs"],
1423
argTypes: {
15-
backgroundColor: { control: 'color' },
24+
title: { control: 'text' },
25+
prep: { control: 'number' },
26+
cook: { control: 'number' },
27+
images: { control: 'array' },
28+
published: { control: 'date' },
1629
},
30+
args: { ...mockRecipe },
1731
};
1832

19-
// More on writing stories with args: https://storybook.js.org/docs/writing-stories/args
33+
export default meta;
34+
2035
export const Primary = {
2136
args: {
22-
primary: true,
23-
label: 'Button',
37+
...mockRecipe
2438
},
2539
};
26-

0 commit comments

Comments
 (0)