mirror of
https://github.com/0xShay/halflink.git
synced 2026-01-11 13:13:25 +00:00
Add frontend template with dummy data
This commit is contained in:
41
frontend/.gitignore
vendored
Normal file
41
frontend/.gitignore
vendored
Normal file
@@ -0,0 +1,41 @@
|
||||
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
|
||||
|
||||
# dependencies
|
||||
/node_modules
|
||||
/.pnp
|
||||
.pnp.*
|
||||
.yarn/*
|
||||
!.yarn/patches
|
||||
!.yarn/plugins
|
||||
!.yarn/releases
|
||||
!.yarn/versions
|
||||
|
||||
# testing
|
||||
/coverage
|
||||
|
||||
# next.js
|
||||
/.next/
|
||||
/out/
|
||||
|
||||
# production
|
||||
/build
|
||||
|
||||
# misc
|
||||
.DS_Store
|
||||
*.pem
|
||||
|
||||
# debug
|
||||
npm-debug.log*
|
||||
yarn-debug.log*
|
||||
yarn-error.log*
|
||||
.pnpm-debug.log*
|
||||
|
||||
# env files (can opt-in for committing if needed)
|
||||
.env*
|
||||
|
||||
# vercel
|
||||
.vercel
|
||||
|
||||
# typescript
|
||||
*.tsbuildinfo
|
||||
next-env.d.ts
|
||||
36
frontend/README.md
Normal file
36
frontend/README.md
Normal file
@@ -0,0 +1,36 @@
|
||||
This is a [Next.js](https://nextjs.org) project bootstrapped with [`create-next-app`](https://nextjs.org/docs/app/api-reference/cli/create-next-app).
|
||||
|
||||
## Getting Started
|
||||
|
||||
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/app/building-your-application/optimizing/fonts) to automatically optimize and load [Geist](https://vercel.com/font), a new font family for Vercel.
|
||||
|
||||
## 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/app/building-your-application/deploying) for more details.
|
||||
9
frontend/app/globals.css
Normal file
9
frontend/app/globals.css
Normal file
@@ -0,0 +1,9 @@
|
||||
@import url('https://fonts.googleapis.com/css2?family=Nova+Oval&display=swap');
|
||||
|
||||
@import "tailwindcss";
|
||||
|
||||
.nova-oval-regular {
|
||||
font-family: "Nova Oval", system-ui;
|
||||
font-weight: 400;
|
||||
font-style: normal;
|
||||
}
|
||||
21
frontend/app/layout.tsx
Normal file
21
frontend/app/layout.tsx
Normal file
@@ -0,0 +1,21 @@
|
||||
import type { Metadata } from "next";
|
||||
import "./globals.css";
|
||||
|
||||
export const metadata: Metadata = {
|
||||
title: "Halflink",
|
||||
description: "Shorten links with the click of a button.",
|
||||
};
|
||||
|
||||
export default function RootLayout({
|
||||
children,
|
||||
}: Readonly<{
|
||||
children: React.ReactNode;
|
||||
}>) {
|
||||
return (
|
||||
<html lang="en">
|
||||
<body className="nova-oval-regular">
|
||||
{children}
|
||||
</body>
|
||||
</html>
|
||||
);
|
||||
}
|
||||
25
frontend/app/manage/page.tsx
Normal file
25
frontend/app/manage/page.tsx
Normal file
@@ -0,0 +1,25 @@
|
||||
export default function Home() {
|
||||
return (
|
||||
<div className="flex min-h-screen flex-col items-center py-2">
|
||||
<h1 className="text-3xl font-bold mt-16">halflink</h1>
|
||||
<p>Shorten a link with ease.</p>
|
||||
|
||||
<h2 className="text-2xl font-bold mt-8">Manage your link</h2>
|
||||
|
||||
<form className="mt-4 flex w-full max-w-md">
|
||||
<input
|
||||
type="text"
|
||||
placeholder="Enter your long URL here"
|
||||
className="flex-grow border border-gray-300 rounded-l px-4 py-2 focus:outline-none focus:ring-2 focus:ring-blue-500"
|
||||
/>
|
||||
<button
|
||||
type="submit"
|
||||
className="bg-blue-500 text-white px-4 py-2 rounded-r hover:bg-blue-600 focus:outline-none focus:ring-2 focus:ring-blue-500"
|
||||
>
|
||||
Shorten
|
||||
</button>
|
||||
</form>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
109
frontend/app/page.tsx
Normal file
109
frontend/app/page.tsx
Normal file
@@ -0,0 +1,109 @@
|
||||
'use client';
|
||||
|
||||
import { useState } from "react";
|
||||
import { shortenLink } from "./utils/shortenLink";
|
||||
import { Clipboard, Minimize2 } from "lucide-react";
|
||||
|
||||
export default function Home() {
|
||||
const [errorMessage, setErrorMessage] = useState<string | null>(null);
|
||||
const [successMessage, setSuccessMessage] = useState<string | null>(null);
|
||||
|
||||
const [shortUrl, setShortUrl] = useState<string | null>(null);
|
||||
const [manageUrl, setManageUrl] = useState<string | null>(null);
|
||||
|
||||
async function handleSubmit(event: React.FormEvent<HTMLFormElement>) {
|
||||
event.preventDefault();
|
||||
try {
|
||||
const formData = new FormData(event.currentTarget);
|
||||
const longUrl = formData.get("longUrl") as string;
|
||||
const res = await shortenLink(longUrl);
|
||||
setSuccessMessage("Shortened URL!");
|
||||
setErrorMessage(null);
|
||||
setShortUrl(res.shortUrl);
|
||||
setManageUrl(res.manageUrl);
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
setErrorMessage("Failed to shorten the link. Please try again.");
|
||||
setSuccessMessage(null);
|
||||
}
|
||||
}
|
||||
|
||||
function copyToClipboard(text: string, title: string) {
|
||||
navigator.clipboard.writeText(text).then(
|
||||
() => {
|
||||
setSuccessMessage(`Copied ${title} to clipboard!`);
|
||||
},
|
||||
() => {
|
||||
setErrorMessage(`Failed to copy ${title} to clipboard.`);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="bg-stone-300 flex min-h-screen flex-col items-center justify-center py-2">
|
||||
<h1 className="text-3xl font-bold">halflink</h1>
|
||||
<p>Shorten a link with ease.</p>
|
||||
|
||||
<form className="mt-4 flex w-full max-w-xl" onSubmit={handleSubmit}>
|
||||
<input
|
||||
type="text"
|
||||
name="longUrl"
|
||||
placeholder="Enter your long URL here"
|
||||
className="bg-white flex-grow border border-stone-400 rounded-l px-4 py-2 focus:outline-none focus:ring-2 focus:ring-blue-500"
|
||||
/>
|
||||
<button
|
||||
type="submit"
|
||||
className="bg-blue-500 text-white px-4 py-2 rounded-r hover:bg-blue-600 focus:outline-none focus:ring-2 focus:ring-blue-500"
|
||||
>
|
||||
<Minimize2 />
|
||||
</button>
|
||||
</form>
|
||||
{errorMessage && (
|
||||
<p className="mt-4 text-red-800 font-bold">{errorMessage}</p>
|
||||
)}
|
||||
{successMessage && (
|
||||
<p className="mt-4 text-green-800 font-bold">{successMessage}</p>
|
||||
)}
|
||||
|
||||
{shortUrl && manageUrl && (
|
||||
<div className="flex flex-col items-center w-full">
|
||||
|
||||
<p className="mt-4">Shareable short link:</p>
|
||||
<div className="flex justify-center w-full max-w-xl">
|
||||
<input
|
||||
type="text"
|
||||
value={shortUrl}
|
||||
readOnly
|
||||
className="bg-white w-full max-w-md border border-stone-400 rounded-l text-center pl-20 pr-4 py-2 focus:outline-none focus:ring-2 focus:ring-blue-500"
|
||||
/>
|
||||
<button
|
||||
type="submit"
|
||||
className="flex justify-center w-16 bg-blue-500 text-white px-4 py-2 rounded-r hover:bg-blue-600 focus:outline-none focus:ring-2 focus:ring-blue-500"
|
||||
onClick={() => copyToClipboard(shortUrl, "short link")}
|
||||
>
|
||||
<Clipboard />
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<p className="mt-4">View analytics and manage your short link at:</p>
|
||||
<div className="flex justify-center w-full max-w-xl">
|
||||
<input
|
||||
type="text"
|
||||
value={manageUrl}
|
||||
readOnly
|
||||
className="bg-white w-full max-w-md border border-stone-400 rounded-l text-center pl-20 pr-4 py-2 focus:outline-none focus:ring-2 focus:ring-blue-500"
|
||||
/>
|
||||
<button
|
||||
type="submit"
|
||||
className="flex justify-center w-16 bg-blue-500 text-white px-4 py-2 rounded-r hover:bg-blue-600 focus:outline-none focus:ring-2 focus:ring-blue-500"
|
||||
onClick={() => copyToClipboard(manageUrl, "manage link")}
|
||||
>
|
||||
<Clipboard />
|
||||
</button>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
10
frontend/app/utils/shortenLink.ts
Normal file
10
frontend/app/utils/shortenLink.ts
Normal file
@@ -0,0 +1,10 @@
|
||||
export async function shortenLink(longUrl: string): Promise<{
|
||||
shortUrl: string;
|
||||
manageUrl: string;
|
||||
}> {
|
||||
let randomText = Math.random().toString(36).substring(2, 8);
|
||||
return {
|
||||
shortUrl: "https://halflink.example/" + randomText,
|
||||
manageUrl: "https://halflink.example/" + randomText + "/manage",
|
||||
}
|
||||
}
|
||||
18
frontend/eslint.config.mjs
Normal file
18
frontend/eslint.config.mjs
Normal file
@@ -0,0 +1,18 @@
|
||||
import { defineConfig, globalIgnores } from "eslint/config";
|
||||
import nextVitals from "eslint-config-next/core-web-vitals";
|
||||
import nextTs from "eslint-config-next/typescript";
|
||||
|
||||
const eslintConfig = defineConfig([
|
||||
...nextVitals,
|
||||
...nextTs,
|
||||
// Override default ignores of eslint-config-next.
|
||||
globalIgnores([
|
||||
// Default ignores of eslint-config-next:
|
||||
".next/**",
|
||||
"out/**",
|
||||
"build/**",
|
||||
"next-env.d.ts",
|
||||
]),
|
||||
]);
|
||||
|
||||
export default eslintConfig;
|
||||
7
frontend/next.config.ts
Normal file
7
frontend/next.config.ts
Normal file
@@ -0,0 +1,7 @@
|
||||
import type { NextConfig } from "next";
|
||||
|
||||
const nextConfig: NextConfig = {
|
||||
/* config options here */
|
||||
};
|
||||
|
||||
export default nextConfig;
|
||||
6548
frontend/package-lock.json
generated
Normal file
6548
frontend/package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
27
frontend/package.json
Normal file
27
frontend/package.json
Normal file
@@ -0,0 +1,27 @@
|
||||
{
|
||||
"name": "frontend",
|
||||
"version": "0.1.0",
|
||||
"private": true,
|
||||
"scripts": {
|
||||
"dev": "next dev",
|
||||
"build": "next build",
|
||||
"start": "next start",
|
||||
"lint": "eslint"
|
||||
},
|
||||
"dependencies": {
|
||||
"lucide-react": "^0.562.0",
|
||||
"next": "16.1.1",
|
||||
"react": "19.2.3",
|
||||
"react-dom": "19.2.3"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@tailwindcss/postcss": "^4",
|
||||
"@types/node": "^20",
|
||||
"@types/react": "^19",
|
||||
"@types/react-dom": "^19",
|
||||
"eslint": "^9",
|
||||
"eslint-config-next": "16.1.1",
|
||||
"tailwindcss": "^4",
|
||||
"typescript": "^5"
|
||||
}
|
||||
}
|
||||
7
frontend/postcss.config.mjs
Normal file
7
frontend/postcss.config.mjs
Normal file
@@ -0,0 +1,7 @@
|
||||
const config = {
|
||||
plugins: {
|
||||
"@tailwindcss/postcss": {},
|
||||
},
|
||||
};
|
||||
|
||||
export default config;
|
||||
34
frontend/tsconfig.json
Normal file
34
frontend/tsconfig.json
Normal file
@@ -0,0 +1,34 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"target": "ES2017",
|
||||
"lib": ["dom", "dom.iterable", "esnext"],
|
||||
"allowJs": true,
|
||||
"skipLibCheck": true,
|
||||
"strict": true,
|
||||
"noEmit": true,
|
||||
"esModuleInterop": true,
|
||||
"module": "esnext",
|
||||
"moduleResolution": "bundler",
|
||||
"resolveJsonModule": true,
|
||||
"isolatedModules": true,
|
||||
"jsx": "react-jsx",
|
||||
"incremental": true,
|
||||
"plugins": [
|
||||
{
|
||||
"name": "next"
|
||||
}
|
||||
],
|
||||
"paths": {
|
||||
"@/*": ["./*"]
|
||||
}
|
||||
},
|
||||
"include": [
|
||||
"next-env.d.ts",
|
||||
"**/*.ts",
|
||||
"**/*.tsx",
|
||||
".next/types/**/*.ts",
|
||||
".next/dev/types/**/*.ts",
|
||||
"**/*.mts"
|
||||
],
|
||||
"exclude": ["node_modules"]
|
||||
}
|
||||
Reference in New Issue
Block a user