Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
OffyOk committed Jun 2, 2024
1 parent b057a2d commit 6f23fd5
Show file tree
Hide file tree
Showing 15 changed files with 252 additions and 137 deletions.
1 change: 1 addition & 0 deletions pages/.env
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
NEXT_PUBLIC_ANALYTICS_ID=abcdefghijk
19 changes: 19 additions & 0 deletions pages/Event/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import ListenClick from "../components/event/ListenClick";
import Link from "next/link";
import StateHooks from "../components/event/StateHooks";

export default function EventPage() {
return (
<div>
<div className="flex justify-between">
<h4 className="text-xl font-bold decoration-stone-600">
This page is about event listener page
</h4>
<Link href="/">Back</Link>
</div>
<ListenClick />
<p>This is about state, A component memory</p>
<StateHooks />
</div>
);
}
23 changes: 23 additions & 0 deletions pages/Prop/pagsse.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import PropSend from "../components/properties/PropSend";
import PropSendDestructuring from "../components/properties/PropSendes";
import PropCondition from "../components/properties/PropCond";
import PropTernary from "../components/properties/PropTernary";
import { title } from "../utils/const";
import Link from "next/link";

export default function PropPage() {
return (
<div>
<div className="flex justify-between">
<h1 className="text-xl font-bold decoration-stone-600">
This page about how to send property to other component
</h1>
<Link href="/">Back</Link>
</div>
<PropSend title={title.person} />
<PropSendDestructuring title={title.person} />
<PropCondition testprop="testasdf" />
<PropTernary testprops="" />
</div>
);
}
13 changes: 13 additions & 0 deletions pages/components/event/ListenClick.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
export default function ListenClick() {
function handleClick() {
console.log("increment like count");
}
return (
<button
onClick={handleClick}
className="bg-red-500 border border-gray-300 shadow-lg rounded-lg px-4 py-2"
>
Like
</button>
);
}
30 changes: 30 additions & 0 deletions pages/components/event/StateHooks.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { useState } from "react";

export default function StateHooks() {
const [count, setCount] = useState(0);
function handleClick() {
console.log("increment like count");
setCount(count + 1);
}
function handleReset() {
console.log("reset count");
setCount(0);
// setCount((count) => (count = 0)); // can use function to setCount like this
}
return (
<>
<button
onClick={handleClick}
className="bg-red-500 border border-gray-300 shadow-lg rounded-lg px-4 py-2"
>
Like ({count})
</button>
<button
onClick={handleReset}
className="bg-red-500 border border-gray-300 shadow-lg rounded-lg px-4 py-2"
>
reset
</button>
</>
);
}
18 changes: 18 additions & 0 deletions pages/components/properties/PropCond.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
function createTitle(testprop: string) {
if (testprop) {
return testprop;
} else {
return "Default testprop";
}
}

export default function PropCondition({ testprop }: { testprop: string }) {
return (
<>
<h4 className="text-lg font-bold decoration-stone-600">
Condition redering
</h4>
<div>This is Prop with condition: {createTitle(testprop)}</div>
</>
);
}
28 changes: 28 additions & 0 deletions pages/components/properties/PropSend.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { Person, Title } from "../../utils/helper";

export default function PropSend(props: { title: Person[] }) {
console.log("this data from prop:", props);
console.log("Prop type is:", typeof props);
console.log("this data in prop:", props.title);
console.log("Title in Prop type is:", typeof props.title);
// console.log(
// "this data in title:",
// props.title.id,
// props.title.name,
// props.title.description
// );
return (
<div>
<h4 className="text-lg font-bold decoration-stone-600">Passing props to a component</h4>
<ul>
{props.title.map((person, index) => (
<li key={index}>
<div>id: {person.id}</div>
<div>name: {person.name}</div>
<div>description: {person.description}</div>
</li>
))}
</ul>
</div>
);
}
19 changes: 19 additions & 0 deletions pages/components/properties/PropSendes.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { Person } from "../../utils/helper";
export default function PropSendDestructuring({ title }: { title: Person[] }) {
return (
<div className="mt-4">
<h4 className="text-lg font-bold decoration-stone-600">
Passing props to a component,When use destructuring
</h4>
<ul>
{title.map((person, index) => (
<li key={index}>
<div>id: {person.id}</div>
<div>name: {person.name}</div>
<div>description: {person.description}</div>
</li>
))}
</ul>
</div>
);
}
12 changes: 12 additions & 0 deletions pages/components/properties/PropTernary.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
export default function PropTernary({ testprops }: { testprops: string }) {
return (
<>
<h4 className="text-lg font-bold decoration-stone-600">
Condeition Redering,but use Ternary condition
</h4>
<div>
This is Prop with Ternary: {testprops ? testprops : "default value"}
</div>
</>
);
}
121 changes: 14 additions & 107 deletions pages/index.tsx
Original file line number Diff line number Diff line change
@@ -1,117 +1,24 @@
import Image from "next/image";
import { Inter } from "next/font/google";

import Link from "next/link";

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

export default function Home() {
return (
<main
className={`flex min-h-screen flex-col items-center justify-between p-24 ${inter.className}`}
>
<div className="z-10 max-w-5xl w-full items-center justify-between font-mono text-sm lg:flex">
<p className="fixed left-0 top-0 flex w-full justify-center border-b border-gray-300 bg-gradient-to-b from-zinc-200 pb-6 pt-8 backdrop-blur-2xl dark:border-neutral-800 dark:bg-zinc-800/30 dark:from-inherit lg:static lg:w-auto lg:rounded-xl lg:border lg:bg-gray-200 lg:p-4 lg:dark:bg-zinc-800/30">
Get started by editing&nbsp;
<code className="font-mono font-bold">pages/index.tsx</code>
</p>
<div className="fixed bottom-0 left-0 flex h-48 w-full items-end justify-center bg-gradient-to-t from-white via-white dark:from-black dark:via-black lg:static lg:h-auto lg:w-auto lg:bg-none">
<a
className="pointer-events-none flex place-items-center gap-2 p-8 lg:pointer-events-auto lg:p-0"
href="https://vercel.com?utm_source=create-next-app&utm_medium=default-template-tw&utm_campaign=create-next-app"
target="_blank"
rel="noopener noreferrer"
>
By{" "}
<Image
src="/vercel.svg"
alt="Vercel Logo"
className="dark:invert"
width={100}
height={24}
priority
/>
</a>
<main className="flex flex-col items-center">
<div className="container">
<div>
<h1 className={inter.className}>Practice this all</h1>
</div>
<div className="flex flex-col border rounded-lg border-gray-500 rounded-lg p-3">
<Link href="/Prop" className="hover:underline">
Send Props Page
</Link>
<Link href="/Event" className="hover:underline">
Listerner Page
</Link>
</div>
</div>

<div className="relative flex place-items-center before:absolute before:h-[300px] before:w-full sm:before:w-[480px] before:-translate-x-1/2 before:rounded-full before:bg-gradient-radial before:from-white before:to-transparent before:blur-2xl before:content-[''] after:absolute after:-z-20 after:h-[180px] after:w-full sm:after:w-[240px] after:translate-x-1/3 after:bg-gradient-conic after:from-sky-200 after:via-blue-200 after:blur-2xl after:content-[''] before:dark:bg-gradient-to-br before:dark:from-transparent before:dark:to-blue-700/10 after:dark:from-sky-900 after:dark:via-[#0141ff]/40 before:lg:h-[360px]">
<Image
className="relative dark:drop-shadow-[0_0_0.3rem_#ffffff70] dark:invert"
src="/next.svg"
alt="Next.js Logo"
width={180}
height={37}
priority
/>
</div>

<div className="mb-32 grid text-center lg:max-w-5xl lg:w-full lg:mb-0 lg:grid-cols-4 lg:text-left">
<a
href="https://nextjs.org/docs?utm_source=create-next-app&utm_medium=default-template-tw&utm_campaign=create-next-app"
className="group rounded-lg border border-transparent px-5 py-4 transition-colors hover:border-gray-300 hover:bg-gray-100 hover:dark:border-neutral-700 hover:dark:bg-neutral-800/30"
target="_blank"
rel="noopener noreferrer"
>
<h2 className={`mb-3 text-2xl font-semibold`}>
Docs{" "}
<span className="inline-block transition-transform group-hover:translate-x-1 motion-reduce:transform-none">
-&gt;
</span>
</h2>
<p className={`m-0 max-w-[30ch] text-sm opacity-50`}>
Find in-depth information about Next.js features and API.
</p>
</a>

<a
href="https://nextjs.org/learn?utm_source=create-next-app&utm_medium=default-template-tw&utm_campaign=create-next-app"
className="group rounded-lg border border-transparent px-5 py-4 transition-colors hover:border-gray-300 hover:bg-gray-100 hover:dark:border-neutral-700 hover:dark:bg-neutral-800/30"
target="_blank"
rel="noopener noreferrer"
>
<h2 className={`mb-3 text-2xl font-semibold`}>
Learn{" "}
<span className="inline-block transition-transform group-hover:translate-x-1 motion-reduce:transform-none">
-&gt;
</span>
</h2>
<p className={`m-0 max-w-[30ch] text-sm opacity-50`}>
Learn about Next.js in an interactive course with&nbsp;quizzes!
</p>
</a>

<a
href="https://vercel.com/templates?framework=next.js&utm_source=create-next-app&utm_medium=default-template-tw&utm_campaign=create-next-app"
className="group rounded-lg border border-transparent px-5 py-4 transition-colors hover:border-gray-300 hover:bg-gray-100 hover:dark:border-neutral-700 hover:dark:bg-neutral-800/30"
target="_blank"
rel="noopener noreferrer"
>
<h2 className={`mb-3 text-2xl font-semibold`}>
Templates{" "}
<span className="inline-block transition-transform group-hover:translate-x-1 motion-reduce:transform-none">
-&gt;
</span>
</h2>
<p className={`m-0 max-w-[30ch] text-sm opacity-50`}>
Discover and deploy boilerplate example Next.js&nbsp;projects.
</p>
</a>

<a
href="https://vercel.com/new?utm_source=create-next-app&utm_medium=default-template-tw&utm_campaign=create-next-app"
className="group rounded-lg border border-transparent px-5 py-4 transition-colors hover:border-gray-300 hover:bg-gray-100 hover:dark:border-neutral-700 hover:dark:bg-neutral-800/30"
target="_blank"
rel="noopener noreferrer"
>
<h2 className={`mb-3 text-2xl font-semibold`}>
Deploy{" "}
<span className="inline-block transition-transform group-hover:translate-x-1 motion-reduce:transform-none">
-&gt;
</span>
</h2>
<p className={`m-0 max-w-[30ch] text-sm opacity-50 text-balance`}>
Instantly deploy your Next.js site to a shareable URL with Vercel.
</p>
</a>
</div>
</main>
);
Expand Down
12 changes: 12 additions & 0 deletions pages/middlewares.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { NextResponse } from 'next/server'
import type { NextRequest } from 'next/server'

// This function can be marked `async` if using `await` inside
export function middleware(request: NextRequest) {
return NextResponse.redirect(new URL('/home', request.url))
}

// See "Matching Paths" below to learn more
export const config = {
matcher: '/about/:path*',
}
27 changes: 27 additions & 0 deletions pages/utils/const.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { Title } from "./helper";

export const title: Title = {
response: "ok",
person: [
{
id: 1,
name: "offy",
description: "lorem offy asdf",
},
{
id: 2,
name: "bam",
description: "lorem bam asdf",
},
{
id: 3,
name: "nan",
description: "lorem nan fdas",
},
{
id: 4,
name: "edith",
description: "lorem edith fdaf",
},
],
};
11 changes: 11 additions & 0 deletions pages/utils/helper.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
export interface Title {
response:string,
person: Person[]
}


export interface Person {
id: number;
name: string;
description: string;
}
25 changes: 25 additions & 0 deletions public/const.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
const title: Title = {
response: "ok",
person: [
{
id: 1,
name: "offy",
description: "lorem offy asdf",
},
{
id: 2,
name: "bam",
description: "lorem bam asdf",
},
{
id: 3,
name: "nan",
description: "lorem nan fdas",
},
{
id: 4,
name: "edith",
description: "lorem edith fdaf",
},
],
};
Loading

0 comments on commit 6f23fd5

Please sign in to comment.