Skip to content

Commit

Permalink
Merge pull request #1 from catawiki/sd-add-vulnerabilities
Browse files Browse the repository at this point in the history
Add vulnerabilities
  • Loading branch information
sdimitrijevikj authored Sep 25, 2024
2 parents cfd2a96 + d3f0c86 commit 466cec8
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 40 deletions.
52 changes: 52 additions & 0 deletions pages/comments.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
// pages/comments.js

import { useState, useEffect } from 'react';

export default function Comments() {
const [comments, setComments] = useState([]);
const [newComment, setNewComment] = useState('');

useEffect(() => {
// Load comments from local storage when the component mounts
const savedComments = JSON.parse(localStorage.getItem('comments')) || [];
setComments(savedComments);
}, []);

const handleAddComment = () => {
if (newComment.trim() === '') return;

const updatedComments = [...comments, newComment];
setComments(updatedComments);
setNewComment('');
localStorage.setItem('comments', JSON.stringify(updatedComments));
};

const handleRemoveComment = (index) => {
const updatedComments = comments.filter((_, i) => i !== index);
setComments(updatedComments);
localStorage.setItem('comments', JSON.stringify(updatedComments));
};

return (
<div>
<h1>Comments</h1>
<div>
<input
type="text"
value={newComment}
onChange={(e) => setNewComment(e.target.value)}
placeholder="Add a comment"
/>
<button onClick={handleAddComment}>Submit</button>
</div>
<ul>
{comments.map((comment, index) => (
<li key={index}>
{comment}
<button onClick={() => handleRemoveComment(index)}>Remove</button>
</li>
))}
</ul>
</div>
);
}
69 changes: 29 additions & 40 deletions pages/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,18 @@
import Head from 'next/head';
import Link from 'next/link';
import { useState, useEffect } from 'react';

import styles from '../styles/Home.module.css';

export default function Home() {
const [comments, setComments] = useState([]);

useEffect(() => {
// Load comments from local storage when the component mounts
const savedComments = JSON.parse(localStorage.getItem('comments')) || [];
setComments(savedComments);
}, []);

return (
<div className={styles.container}>
<Head>
Expand All @@ -11,53 +22,31 @@ export default function Home() {

<main>
<h1 className={styles.title}>
Welcome to <a href="https://nextjs.org">Next.js!</a>
Playground project
</h1>

<p className={styles.description}>
Get started by editing <code>pages/index.js</code>
</p>
<nav>
<ul>
<li>
<Link href="/comments">
Add a comment
</Link>
</li>
</ul>
</nav>

<div className={styles.grid}>
<a href="https://nextjs.org/docs" className={styles.card}>
<h3>Documentation &rarr;</h3>
<p>Find in-depth information about Next.js features and API.</p>
</a>

<a href="https://nextjs.org/learn" className={styles.card}>
<h3>Learn &rarr;</h3>
<p>Learn about Next.js in an interactive course with quizzes!</p>
</a>

<a
href="https://github.com/vercel/next.js/tree/canary/examples"
className={styles.card}
>
<h3>Examples &rarr;</h3>
<p>Discover and deploy boilerplate example Next.js projects.</p>
</a>

<a
href="https://vercel.com/import?filter=next.js&utm_source=create-next-app&utm_medium=default-template&utm_campaign=create-next-app"
className={styles.card}
>
<h3>Deploy &rarr;</h3>
<p>
Instantly deploy your Next.js site to a public URL with Vercel.
</p>
</a>
</div>
<h2>Comments</h2>
<ul>
{comments.map((comment, index) => (
<li key={`${index}-comment`}>{comment}</li>
))}
</ul>
<div>
</div>
</main>

<footer>
<a
href="https://vercel.com?utm_source=create-next-app&utm_medium=default-template&utm_campaign=create-next-app"
target="_blank"
rel="noopener noreferrer"
>
Powered by{' '}
<img src="/vercel.svg" alt="Vercel" className={styles.logo} />
</a>
</footer>

<style jsx>{`
Expand Down

0 comments on commit 466cec8

Please sign in to comment.