feat: sign in sign up with all views

This commit is contained in:
Pc
2025-12-30 18:32:13 +01:00
parent a30a6168ba
commit bca5fc03a8
31 changed files with 5568 additions and 0 deletions

6
.env.default Normal file
View File

@@ -0,0 +1,6 @@
# Site info
PUBLIC_URL=https://example.com # Publicly accessible website root, used for rewrites. Note there is no trailing slash in the URL.
USE_SUBDOMAINS=true # Whether backend allows for use of subdomains in URL generation.
DEBUG=false
# Frontend specific
<miejsce na twoje zmienne>

25
kittyurl-frontend/.gitignore vendored Normal file
View File

@@ -0,0 +1,25 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*
lerna-debug.log*
node_modules
dist
dist-ssr
*.local
# Editor directories and files
.vscode/*
!.vscode/extensions.json
.idea
.DS_Store
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw?
.node_modules

View File

@@ -0,0 +1,73 @@
# React + TypeScript + Vite
This template provides a minimal setup to get React working in Vite with HMR and some ESLint rules.
Currently, two official plugins are available:
- [@vitejs/plugin-react](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react) uses [Babel](https://babeljs.io/) (or [oxc](https://oxc.rs) when used in [rolldown-vite](https://vite.dev/guide/rolldown)) for Fast Refresh
- [@vitejs/plugin-react-swc](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react-swc) uses [SWC](https://swc.rs/) for Fast Refresh
## React Compiler
The React Compiler is not enabled on this template because of its impact on dev & build performances. To add it, see [this documentation](https://react.dev/learn/react-compiler/installation).
## Expanding the ESLint configuration
If you are developing a production application, we recommend updating the configuration to enable type-aware lint rules:
```js
export default defineConfig([
globalIgnores(['dist']),
{
files: ['**/*.{ts,tsx}'],
extends: [
// Other configs...
// Remove tseslint.configs.recommended and replace with this
tseslint.configs.recommendedTypeChecked,
// Alternatively, use this for stricter rules
tseslint.configs.strictTypeChecked,
// Optionally, add this for stylistic rules
tseslint.configs.stylisticTypeChecked,
// Other configs...
],
languageOptions: {
parserOptions: {
project: ['./tsconfig.node.json', './tsconfig.app.json'],
tsconfigRootDir: import.meta.dirname,
},
// other options...
},
},
])
```
You can also install [eslint-plugin-react-x](https://github.com/Rel1cx/eslint-react/tree/main/packages/plugins/eslint-plugin-react-x) and [eslint-plugin-react-dom](https://github.com/Rel1cx/eslint-react/tree/main/packages/plugins/eslint-plugin-react-dom) for React-specific lint rules:
```js
// eslint.config.js
import reactX from 'eslint-plugin-react-x'
import reactDom from 'eslint-plugin-react-dom'
export default defineConfig([
globalIgnores(['dist']),
{
files: ['**/*.{ts,tsx}'],
extends: [
// Other configs...
// Enable lint rules for React
reactX.configs['recommended-typescript'],
// Enable lint rules for React DOM
reactDom.configs.recommended,
],
languageOptions: {
parserOptions: {
project: ['./tsconfig.node.json', './tsconfig.app.json'],
tsconfigRootDir: import.meta.dirname,
},
// other options...
},
},
])
```

View File

@@ -0,0 +1,23 @@
import js from '@eslint/js'
import globals from 'globals'
import reactHooks from 'eslint-plugin-react-hooks'
import reactRefresh from 'eslint-plugin-react-refresh'
import tseslint from 'typescript-eslint'
import { defineConfig, globalIgnores } from 'eslint/config'
export default defineConfig([
globalIgnores(['dist']),
{
files: ['**/*.{ts,tsx}'],
extends: [
js.configs.recommended,
tseslint.configs.recommended,
reactHooks.configs.flat.recommended,
reactRefresh.configs.vite,
],
languageOptions: {
ecmaVersion: 2020,
globals: globals.browser,
},
},
])

View File

@@ -0,0 +1,13 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>kittyurl-frontend</title>
</head>
<body>
<div id="root"></div>
<script type="module" src="/src/main.tsx"></script>
</body>
</html>

4149
kittyurl-frontend/package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,38 @@
{
"name": "kittyurl-frontend",
"private": true,
"version": "0.0.0",
"type": "module",
"scripts": {
"dev": "vite",
"build": "tsc -b && vite build",
"lint": "eslint .",
"preview": "vite preview"
},
"dependencies": {
"@tailwindcss/vite": "^4.1.18",
"axios": "^1.13.2",
"js-sha512": "^0.9.0",
"lucide-react": "^0.562.0",
"react": "^19.2.0",
"react-dom": "^19.2.0",
"react-router-dom": "^7.11.0"
},
"devDependencies": {
"@eslint/js": "^9.39.1",
"@types/node": "^24.10.1",
"@types/react": "^19.2.5",
"@types/react-dom": "^19.2.3",
"@vitejs/plugin-react": "^5.1.1",
"autoprefixer": "^10.4.23",
"eslint": "^9.39.1",
"eslint-plugin-react-hooks": "^7.0.1",
"eslint-plugin-react-refresh": "^0.4.24",
"globals": "^16.5.0",
"postcss": "^8.5.6",
"tailwindcss": "^4.1.18",
"typescript": "~5.9.3",
"typescript-eslint": "^8.46.4",
"vite": "^7.2.4"
}
}

View File

@@ -0,0 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" class="iconify iconify--logos" width="31.88" height="32" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 257"><defs><linearGradient id="IconifyId1813088fe1fbc01fb466" x1="-.828%" x2="57.636%" y1="7.652%" y2="78.411%"><stop offset="0%" stop-color="#41D1FF"></stop><stop offset="100%" stop-color="#BD34FE"></stop></linearGradient><linearGradient id="IconifyId1813088fe1fbc01fb467" x1="43.376%" x2="50.316%" y1="2.242%" y2="89.03%"><stop offset="0%" stop-color="#FFEA83"></stop><stop offset="8.333%" stop-color="#FFDD35"></stop><stop offset="100%" stop-color="#FFA800"></stop></linearGradient></defs><path fill="url(#IconifyId1813088fe1fbc01fb466)" d="M255.153 37.938L134.897 252.976c-2.483 4.44-8.862 4.466-11.382.048L.875 37.958c-2.746-4.814 1.371-10.646 6.827-9.67l120.385 21.517a6.537 6.537 0 0 0 2.322-.004l117.867-21.483c5.438-.991 9.574 4.796 6.877 9.62Z"></path><path fill="url(#IconifyId1813088fe1fbc01fb467)" d="M185.432.063L96.44 17.501a3.268 3.268 0 0 0-2.634 3.014l-5.474 92.456a3.268 3.268 0 0 0 3.997 3.378l24.777-5.718c2.318-.535 4.413 1.507 3.936 3.838l-7.361 36.047c-.495 2.426 1.782 4.5 4.151 3.78l15.304-4.649c2.372-.72 4.652 1.36 4.15 3.788l-11.698 56.621c-.732 3.542 3.979 5.473 5.943 2.437l1.313-2.028l72.516-144.72c1.215-2.423-.88-5.186-3.54-4.672l-25.505 4.922c-2.396.462-4.435-1.77-3.759-4.114l16.646-57.705c.677-2.35-1.37-4.583-3.769-4.113Z"></path></svg>

After

Width:  |  Height:  |  Size: 1.5 KiB

View File

@@ -0,0 +1,42 @@
#root {
max-width: 1280px;
margin: 0 auto;
padding: 2rem;
text-align: center;
}
.logo {
height: 6em;
padding: 1.5em;
will-change: filter;
transition: filter 300ms;
}
.logo:hover {
filter: drop-shadow(0 0 2em #646cffaa);
}
.logo.react:hover {
filter: drop-shadow(0 0 2em #61dafbaa);
}
@keyframes logo-spin {
from {
transform: rotate(0deg);
}
to {
transform: rotate(360deg);
}
}
@media (prefers-reduced-motion: no-preference) {
a:nth-of-type(2) .logo {
animation: logo-spin infinite 20s linear;
}
}
.card {
padding: 2em;
}
.read-the-docs {
color: #888;
}

View File

@@ -0,0 +1,45 @@
import { useState } from 'react';
import { Navbar } from './components/Navbar';
import { Generator } from './components/Generator';
import { LoginView } from './components/LoginView';
import { HistoryView } from './components/HistoryView';
import { KittyGame } from './components/KittyGame';
import { FlappyCat } from './components/FlappyCat';
import { useAuth } from './hooks/useAuth';
// Eksportujemy typ, aby inne pliki mogły go użyć
export type View = 'home' | 'login' | 'history' | 'jump-game' | 'flappy-game';
function App() {
const [url, setUrl] = useState('');
const [view, setView] = useState<View>('home');
const { isAuthenticated, logout } = useAuth();
const renderView = () => {
switch (view) {
case 'login':
return <LoginView onBack={() => setView('home')} onSuccess={() => setView('home')} />;
case 'history':
return <HistoryView onBack={() => setView('home')} />;
case 'jump-game':
return <KittyGame onBack={() => setView('home')} />;
case 'flappy-game':
return <FlappyCat onBack={() => setView('home')} />;
default:
return <Generator url={url} setUrl={setUrl} onGenerate={() => alert('Meow!')} />;
}
};
return (
<div className="min-h-screen bg-[#fff5f8] text-slate-700 font-sans">
<Navbar
onNavigate={(v: View) => setView(v)}
isAuthenticated={isAuthenticated}
onLogout={logout}
/>
<main>{renderView()}</main>
</div>
);
}
export default App;

View File

@@ -0,0 +1,25 @@
import axios from 'axios';
import { sha512 } from 'js-sha512';
// Interfejs zgodny z Twoją dokumentacją [cite: 74-79]
export interface AuthResponse {
status: "ok";
name: string;
role: "user" | "admin";
token: string;
}
export const loginUser = async (name: string, pass: string): Promise<AuthResponse> => {
// Wysyłamy POST zgodnie ze specyfikacją dokumentacji [cite: 68]
const response = await axios.post('https://twoj-backend.pl/api/v1/user/signIn', {
name: name,
password: sha512(pass) // Wymagane SHA-512 [cite: 71]
});
// Jeśli sukces, zapisujemy token JWT [cite: 78]
if (response.data.status === "ok") {
localStorage.setItem('token', response.data.token);
}
return response.data;
};

View File

@@ -0,0 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" class="iconify iconify--logos" width="35.93" height="32" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 228"><path fill="#00D8FF" d="M210.483 73.824a171.49 171.49 0 0 0-8.24-2.597c.465-1.9.893-3.777 1.273-5.621c6.238-30.281 2.16-54.676-11.769-62.708c-13.355-7.7-35.196.329-57.254 19.526a171.23 171.23 0 0 0-6.375 5.848a155.866 155.866 0 0 0-4.241-3.917C100.759 3.829 77.587-4.822 63.673 3.233C50.33 10.957 46.379 33.89 51.995 62.588a170.974 170.974 0 0 0 1.892 8.48c-3.28.932-6.445 1.924-9.474 2.98C17.309 83.498 0 98.307 0 113.668c0 15.865 18.582 31.778 46.812 41.427a145.52 145.52 0 0 0 6.921 2.165a167.467 167.467 0 0 0-2.01 9.138c-5.354 28.2-1.173 50.591 12.134 58.266c13.744 7.926 36.812-.22 59.273-19.855a145.567 145.567 0 0 0 5.342-4.923a168.064 168.064 0 0 0 6.92 6.314c21.758 18.722 43.246 26.282 56.54 18.586c13.731-7.949 18.194-32.003 12.4-61.268a145.016 145.016 0 0 0-1.535-6.842c1.62-.48 3.21-.974 4.76-1.488c29.348-9.723 48.443-25.443 48.443-41.52c0-15.417-17.868-30.326-45.517-39.844Zm-6.365 70.984c-1.4.463-2.836.91-4.3 1.345c-3.24-10.257-7.612-21.163-12.963-32.432c5.106-11 9.31-21.767 12.459-31.957c2.619.758 5.16 1.557 7.61 2.4c23.69 8.156 38.14 20.213 38.14 29.504c0 9.896-15.606 22.743-40.946 31.14Zm-10.514 20.834c2.562 12.94 2.927 24.64 1.23 33.787c-1.524 8.219-4.59 13.698-8.382 15.893c-8.067 4.67-25.32-1.4-43.927-17.412a156.726 156.726 0 0 1-6.437-5.87c7.214-7.889 14.423-17.06 21.459-27.246c12.376-1.098 24.068-2.894 34.671-5.345a134.17 134.17 0 0 1 1.386 6.193ZM87.276 214.515c-7.882 2.783-14.16 2.863-17.955.675c-8.075-4.657-11.432-22.636-6.853-46.752a156.923 156.923 0 0 1 1.869-8.499c10.486 2.32 22.093 3.988 34.498 4.994c7.084 9.967 14.501 19.128 21.976 27.15a134.668 134.668 0 0 1-4.877 4.492c-9.933 8.682-19.886 14.842-28.658 17.94ZM50.35 144.747c-12.483-4.267-22.792-9.812-29.858-15.863c-6.35-5.437-9.555-10.836-9.555-15.216c0-9.322 13.897-21.212 37.076-29.293c2.813-.98 5.757-1.905 8.812-2.773c3.204 10.42 7.406 21.315 12.477 32.332c-5.137 11.18-9.399 22.249-12.634 32.792a134.718 134.718 0 0 1-6.318-1.979Zm12.378-84.26c-4.811-24.587-1.616-43.134 6.425-47.789c8.564-4.958 27.502 2.111 47.463 19.835a144.318 144.318 0 0 1 3.841 3.545c-7.438 7.987-14.787 17.08-21.808 26.988c-12.04 1.116-23.565 2.908-34.161 5.309a160.342 160.342 0 0 1-1.76-7.887Zm110.427 27.268a347.8 347.8 0 0 0-7.785-12.803c8.168 1.033 15.994 2.404 23.343 4.08c-2.206 7.072-4.956 14.465-8.193 22.045a381.151 381.151 0 0 0-7.365-13.322Zm-45.032-43.861c5.044 5.465 10.096 11.566 15.065 18.186a322.04 322.04 0 0 0-30.257-.006c4.974-6.559 10.069-12.652 15.192-18.18ZM82.802 87.83a323.167 323.167 0 0 0-7.227 13.238c-3.184-7.553-5.909-14.98-8.134-22.152c7.304-1.634 15.093-2.97 23.209-3.984a321.524 321.524 0 0 0-7.848 12.897Zm8.081 65.352c-8.385-.936-16.291-2.203-23.593-3.793c2.26-7.3 5.045-14.885 8.298-22.6a321.187 321.187 0 0 0 7.257 13.246c2.594 4.48 5.28 8.868 8.038 13.147Zm37.542 31.03c-5.184-5.592-10.354-11.779-15.403-18.433c4.902.192 9.899.29 14.978.29c5.218 0 10.376-.117 15.453-.343c-4.985 6.774-10.018 12.97-15.028 18.486Zm52.198-57.817c3.422 7.8 6.306 15.345 8.596 22.52c-7.422 1.694-15.436 3.058-23.88 4.071a382.417 382.417 0 0 0 7.859-13.026a347.403 347.403 0 0 0 7.425-13.565Zm-16.898 8.101a358.557 358.557 0 0 1-12.281 19.815a329.4 329.4 0 0 1-23.444.823c-7.967 0-15.716-.248-23.178-.732a310.202 310.202 0 0 1-12.513-19.846h.001a307.41 307.41 0 0 1-10.923-20.627a310.278 310.278 0 0 1 10.89-20.637l-.001.001a307.318 307.318 0 0 1 12.413-19.761c7.613-.576 15.42-.876 23.31-.876H128c7.926 0 15.743.303 23.354.883a329.357 329.357 0 0 1 12.335 19.695a358.489 358.489 0 0 1 11.036 20.54a329.472 329.472 0 0 1-11 20.722Zm22.56-122.124c8.572 4.944 11.906 24.881 6.52 51.026c-.344 1.668-.73 3.367-1.15 5.09c-10.622-2.452-22.155-4.275-34.23-5.408c-7.034-10.017-14.323-19.124-21.64-27.008a160.789 160.789 0 0 1 5.888-5.4c18.9-16.447 36.564-22.941 44.612-18.3ZM128 90.808c12.625 0 22.86 10.235 22.86 22.86s-10.235 22.86-22.86 22.86s-22.86-10.235-22.86-22.86s10.235-22.86 22.86-22.86Z"></path></svg>

After

Width:  |  Height:  |  Size: 4.0 KiB

View File

@@ -0,0 +1,94 @@
import React from 'react';
interface DetailedKittyProps {
isJumping: boolean;
isNight: boolean;
isGameOver: boolean;
}
export const DetailedKitty: React.FC<DetailedKittyProps> = ({ isJumping, isNight, isGameOver }) => {
const mainColor = isGameOver ? (isNight ? '#475569' : '#cbd5e1') : (isNight ? '#f8fafc' : '#f472b6');
const stripeColor = isNight ? '#cbd5e1' : '#ec4899';
const earColor = isNight ? '#334155' : '#fbcfe8';
return (
<div className={`relative w-20 h-14 transition-all duration-200 ${isJumping ? '-rotate-6 scale-110' : ''}`}>
{/* OGON (Merdający) */}
<div
className="absolute -left-4 top-4 w-8 h-3 rounded-full origin-right rotate-[-20deg]"
style={{
backgroundColor: mainColor,
animation: !isGameOver ? 'tail-wag 0.8s ease-in-out infinite' : 'none'
}}
/>
{/* TUŁÓW */}
<div className="absolute inset-0 rounded-[2rem] overflow-hidden" style={{ backgroundColor: mainColor }}>
{/* Paski na grzbiecie */}
<div className="absolute top-0 left-1/4 w-2 h-4 rounded-full opacity-30" style={{ backgroundColor: stripeColor }} />
<div className="absolute top-0 left-1/2 w-2 h-4 rounded-full opacity-30" style={{ backgroundColor: stripeColor }} />
<div className="absolute top-0 left-3/4 w-2 h-4 rounded-full opacity-30" style={{ backgroundColor: stripeColor }} />
</div>
{/* GŁOWA */}
<div className="absolute -right-4 -top-6 w-14 h-13 rounded-full shadow-sm" style={{ backgroundColor: mainColor }}>
{/* Uszy z wnętrzem */}
<div className="absolute -top-2 left-1 w-5 h-6 rounded-t-full rotate-[-15deg]" style={{ backgroundColor: mainColor }}>
<div className="absolute inset-1 rounded-t-full" style={{ backgroundColor: earColor }} />
</div>
<div className="absolute -top-2 right-1 w-5 h-6 rounded-t-full rotate-[15deg]" style={{ backgroundColor: mainColor }}>
<div className="absolute inset-1 rounded-t-full" style={{ backgroundColor: earColor }} />
</div>
{/* Oczy z błyskiem */}
<div className={`absolute top-5 left-3 w-2.5 h-2.5 rounded-full ${isGameOver ? 'bg-slate-400' : 'bg-slate-900'}`}>
{!isGameOver && <div className="absolute top-0.5 left-0.5 w-1 h-1 bg-white rounded-full opacity-70" />}
</div>
<div className={`absolute top-5 right-3 w-2.5 h-2.5 rounded-full ${isGameOver ? 'bg-slate-400' : 'bg-slate-900'}`}>
{!isGameOver && <div className="absolute top-0.5 left-0.5 w-1 h-1 bg-white rounded-full opacity-70" />}
</div>
{/* Wąsy */}
<div className="absolute top-7 -left-3 w-4 h-[1px] bg-slate-300 rotate-[10deg] opacity-50" />
<div className="absolute top-9 -left-3 w-4 h-[1px] bg-slate-300 rotate-[-5deg] opacity-50" />
<div className="absolute top-7 -right-3 w-4 h-[1px] bg-slate-300 rotate-[-10deg] opacity-50" />
<div className="absolute top-9 -right-3 w-4 h-[1px] bg-slate-300 rotate-[5deg] opacity-50" />
{/* Nosek i Pyszczek */}
<div className="absolute top-8 left-1/2 -translate-x-1/2 w-2 h-1.5 bg-pink-400 rounded-full" />
</div>
{/* ŁAPKI (Zintegrowane z animacją biegu) */}
{/* Przednia lewa */}
<div className="absolute bottom-[-10px] left-4 w-3 h-6 rounded-full origin-top"
style={{
backgroundColor: mainColor,
animation: !isJumping && !isGameOver ? 'kitty-walk 0.2s infinite' : 'none',
transform: isJumping ? 'rotate(45deg)' : 'none'
}}>
<div className="absolute bottom-0 w-full h-2 bg-white rounded-full opacity-60" /> {/* Skarpetka */}
</div>
{/* Przednia prawa */}
<div className="absolute bottom-[-10px] left-8 w-3 h-6 rounded-full origin-top"
style={{
backgroundColor: mainColor,
animation: !isJumping && !isGameOver ? 'kitty-walk-alt 0.2s infinite' : 'none',
transform: isJumping ? 'rotate(45deg)' : 'none'
}}>
<div className="absolute bottom-0 w-full h-2 bg-white rounded-full opacity-60" />
</div>
{/* Tylna lewa */}
<div className="absolute bottom-[-10px] right-4 w-3 h-6 rounded-full origin-top"
style={{
backgroundColor: mainColor,
animation: !isJumping && !isGameOver ? 'kitty-walk 0.2s infinite' : 'none',
transform: isJumping ? 'rotate(-45deg)' : 'none'
}}>
<div className="absolute bottom-0 w-full h-2 bg-white rounded-full opacity-60" />
</div>
</div>
);
};

View File

@@ -0,0 +1,216 @@
import React, { useState, useEffect, useRef, useCallback } from 'react';
import { ArrowLeft, Trophy, Sparkles } from 'lucide-react';
import { DetailedKitty } from './DetailedKitty';
const GAP_SIZE = 170; // Przerwa między drapakami
const PIPE_WIDTH = 70;
const PIPE_SPAWN_RATE = 1500; // Nowy drapak co 1.5 sekundy
export const FlappyCat: React.FC<{ onBack: () => void }> = ({ onBack }) => {
const [isPlaying, setIsPlaying] = useState(false);
const [gameOver, setGameOver] = useState(false);
const [score, setScore] = useState(0);
const [highScore, setHighScore] = useState<number>(() => {
const saved = localStorage.getItem('flappyKittyHighScore');
return saved ? parseInt(saved, 10) : 0;
});
// Stany pozycji do renderowania
const [displayKittyY, setDisplayKittyY] = useState(150);
const [displayPipes, setDisplayPipes] = useState<{ x: number; topHeight: number; id: number }[]>([]);
const [rotation, setRotation] = useState(0);
// Referencje do fizyki (obliczenia poza Reactem dla płynności)
const kittyYRef = useRef(150);
const velocityRef = useRef(0);
const pipesRef = useRef<{ x: number; topHeight: number; id: number }[]>([]);
const scoreRef = useRef(0);
const requestRef = useRef<number>(0);
const GRAVITY = 0.35;
const JUMP_STRENGTH = -7;
const startGame = useCallback(() => {
setIsPlaying(true);
setGameOver(false);
setScore(0);
scoreRef.current = 0;
kittyYRef.current = 150;
velocityRef.current = 0;
pipesRef.current = [];
setDisplayKittyY(150);
setDisplayPipes([]);
}, []);
const flap = useCallback(() => {
if (isPlaying && !gameOver) {
velocityRef.current = JUMP_STRENGTH;
}
}, [isPlaying, gameOver]);
useEffect(() => {
const update = () => {
if (gameOver || !isPlaying) return;
// 1. Fizyka lotu
velocityRef.current += GRAVITY;
kittyYRef.current += velocityRef.current;
// Obrót kota zależnie od prędkości
setRotation(Math.min(Math.max(velocityRef.current * 4, -20), 90));
// 2. Kolizja z sufitem i podłogą
if (kittyYRef.current > 380 || kittyYRef.current < -50) {
endGame();
return;
}
// 3. Ruch drapaków (rur)
pipesRef.current = pipesRef.current
.map(p => ({ ...p, x: p.x - 4 })) // Prędkość rur
.filter(p => p.x > -100);
// 4. Wykrywanie kolizji z drapakami
pipesRef.current.forEach(p => {
// Kot jest na stałej pozycji X (ok. 50-100px)
if (p.x < 110 && p.x + PIPE_WIDTH > 40) {
// Sprawdzanie czy kot uderzył w górny lub dolny drapak
if (kittyYRef.current < p.topHeight || kittyYRef.current > p.topHeight + GAP_SIZE - 40) {
endGame();
}
}
// Dodawanie punktów
if (p.x < 40 && !p.hasOwnProperty('passed')) {
(p as any).passed = true;
scoreRef.current += 1;
setScore(scoreRef.current);
}
});
// 5. Synchronizacja z widokiem
setDisplayKittyY(kittyYRef.current);
setDisplayPipes([...pipesRef.current]);
requestRef.current = requestAnimationFrame(update);
};
const endGame = () => {
setGameOver(true);
setIsPlaying(false);
const currentHS = parseInt(localStorage.getItem('flappyKittyHighScore') || '0', 10);
if (scoreRef.current > currentHS) {
setHighScore(scoreRef.current);
localStorage.setItem('flappyKittyHighScore', scoreRef.current.toString());
}
};
if (isPlaying && !gameOver) {
requestRef.current = requestAnimationFrame(update);
}
return () => cancelAnimationFrame(requestRef.current);
}, [isPlaying, gameOver]);
// Generator nowych drapaków
useEffect(() => {
if (!isPlaying || gameOver) return;
const interval = setInterval(() => {
const topHeight = Math.random() * (220 - 50) + 50;
pipesRef.current.push({ x: 650, topHeight, id: Date.now() });
}, PIPE_SPAWN_RATE);
return () => clearInterval(interval);
}, [isPlaying, gameOver]);
// Obsługa klawiszy
useEffect(() => {
const handleKey = (e: KeyboardEvent) => {
if (e.code === 'Space') {
e.preventDefault();
if (!isPlaying || gameOver) startGame(); else flap();
}
};
window.addEventListener('keydown', handleKey);
return () => window.removeEventListener('keydown', handleKey);
}, [isPlaying, gameOver, startGame, flap]);
return (
<div className="flex flex-col items-center justify-center min-h-[75vh] p-4">
<button onClick={onBack} className="mb-6 flex items-center gap-2 text-pink-500 font-bold hover:scale-105 transition-all outline-none">
<ArrowLeft size={20} /> Back to Menu
</button>
{/* OKNO GRY */}
<div
className="relative w-full max-w-[600px] h-[450px] bg-sky-100 rounded-[3rem] shadow-2xl border-4 border-white overflow-hidden cursor-pointer select-none"
onClick={() => { if (!isPlaying || gameOver) startGame(); else flap(); }}
>
{/* Dekoracje tła */}
<div className="absolute top-10 left-10 text-white/40"><Sparkles size={40} /></div>
<div className="absolute top-40 right-20 text-white/30"><Sparkles size={60} /></div>
{/* Punkty */}
<div className="absolute top-6 right-8 text-right z-30 font-black">
<div className="text-pink-500 text-4xl drop-shadow-sm">Score: {score}</div>
<div className="text-pink-300 text-sm flex items-center justify-end gap-1"><Trophy size={14} /> Record: {highScore}</div>
</div>
{/* KOTEK */}
<div
className="absolute left-10 z-20 transition-transform duration-75"
style={{
top: `${displayKittyY}px`,
transform: `rotate(${rotation}deg)`
}}
>
<DetailedKitty isJumping={true} isNight={false} isGameOver={gameOver} />
</div>
{/* DRAPAKI (Rury) */}
{displayPipes.map(p => (
<React.Fragment key={p.id}>
{/* Górny Drapak */}
<div
className="absolute bg-[#e5c29f] border-x-4 border-b-8 border-[#d4ac87] rounded-b-3xl shadow-sm"
style={{ left: p.x, top: 0, width: PIPE_WIDTH, height: p.topHeight }}
>
<div className="absolute bottom-4 w-full h-2 bg-white/20" />
<div className="absolute bottom-8 w-full h-2 bg-white/20" />
</div>
{/* Dolny Drapak */}
<div
className="absolute bg-[#e5c29f] border-x-4 border-t-8 border-[#d4ac87] rounded-t-3xl shadow-sm"
style={{ left: p.x, top: p.topHeight + GAP_SIZE, width: PIPE_WIDTH, height: 450 - (p.topHeight + GAP_SIZE) }}
>
<div className="absolute top-4 w-full h-2 bg-white/20" />
<div className="absolute top-8 w-full h-2 bg-white/20" />
</div>
</React.Fragment>
))}
{/* Ekran Startowy */}
{!isPlaying && !gameOver && (
<div className="absolute inset-0 bg-white/40 backdrop-blur-sm flex items-center justify-center z-40">
<div className="bg-white p-10 rounded-[3rem] shadow-2xl text-center border-4 border-pink-100 max-w-xs w-full">
<p className="text-3xl font-black text-pink-500 mb-6 tracking-tighter">Flappy Cat 🎈</p>
<button className="bg-pink-500 text-white px-10 py-4 rounded-2xl font-black animate-bounce shadow-lg shadow-pink-200 text-xl">
MEOW TO FLY
</button>
<p className="text-pink-300 text-xs mt-4 font-bold uppercase">Click or Space</p>
</div>
</div>
)}
{/* Ekran Koniec Gry */}
{gameOver && (
<div className="absolute inset-0 bg-pink-50/90 backdrop-blur-md flex flex-col items-center justify-center z-40">
<h3 className="text-5xl font-black text-pink-600 mb-2">Oops! 😿</h3>
<p className="font-bold text-3xl text-pink-400 mb-8">Score: {score}</p>
<button className="bg-pink-500 text-white px-12 py-4 rounded-2xl font-black text-xl shadow-xl hover:scale-110 transition-all active:scale-95">
TRY AGAIN
</button>
</div>
)}
</div>
</div>
);
};

View File

@@ -0,0 +1,49 @@
import React from 'react';
import { PawPrint, Heart, Sparkles, Cat } from 'lucide-react';
interface GeneratorProps {
url: string;
setUrl: (val: string) => void;
onGenerate: () => void;
}
export const Generator: React.FC<GeneratorProps> = ({ url, setUrl, onGenerate }) => (
<div className="max-w-[800px] mx-auto pt-16 px-4 flex flex-col items-center">
<header className="text-center mb-12">
<h1 className="text-7xl font-black text-pink-500 mb-2 tracking-tighter flex items-center gap-4">
KittyURL <PawPrint size={50} fill="currentColor" />
</h1>
<p className="text-pink-300 text-xl font-medium">Shorten your links with a purr!</p>
</header>
<div className="w-full bg-white rounded-[3rem] shadow-2xl shadow-pink-200/50 p-10 border-4 border-white relative overflow-hidden">
<div className="mb-6">
<label className="block text-xs font-black uppercase tracking-widest text-pink-300 mb-3 ml-2">Long URL to shorten</label>
<div className="relative">
<input
type="url"
placeholder="https://example.com/very-long-url"
className="w-full p-5 bg-pink-50/30 border-2 border-pink-100 rounded-2xl outline-none focus:border-pink-400 focus:bg-white transition-all text-lg shadow-inner"
value={url}
onChange={(e) => setUrl(e.target.value)}
/>
<Heart className="absolute right-5 top-1/2 -translate-y-1/2 text-pink-200" size={24} />
</div>
</div>
<button
onClick={onGenerate}
className="w-full bg-pink-500 hover:bg-pink-600 text-white font-black py-5 rounded-[1.5rem] transition-all shadow-xl shadow-pink-100 active:scale-[0.98] text-xl flex items-center justify-center gap-3 cursor-pointer"
>
Generate Kitty Link <Sparkles size={24} />
</button>
</div>
<div className="w-full mt-16 text-center">
<div className="bg-pink-100/50 rounded-[2.5rem] border-4 border-dashed border-pink-200 p-12">
<Cat size={60} className="mx-auto text-pink-200 mb-4" />
<p className="text-pink-300 font-bold">No links generated yet. Feed me a URL! 🐾</p>
</div>
</div>
</div>
);

View File

@@ -0,0 +1,29 @@
import { PawPrint, ExternalLink } from 'lucide-react';
export const HistoryView = ({ onBack }: { onBack: () => void }) => (
<div className="max-w-4xl mx-auto p-6 pt-10">
<button onClick={onBack} className="mb-8 flex items-center gap-2 text-pink-500 font-bold hover:scale-105 transition-transform">
<PawPrint size={20} /> Back to KittyURL
</button>
<div className="bg-white/80 backdrop-blur-md rounded-[2.5rem] p-8 shadow-xl border-2 border-pink-50">
<h2 className="text-3xl font-black text-slate-800 mb-8">Recent Paws 🐾</h2>
<div className="overflow-hidden rounded-2xl border border-pink-100">
<table className="w-full text-left bg-white">
<thead className="bg-pink-50 text-pink-600">
<tr>
<th className="px-6 py-4 font-bold uppercase text-xs">Long URL</th>
<th className="px-6 py-4 font-bold uppercase text-xs">Kitty URL</th>
</tr>
</thead>
<tbody className="divide-y divide-pink-50">
<tr className="hover:bg-pink-50/50 transition-colors">
<td className="px-6 py-4 text-slate-400 truncate max-w-[200px]">https://very-long-link.com/cats</td>
<td className="px-6 py-4 font-bold text-pink-500 flex items-center gap-2">kitty.url/meow <ExternalLink size={14} /></td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
);

View File

@@ -0,0 +1,251 @@
import React, { useState, useEffect, useRef, useCallback } from 'react';
import { ArrowLeft, Trophy, Sparkles, Moon, Sun } from 'lucide-react';
// --- ZAAWANSOWANY MODEL KOTA (DetailedKitty) ---
interface DetailedKittyProps {
isJumping: boolean;
isNight: boolean;
isGameOver: boolean;
}
const DetailedKitty: React.FC<DetailedKittyProps> = ({ isJumping, isNight, isGameOver }) => {
const mainColor = isGameOver ? (isNight ? '#475569' : '#cbd5e1') : (isNight ? '#f8fafc' : '#f472b6');
const stripeColor = isNight ? '#cbd5e1' : '#ec4899';
const earColor = isNight ? '#334155' : '#fbcfe8';
return (
<div className={`relative w-20 h-14 transition-all duration-200 ${isJumping ? '-rotate-6 scale-110' : ''}`}>
{/* OGON */}
<div
className="absolute -left-4 top-4 w-8 h-3 rounded-full origin-right rotate-[-20deg]"
style={{
backgroundColor: mainColor,
animation: !isGameOver ? 'tail-wag 0.8s ease-in-out infinite' : 'none'
}}
/>
{/* TUŁÓW */}
<div className="absolute inset-0 rounded-[2rem] overflow-hidden shadow-sm" style={{ backgroundColor: mainColor }}>
{/* Paski dekoracyjne */}
<div className="absolute top-0 left-1/4 w-2 h-4 rounded-full opacity-30" style={{ backgroundColor: stripeColor }} />
<div className="absolute top-0 left-1/2 w-2 h-4 rounded-full opacity-30" style={{ backgroundColor: stripeColor }} />
</div>
{/* GŁOWA */}
<div className="absolute -right-4 -top-6 w-14 h-13 rounded-full shadow-sm" style={{ backgroundColor: mainColor }}>
{/* Uszy */}
<div className="absolute -top-2 left-1 w-5 h-6 rounded-t-full rotate-[-15deg]" style={{ backgroundColor: mainColor }}>
<div className="absolute inset-1 rounded-t-full" style={{ backgroundColor: earColor }} />
</div>
<div className="absolute -top-2 right-1 w-5 h-6 rounded-t-full rotate-[15deg]" style={{ backgroundColor: mainColor }}>
<div className="absolute inset-1 rounded-t-full" style={{ backgroundColor: earColor }} />
</div>
{/* Oczy */}
<div className={`absolute top-5 left-3 w-2.5 h-2.5 rounded-full ${isGameOver ? 'bg-slate-500 text-[10px] flex items-center justify-center' : 'bg-slate-900'}`}>
{isGameOver ? 'x' : <div className="absolute top-0.5 left-0.5 w-1 h-1 bg-white rounded-full opacity-70" />}
</div>
<div className={`absolute top-5 right-3 w-2.5 h-2.5 rounded-full ${isGameOver ? 'bg-slate-500 text-[10px] flex items-center justify-center' : 'bg-slate-900'}`}>
{isGameOver ? 'x' : <div className="absolute top-0.5 left-0.5 w-1 h-1 bg-white rounded-full opacity-70" />}
</div>
{/* Wąsy */}
<div className="absolute top-7 -left-2 w-3 h-[1px] bg-slate-300 rotate-[10deg] opacity-40" />
<div className="absolute top-9 -left-2 w-3 h-[1px] bg-slate-300 rotate-[-10deg] opacity-40" />
<div className="absolute top-8 left-1/2 -translate-x-1/2 w-2 h-1.5 bg-pink-400 rounded-full" />
</div>
{/* ŁAPKI (Animowane) */}
<div className="absolute bottom-[-10px] left-4 w-3 h-6 rounded-full origin-top"
style={{
backgroundColor: mainColor,
animation: !isJumping && !isGameOver ? 'kitty-walk 0.2s infinite' : 'none',
transform: isJumping ? 'rotate(45deg)' : 'none'
}}>
<div className="absolute bottom-0 w-full h-2 bg-white rounded-full opacity-60" />
</div>
<div className="absolute bottom-[-10px] right-5 w-3 h-6 rounded-full origin-top"
style={{
backgroundColor: mainColor,
animation: !isJumping && !isGameOver ? 'kitty-walk-alt 0.2s infinite' : 'none',
transform: isJumping ? 'rotate(-45deg)' : 'none'
}}>
<div className="absolute bottom-0 w-full h-2 bg-white rounded-full opacity-60" />
</div>
</div>
);
};
// --- GŁÓWNY KOMPONENT GRY ---
export const KittyGame: React.FC<{ onBack: () => void }> = ({ onBack }) => {
const [isPlaying, setIsPlaying] = useState(false);
const [gameOver, setGameOver] = useState(false);
const [score, setScore] = useState(0);
const [highScore, setHighScore] = useState<number>(() => {
const saved = localStorage.getItem('kittyHighScore');
return saved ? parseInt(saved, 10) : 0;
});
const [displayKittyY, setDisplayKittyY] = useState(0);
const [displayObstacleX, setDisplayObstacleX] = useState(600);
const isNight = Math.floor(score / 10) % 2 === 1;
const kittyYRef = useRef(0);
const obstacleXRef = useRef(600);
const velocityRef = useRef(0);
const scoreRef = useRef(0);
const requestRef = useRef<number>(0);
const GRAVITY = 0.6;
const JUMP_STRENGTH = -11;
const GROUND_Y = 0;
const endGame = useCallback(() => {
setGameOver(true);
setIsPlaying(false);
const currentHighScore = parseInt(localStorage.getItem('kittyHighScore') || '0', 10);
if (scoreRef.current > currentHighScore) {
setHighScore(scoreRef.current);
localStorage.setItem('kittyHighScore', scoreRef.current.toString());
}
}, []);
const startGame = useCallback(() => {
setIsPlaying(true);
setGameOver(false);
setScore(0);
scoreRef.current = 0;
kittyYRef.current = 0;
obstacleXRef.current = 600;
velocityRef.current = 0;
setDisplayKittyY(0);
setDisplayObstacleX(600);
}, []);
const jump = useCallback(() => {
if (kittyYRef.current <= GROUND_Y && !gameOver && isPlaying) {
velocityRef.current = JUMP_STRENGTH;
}
}, [gameOver, isPlaying]);
useEffect(() => {
const update = () => {
if (gameOver || !isPlaying) return;
velocityRef.current += GRAVITY;
kittyYRef.current -= velocityRef.current;
if (kittyYRef.current <= GROUND_Y) {
kittyYRef.current = GROUND_Y;
velocityRef.current = 0;
}
obstacleXRef.current -= 5 + (scoreRef.current * 0.2);
if (obstacleXRef.current < -50) {
obstacleXRef.current = 650;
scoreRef.current += 1;
setScore(scoreRef.current);
}
// DOSTOSOWANA KOLIZJA: Uwzględnia większy model kota
if (obstacleXRef.current < 110 && obstacleXRef.current > 30 && kittyYRef.current < 45) {
endGame();
return;
}
setDisplayKittyY(kittyYRef.current);
setDisplayObstacleX(obstacleXRef.current);
requestRef.current = requestAnimationFrame(update);
};
if (isPlaying && !gameOver) {
requestRef.current = requestAnimationFrame(update);
}
return () => cancelAnimationFrame(requestRef.current);
}, [isPlaying, gameOver, endGame]);
useEffect(() => {
const handleKey = (e: KeyboardEvent) => {
if (e.code === 'Space') {
e.preventDefault();
if (!isPlaying || gameOver) startGame(); else jump();
}
};
window.addEventListener('keydown', handleKey);
return () => window.removeEventListener('keydown', handleKey);
}, [isPlaying, gameOver, startGame, jump]);
return (
<div className="flex flex-col items-center justify-center min-h-[70vh] p-4">
<button onClick={onBack} className="mb-6 flex items-center gap-2 text-pink-500 font-bold hover:scale-105 transition-all outline-none">
<ArrowLeft size={20} /> Back to Home
</button>
<div
className={`relative w-full max-w-[650px] h-[320px] rounded-[3.5rem] shadow-2xl border-4 transition-colors duration-1000 overflow-hidden cursor-pointer select-none
${isNight ? 'bg-slate-950 border-indigo-500 shadow-indigo-500/20' : 'bg-white border-pink-100 shadow-pink-200/50'}`}
onClick={() => { if (!isPlaying || gameOver) startGame(); else jump(); }}
>
{/* Niebo */}
<div className={`absolute top-10 left-12 transition-all duration-1000 ${isNight ? 'translate-y-0 opacity-100' : '-translate-y-20 opacity-0'}`}>
<Moon className="text-indigo-200 fill-indigo-100" size={48} />
</div>
<div className={`absolute top-10 left-12 transition-all duration-1000 ${isNight ? '-translate-y-20 opacity-0' : 'translate-y-0 opacity-100'}`}>
<Sun className="text-yellow-400 fill-yellow-200 animate-spin-slow" size={48} />
</div>
{/* Wyniki */}
<div className={`absolute top-6 right-8 text-right z-10 font-black transition-colors duration-1000 ${isNight ? 'text-indigo-100' : 'text-pink-500'}`}>
<div className="text-3xl tracking-tighter">Score: {score}</div>
<div className={`text-sm flex items-center justify-end gap-1 ${isNight ? 'text-indigo-400' : 'text-pink-300'}`}>
<Trophy size={14} /> High: {highScore}
</div>
</div>
{/* KOTEK */}
<div className="absolute left-10" style={{ bottom: `${displayKittyY + 48}px` }}>
<DetailedKitty isJumping={displayKittyY > 2} isNight={isNight} isGameOver={gameOver} />
</div>
{/* PRZESZKODA (Kłębek wełny) */}
<div
className={`absolute bottom-12 w-12 h-12 rounded-full border-2 flex items-center justify-center animate-spin transition-colors duration-1000
${isNight ? 'bg-indigo-900 border-indigo-400 shadow-lg shadow-indigo-500/30' : 'bg-pink-200 border-pink-400'}`}
style={{ left: `${displayObstacleX}px` }}
>
<div className={`w-8 h-1 border-t-2 rotate-45 ${isNight ? 'border-indigo-300' : 'border-pink-400'}`}></div>
</div>
{/* Ziemia */}
<div className={`absolute bottom-0 w-full h-12 border-t-4 transition-colors duration-1000 flex items-center justify-around
${isNight ? 'bg-slate-900 border-indigo-900 text-indigo-900' : 'bg-pink-50 border-pink-100 text-pink-200'}`}>
{[...Array(9)].map((_, i) => <span key={i} className="text-2xl">🐾</span>)}
</div>
{/* Ekrany informacyjne */}
{!isPlaying && !gameOver && (
<div className="absolute inset-0 bg-white/20 backdrop-blur-[4px] flex items-center justify-center">
<div className="bg-white p-10 rounded-[3rem] shadow-2xl flex flex-col items-center border-4 border-pink-100">
<Sparkles className="text-yellow-400 mb-2 animate-bounce" size={40} />
<button className="bg-pink-500 text-white px-12 py-4 rounded-2xl font-black text-xl shadow-lg hover:scale-105 transition-all">
START GAME
</button>
</div>
</div>
)}
{gameOver && (
<div className={`absolute inset-0 backdrop-blur-md flex flex-col items-center justify-center text-center p-6 transition-colors duration-1000
${isNight ? 'bg-slate-950/90' : 'bg-pink-50/90'}`}>
<h3 className={`text-5xl font-black mb-4 ${isNight ? 'text-white' : 'text-pink-600'}`}>Meow! 😿</h3>
<p className={`font-bold mb-8 text-2xl ${isNight ? 'text-indigo-300' : 'text-pink-400'}`}>Score: {score}</p>
<button className="bg-pink-500 text-white border-4 border-white px-12 py-4 rounded-2xl font-black text-xl hover:bg-pink-600 transition-all shadow-xl">
TRY AGAIN
</button>
</div>
)}
</div>
</div>
);
};

View File

@@ -0,0 +1,93 @@
import { useState, type FormEvent } from 'react'; // Używamy type FormEvent
import { Cat, ArrowLeft, Loader2, AlertCircle } from 'lucide-react';
import { useAuth } from '../hooks/useAuth';
interface LoginViewProps {
onBack: () => void;
onSuccess: () => void;
}
export const LoginView = ({ onBack, onSuccess }: LoginViewProps) => {
const [isSignUp, setIsSignUp] = useState(false);
const [name, setName] = useState('');
const [password, setPassword] = useState('');
const { signIn, signUp, loading, error, isAuthenticated } = useAuth();
const handleSubmit = async (e: FormEvent) => { // Zmieniono na FormEvent
e.preventDefault();
const result = isSignUp
? await signUp(name, password)
: await signIn(name, password);
if (result) {
onSuccess();
}
};
return (
<div className="flex flex-col items-center justify-center min-h-[80vh] px-4">
<div className="bg-white p-10 rounded-[3rem] shadow-2xl border-4 border-pink-100 w-full max-w-md relative">
<div className="absolute -top-10 left-1/2 -translate-x-1/2 bg-pink-400 p-4 rounded-full shadow-lg text-white">
<Cat size={40} />
</div>
<h2 className="text-3xl font-black text-pink-500 text-center mb-8 mt-4">
{isSignUp ? 'Create Kitty Account' : 'Kitty Login'}
</h2>
{error && (
<div className="mb-6 p-4 bg-red-50 border-2 border-red-100 rounded-2xl text-red-500 text-sm font-bold flex items-center gap-2">
<AlertCircle size={18} /> {error}
</div>
)}
{isAuthenticated && (
<div className="mb-6 p-4 bg-green-50 border-2 border-green-100 rounded-2xl text-green-600 text-sm font-bold text-center">
Success! Meow! 🐾
</div>
)}
<form onSubmit={handleSubmit} className="space-y-4">
<input
type="text"
placeholder="Username or Email"
className="w-full p-4 bg-pink-50 border-2 border-pink-100 rounded-2xl outline-none focus:border-pink-300 transition-all"
value={name}
onChange={(e) => setName(e.target.value)}
required
/>
<input
type="password"
placeholder="Secret Password"
className="w-full p-4 bg-pink-50 border-2 border-pink-100 rounded-2xl outline-none focus:border-pink-300 transition-all"
value={password}
onChange={(e) => setPassword(e.target.value)}
required
/>
<button
type="submit"
disabled={loading}
className="w-full bg-pink-500 hover:bg-pink-600 disabled:bg-pink-300 text-white py-4 rounded-2xl font-bold shadow-lg transition-all active:scale-95 flex items-center justify-center gap-2"
>
{loading ? <Loader2 className="animate-spin" /> : (isSignUp ? 'Register Now' : 'Meow In!')}
</button>
</form>
<div className="mt-6 text-center">
<button
onClick={() => setIsSignUp(!isSignUp)}
className="text-pink-400 text-sm font-bold hover:underline"
>
{isSignUp ? 'Already have an account? Log in' : 'New here? Create an account'}
</button>
</div>
<button onClick={onBack} className="w-full mt-4 text-pink-200 text-xs font-bold flex items-center justify-center gap-2">
<ArrowLeft size={14} /> Back to home
</button>
</div>
</div>
);
};

View File

@@ -0,0 +1,57 @@
import { History as HistoryIcon, LogIn, LogOut, Gamepad2, Wind } from 'lucide-react';
// Używamy 'import type' dla zadowolenia verbatimModuleSyntax
import type { View } from '../App';
interface NavbarProps {
onNavigate: (view: View) => void;
isAuthenticated: boolean;
onLogout: () => void;
}
export const Navbar = ({ onNavigate, isAuthenticated, onLogout }: NavbarProps) => (
<nav className="max-w-5xl mx-auto py-6 px-6 flex justify-end gap-3">
{/* Przycisk Jump Game */}
<button
onClick={() => onNavigate('jump-game')}
className="flex items-center gap-2 px-4 py-2 bg-pink-100 hover:bg-pink-200 rounded-full font-bold text-pink-600 transition-all active:scale-95"
>
<Gamepad2 size={18} /> Jump
</button>
{/* Przycisk Flappy Cat */}
<button
onClick={() => onNavigate('flappy-game')}
className="flex items-center gap-2 px-4 py-2 bg-blue-100 hover:bg-blue-200 rounded-full font-bold text-blue-600 transition-all active:scale-95"
>
<Wind size={18} /> Flappy
</button>
{/* Przycisk History */}
<button
onClick={() => onNavigate('history')}
className="flex items-center gap-2 px-4 py-2 bg-white rounded-full font-bold text-pink-500 border border-pink-100 transition-all active:scale-95"
>
<HistoryIcon size={18} /> History
</button>
{/* Dynamiczny przycisk Logowania / Wylogowania */}
{isAuthenticated ? (
<button
onClick={() => {
onLogout();
onNavigate('home');
}}
className="flex items-center gap-2 px-4 py-2 bg-pink-50 hover:bg-pink-100 rounded-full font-bold text-pink-500 border-2 border-pink-200 transition-all active:scale-95"
>
<LogOut size={18} /> Logout
</button>
) : (
<button
onClick={() => onNavigate('login')}
className="flex items-center gap-2 px-4 py-2 bg-pink-500 hover:bg-pink-600 rounded-full font-bold text-white shadow-lg shadow-pink-200 transition-all active:scale-95"
>
<LogIn size={18} /> Sign In
</button>
)}
</nav>
);

View File

@@ -0,0 +1,6 @@
// src/context/AuthContext.ts
import { createContext } from 'react';
import type { AuthContextType } from '../types/auth';
// Eksportujemy tylko "pusty" kontekst
export const AuthContext = createContext<AuthContextType | undefined>(undefined);

View File

@@ -0,0 +1,60 @@
// src/context/AuthProvider.tsx
import { useState, useCallback, type ReactNode } from 'react';
import { AuthContext } from './AuthContext'; // Importujemy stałą z pliku obok
import { sha512 } from '../utils/crypto';
import type { AuthResponse } from '../types/auth';
export function AuthProvider({ children }: { children: ReactNode }) {
const [token, setToken] = useState<string | null>(sessionStorage.getItem('ktty_token'));
const [loading, setLoading] = useState(false);
const [error, setError] = useState<string | null>(null);
const authRequest = useCallback(async (endpoint: 'signUp' | 'signIn', name: string, pass: string) => {
setLoading(true);
setError(null);
try {
const hashedPassword = await sha512(pass);
const response = await fetch(`/api/v1/user/${endpoint}`, {
method: 'POST',
headers: {
'accept': 'application/json',
'Content-Type': 'application/json',
},
body: JSON.stringify({ name, password: hashedPassword, ttl: 86400 }),
});
const data: AuthResponse = await response.json();
if (!response.ok) throw new Error(data.error || data.message || `Error ${response.status}`);
if (data.token) {
sessionStorage.setItem('ktty_token', data.token);
setToken(data.token); // To aktualizuje stan w całej aplikacji natychmiast!
}
return data;
} catch (err: unknown) {
setError(err instanceof Error ? err.message : 'Unknown error');
return null;
} finally {
setLoading(false);
}
}, []);
const logout = useCallback(() => {
sessionStorage.removeItem('ktty_token');
setToken(null);
}, []);
return (
<AuthContext.Provider value={{
isAuthenticated: !!token,
token,
loading,
error,
signIn: (n, p) => authRequest('signIn', n, p),
signUp: (n, p) => authRequest('signUp', n, p),
logout
}}>
{children}
</AuthContext.Provider>
);
}

View File

@@ -0,0 +1,11 @@
// src/hooks/useAuth.ts
import { useContext } from 'react';
import { AuthContext } from '../context/AuthContext';
export const useAuth = () => {
const context = useContext(AuthContext);
if (!context) {
throw new Error('useAuth must be used within an AuthProvider');
}
return context;
};

View File

@@ -0,0 +1,108 @@
@import "tailwindcss";
/* Jeśli powyższy import nie działa (używasz Tailwind v3), użyj tych trzech linii: */
/* @tailwind base; @tailwind components; @tailwind utilities; */
:root {
background-color: #fff5f8;
}
body {
margin: 0;
font-family: 'Inter', system-ui, -apple-system, sans-serif;
}
#root {
width: 100%;
}
/* Animacja chodzenia - przednie i tylne łapki poruszają się naprzemiennie */
@keyframes kitty-walk {
0%, 100% {
transform: rotate(-20deg);
}
50% {
transform: rotate(20deg);
}
}
@keyframes kitty-walk-alt {
0%, 100% {
transform: rotate(20deg);
}
50% {
transform: rotate(-20deg);
}
}
/* Merdanie ogonkiem */
@keyframes tail-wag {
0%, 100% {
transform: rotate(0deg);
}
50% {
transform: rotate(15deg);
}
}
/* Delikatne pulsowanie ciała (oddychanie) */
@keyframes kitty-breathe {
0%, 100% {
transform: scaleY(1);
}
50% {
transform: scaleY(1.05);
}
}
/* Animacja łapek podczas skoku (podkurczanie) */
.legs-jump {
transform: rotate(45deg) translateY(-5px) !important;
}
/* Animacja oddychania tułowia */
@keyframes kitty-breathe {
0%, 100% { transform: scaleY(1); }
50% { transform: scaleY(1.03); }
}
/* Animacja chodzenia łapek - naprzemienna */
@keyframes kitty-walk {
0%, 100% { transform: rotate(-25deg); }
50% { transform: rotate(25deg); }
}
@keyframes kitty-walk-alt {
0%, 100% { transform: rotate(25deg); }
50% { transform: rotate(-25deg); }
}
/* Merdanie ogonkiem */
@keyframes tail-wag {
0%, 100% { transform: rotate(0deg); }
50% { transform: rotate(20deg); }
}
@keyframes kitty-walk {
0%, 100% { transform: rotate(-30deg) translateY(0); }
50% { transform: rotate(30deg) translateY(-2px); }
}
@keyframes kitty-walk-alt {
0%, 100% { transform: rotate(30deg) translateY(-2px); }
50% { transform: rotate(-30deg) translateY(0); }
}
@keyframes tail-wag {
0%, 100% { transform: rotate(-20deg); }
50% { transform: rotate(10deg); }
}
@keyframes kitty-breathe {
0%, 100% { transform: scale(1); }
50% { transform: scale(1.02); }
}
.animate-spin-slow {
animation: animate-spin-slow 8s linear infinite;
}

View File

@@ -0,0 +1,15 @@
// src/main.tsx
import React from 'react';
import ReactDOM from 'react-dom/client';
import App from './App';
// ZMIANA: Importujemy z AuthProvider, a nie z AuthContext
import { AuthProvider } from './context/AuthProvider';
import './index.css';
ReactDOM.createRoot(document.getElementById('root')!).render(
<React.StrictMode>
<AuthProvider>
<App />
</AuthProvider>
</React.StrictMode>
);

View File

@@ -0,0 +1,17 @@
// src/types/auth.ts
export interface AuthResponse {
token?: string;
message?: string;
error?: string;
status?: string;
}
export interface AuthContextType {
isAuthenticated: boolean;
token: string | null;
loading: boolean;
error: string | null;
signIn: (name: string, pass: string) => Promise<AuthResponse | null>;
signUp: (name: string, pass: string) => Promise<AuthResponse | null>;
logout: () => void;
}

View File

@@ -0,0 +1,17 @@
// src/utils/authUtils.ts
export interface AuthResponse {
token?: string;
message?: string;
error?: string;
}
/**
* Bezpieczne haszowanie SHA-512
*/
export async function sha512(message: string): Promise<string> {
const msgUint8 = new TextEncoder().encode(message);
const hashBuffer = await crypto.subtle.digest('SHA-512', msgUint8);
const hashArray = Array.from(new Uint8Array(hashBuffer));
return hashArray.map(b => b.toString(16).padStart(2, '0')).join('');
}

View File

@@ -0,0 +1,7 @@
// src/utils/crypto.ts
export async function sha512(message: string): Promise<string> {
const msgUint8 = new TextEncoder().encode(message);
const hashBuffer = await crypto.subtle.digest('SHA-512', msgUint8);
const hashArray = Array.from(new Uint8Array(hashBuffer));
return hashArray.map(b => b.toString(16).padStart(2, '0')).join('');
}

View File

@@ -0,0 +1,28 @@
{
"compilerOptions": {
"tsBuildInfoFile": "./node_modules/.tmp/tsconfig.app.tsbuildinfo",
"target": "ES2022",
"useDefineForClassFields": true,
"lib": ["ES2022", "DOM", "DOM.Iterable"],
"module": "ESNext",
"types": ["vite/client"],
"skipLibCheck": true,
/* Bundler mode */
"moduleResolution": "bundler",
"allowImportingTsExtensions": true,
"verbatimModuleSyntax": true,
"moduleDetection": "force",
"noEmit": true,
"jsx": "react-jsx",
/* Linting */
"strict": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"erasableSyntaxOnly": true,
"noFallthroughCasesInSwitch": true,
"noUncheckedSideEffectImports": true
},
"include": ["src"]
}

View File

@@ -0,0 +1,7 @@
{
"files": [],
"references": [
{ "path": "./tsconfig.app.json" },
{ "path": "./tsconfig.node.json" }
]
}

View File

@@ -0,0 +1,26 @@
{
"compilerOptions": {
"tsBuildInfoFile": "./node_modules/.tmp/tsconfig.node.tsbuildinfo",
"target": "ES2023",
"lib": ["ES2023"],
"module": "ESNext",
"types": ["node"],
"skipLibCheck": true,
/* Bundler mode */
"moduleResolution": "bundler",
"allowImportingTsExtensions": true,
"verbatimModuleSyntax": true,
"moduleDetection": "force",
"noEmit": true,
/* Linting */
"strict": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"erasableSyntaxOnly": true,
"noFallthroughCasesInSwitch": true,
"noUncheckedSideEffectImports": true
},
"include": ["vite.config.ts"]
}

View File

@@ -0,0 +1,36 @@
import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react'
import tailwindcss from '@tailwindcss/vite'
export default defineConfig({
plugins: [
react(),
tailwindcss(),
],
server: {
port: 6568,
proxy: {
'/api': {
target: 'https://ktty.is',
changeOrigin: true,
secure: false,
// Dodatkowe nagłówki pomagają oszukać zabezpieczenia serwera (np. Cloudflare)
headers: {
'Origin': 'https://ktty.is',
'Referer': 'https://ktty.is/'
},
configure: (proxy) => {
proxy.on('error', (err) => {
console.log('[Proxy Error]:', err.message);
});
proxy.on('proxyReq', (_, req) => {
console.log(`[Proxy] Wysyłam do zdalnego serwera: ${req.method} ${req.url}`);
});
proxy.on('proxyRes', (proxyRes, req) => {
console.log(`[Proxy] Odpowiedź z ktty.is: ${proxyRes.statusCode} ${req.url}`);
});
},
}
}
},
})