Skip to content
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

Sample app frontend #5931

Merged
merged 11 commits into from Apr 5, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
@@ -0,0 +1,3 @@
{
"extends": "next/core-web-vitals"
}
36 changes: 36 additions & 0 deletions code-samples/eventing/bookstore-sample-app/frontend/.gitignore
@@ -0,0 +1,36 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.

# dependencies
/node_modules
/.pnp
.pnp.js
.yarn/install-state.gz

# testing
/coverage

# next.js
/.next/
/out/

# production
/build

# misc
.DS_Store
*.pem

# debug
npm-debug.log*
yarn-debug.log*
yarn-error.log*

# local env files
.env*.local

# vercel
.vercel

# typescript
*.tsbuildinfo
next-env.d.ts
37 changes: 37 additions & 0 deletions code-samples/eventing/bookstore-sample-app/frontend/README.md
ctmphuongg marked this conversation as resolved.
Show resolved Hide resolved
Copy link
Member

Choose a reason for hiding this comment

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

The README.md looks great! But just a note here: it might need to be changed when the sample app approaches to the end!! If it got changed, it doesn't mean your README.md is wrong!!

@@ -0,0 +1,37 @@
This is a [Next.js](https://nextjs.org/) project bootstrapped with [`create-next-app`](https://github.com/vercel/next.js/tree/canary/packages/create-next-app).

## Getting Started

Before running, may need to install node >= v18, next-themes
First, run the development server:

```bash
npm run dev
# or
yarn dev
# or
pnpm dev
# or
bun dev
```

Open [http://localhost:3000](http://localhost:3000) with your browser to see the result.

You can start editing the page by modifying `app/page.tsx`. The page auto-updates as you edit the file.

This project uses [`next/font`](https://nextjs.org/docs/basic-features/font-optimization) to automatically optimize and load Inter, a custom Google Font.

## Learn More

To learn more about Next.js, take a look at the following resources:

- [Next.js Documentation](https://nextjs.org/docs) - learn about Next.js features and API.
- [Learn Next.js](https://nextjs.org/learn) - an interactive Next.js tutorial.

You can check out [the Next.js GitHub repository](https://github.com/vercel/next.js/) - your feedback and contributions are welcome!

## Deploy on Vercel

The easiest way to deploy your Next.js app is to use the [Vercel Platform](https://vercel.com/new?utm_medium=default-template&filter=next.js&utm_source=create-next-app&utm_campaign=create-next-app-readme) from the creators of Next.js.

Check out our [Next.js deployment documentation](https://nextjs.org/docs/deployment) for more details.
ctmphuongg marked this conversation as resolved.
Show resolved Hide resolved
Binary file not shown.
@@ -0,0 +1,59 @@
@tailwind base;
@tailwind components;
@tailwind utilities;

@import url('https://fonts.googleapis.com/css2?family=Poppins:wght@400;500;600;700&display=swap');

/* :root {
--foreground-rgb: 0, 0, 0;
--background-start-rgb: 214, 219, 220;
--background-end-rgb: 255, 255, 255;
}*/

/* .comment-display {
--bg-cmt: #323232;
--text-cmt: white;
}

@media (prefers-color-scheme: dark) {
.comment-display {
--bg-cmt: #e3e2e2;
--text-cmt: black;
}
} */

/* @layer base {
.comment-display {
@apply dark:bg-white bg-gray-800;
@apply dark:text-black text-white;
}
} */

#__next {
min-height: 100vh;
width: 100%;
display: flex;
flex-direction: column;
}

body {
font-family: 'Poppins', sans-serif;
/* color: rgb(var(--foreground-rgb)); */
/* background: linear-gradient(
to bottom,
transparent,
rgb(var(--background-end-rgb))
) */
/* background: rgb(var(--background-start-rgb)); */
}

@layer utilities {
.text-balance {
text-wrap: balance;
}
}

/* .comment-display {
background: rgb(var(--bg-cmt));
text-decoration-color: rgb(var(--text-cmt));
} */
22 changes: 22 additions & 0 deletions code-samples/eventing/bookstore-sample-app/frontend/app/layout.tsx
@@ -0,0 +1,22 @@
import type { Metadata } from "next";
import { Inter } from "next/font/google";
import "./globals.css";

const inter = Inter({ subsets: ["latin"] });

export const metadata: Metadata = {
title: "Create Next App",
description: "Generated by create next app",
};

export default function RootLayout({
children,
}: Readonly<{
children: React.ReactNode;
}>) {
return (
<html lang="en">
<body className={inter.className}>{children}</body>
</html>
);
}
14 changes: 14 additions & 0 deletions code-samples/eventing/bookstore-sample-app/frontend/app/page.tsx
@@ -0,0 +1,14 @@
'use client';
import Image from 'next/image';
import Main from '../client/pages/Main';
// import { keepTheme } from '../client/utils/themes';
ctmphuongg marked this conversation as resolved.
Show resolved Hide resolved
import { useEffect } from 'react';
import { ThemeProvider } from 'next-themes';

export default function Home() {
return (
<ThemeProvider>
<Main />
</ThemeProvider>
);
}
@@ -0,0 +1,48 @@
const BookDetail = ({ book }) => {
// Assume receiving a book object
return (
<div className='flex flex-col md:flex-row md:items-start p-8 space-x-8 justify-center items-center font-sans'>
<div className='mb-4 md:mb-0 md:mr-8'>
<img
src='/images/Bookcover.png'
alt='Book Cover'
className='w-48 h-auto'
/>
</div>
<div>
<div className='space-y-4'>
<div className='grid grid-cols-2 items-center'>
<span className='font-bold text-left pr-3'>Title:</span>
<span className='text-left'>{book.title}</span>
</div>
<div className='grid grid-cols-2 items-center'>
<span className='font-bold text-left pr-4'>Author:</span>
<span className='text-left'>{book.author}</span>
</div>
<div className='grid grid-cols-2 items-center'>
<span className='font-bold text-left pr-4'>ISBN:</span>
<span>{book.ISBN}</span>
</div>
<div className='grid grid-cols-2 items-center'>
<span className='font-bold text-left pr-4'>Publisher:</span>
<span>{book.publisher}</span>
</div>
<div className='grid grid-cols-2 items-center'>
<span className='font-bold text-left pr-4'>Published Date:</span>
<span>{book.publishedDate}</span>
</div>
<div className='grid grid-cols-2 items-center'>
<span className='font-bold text-left pr-4'>Description:</span>
<span>{book.description}</span>
</div>
<div className='grid grid-cols-2 items-center'>
<span className='font-bold text-left pr-4'>Price:</span>
<span>{book.price}</span>
</div>
</div>
</div>
</div>
);
};

export default BookDetail;
@@ -0,0 +1,22 @@
const CommentDisplay = ({ comment }) => {
// Assume receiving a comment object
return (
<div className='flex my-4 p-4 justify-center'>
{/* Customized darkmode not working as expected yet */}
<div className='comment-display w-full w-7/12 flex flex-row rounded-lg p-4 bg-gray-800 text-white dark:bg-white'>
ctmphuongg marked this conversation as resolved.
Show resolved Hide resolved
<div className='flex items-center justify-center md:justify-start md:w-1/12'>
<img
src={comment.avatar}
alt='Avatar'
className='rounded-full w-10 h-10'
/>
ctmphuongg marked this conversation as resolved.
Show resolved Hide resolved
</div>
<div className='md:w-1/12 text-sm text-gray-200'> {comment.time} </div>
<div className='md:w-8/12'> {comment.text} </div>
<div className='md:w-2/12'> {comment.emotion} </div>
</div>
ctmphuongg marked this conversation as resolved.
Show resolved Hide resolved
</div>
);
};

export default CommentDisplay;
@@ -0,0 +1,17 @@
import SubmitButton from './SubmitButton';
const CommentForm = () => {
return (
<div className='flex my-4 p-4 justify-center'>
<form className='w-full w-8/12 flex flex-col items-end'>
<textarea
className='form-textarea w-full mb-2 p-2 border border-2 border-black rounded-lg p-4'
rows='3'
placeholder='Leave your comment here...'
></textarea>
<SubmitButton />
</form>
</div>
);
};

export default CommentForm;
@@ -0,0 +1,12 @@
import CommentDisplay from './CommentDisplay';
const CommentList = () => {
const comment = {
avatar: '/images/knative-logo.png',
time: '10:05',
text: 'Good work!',
emotion: 'Happy',
ctmphuongg marked this conversation as resolved.
Show resolved Hide resolved
};
return <CommentDisplay comment={comment} />;
};

export default CommentList;
@@ -0,0 +1,22 @@
import Image from 'next/image';
import Toggle from './Toggle';

const Header = () => {
return (
<div className='flex justify-between p-4'>
<header className='flex items-center p-4'>
<Image
src='/images/knative-logo.png'
alt='Knative BookStore Logo'
width={50}
height={50}
className='mr-2'
/>
<h1 className='text-3xl font-bold'>Knative BookStore</h1>
</header>
<Toggle />
</div>
);
};

export default Header;
@@ -0,0 +1,18 @@
'use-client';
import { useState } from 'react';

export default function SubmitButton() {
const [hover, setHover] = useState(false);

ctmphuongg marked this conversation as resolved.
Show resolved Hide resolved
return (
<button
type='submit'
className={`font-bold py-2 px-9 rounded ${hover ? '' : 'bg-blue-600'}`}
style={{ backgroundColor: hover ? '#A0DDFF' : '#A5D8FF' }}
onMouseEnter={() => setHover(true)}
onMouseLeave={() => setHover(false)}
>
Submit
</button>
);
}
@@ -0,0 +1,19 @@
'use client';
import React from 'react';
import { useTheme } from 'next-themes';

const Toggle = () => {
const { systemTheme, theme, setTheme } = useTheme();
const currentTheme = theme === 'system' ? systemTheme : theme;

ctmphuongg marked this conversation as resolved.
Show resolved Hide resolved
return (
<button
onClick={() => (theme == 'dark' ? setTheme('light') : setTheme('dark'))}
className='bg-gray-800 dark:bg-gray-50 hover:bg-gray-600 dark:hover:bg-gray-300 transition-all duration-100 text-white dark:text-gray-800 px-6 py-1 text-xl md:text-2xl rounded-md'
>
Mode
</button>
);
};

export default Toggle;
@@ -0,0 +1,32 @@
'use client';
import Header from '../components/Header';
import BookDetail from '../components/BookDetail';
import CommentForm from '../components/CommentForm';
import CommentList from '../components/CommentList';
import { ThemeProvider } from 'next-themes';

export default function Main() {
/* Example Book object */
const book = {
title: 'Book Mock Up',
author: 'me',
ISBN: '12342432',
publisher: 'dsfa',
publishedDate: '3333',
description: 'You are my fire! Hello world Im a book',
ctmphuongg marked this conversation as resolved.
Show resolved Hide resolved
price: '$10',
};
return (
<div>
<ThemeProvider attribute='class'>
<Header />

<main className='container mx-auto my-8'>
<BookDetail book={book} />
<CommentForm />
<CommentList />
</main>
</ThemeProvider>
</div>
);
}
@@ -0,0 +1,4 @@
/** @type {import('next').NextConfig} */
const nextConfig = {};

export default nextConfig;