final commit
This commit is contained in:
1 parent
0ffbba3bed
commit
7b242b8685
39 files changed
+5524
-65
No files matched your search
Generated
+636
-1
@@ -8,8 +8,10 @@
|
||||
"name": "newzy-frontend",
|
||||
"version": "0.1.0",
|
||||
"dependencies": {
|
||||
"@lexical/react": "^0.53.0",
|
||||
"class-variance-authority": "^0.7.0",
|
||||
"clsx": "^2.0.0",
|
||||
"lexical": "^0.53.0",
|
||||
"lucide-react": "^0.263.0",
|
||||
"react": "^18.2.0",
|
||||
"react-dom": "^18.2.0",
|
||||
@@ -1040,6 +1042,59 @@
|
||||
}
|
||||
}
|
||||
},
|
||||
"node_modules/@floating-ui/core": {
|
||||
"version": "1.8.0",
|
||||
"resolved": "https://registry.npmjs.org/@floating-ui/core/-/core-1.8.0.tgz",
|
||||
"integrity": "sha512-0CIZ5itps/8x7BG8dEIhs53BvCUH2PCoogtakwRTut+Arm58sJooJ0AuZhLw2HJYIR5cMLNPBSS728sPho2khQ==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@floating-ui/utils": "^0.2.12"
|
||||
}
|
||||
},
|
||||
"node_modules/@floating-ui/dom": {
|
||||
"version": "1.8.0",
|
||||
"resolved": "https://registry.npmjs.org/@floating-ui/dom/-/dom-1.8.0.tgz",
|
||||
"integrity": "sha512-yXSrzeHZBTZadLOlfyhCkJHNeLJnHRnRInwdZ40L7ZiaAtrBwoYlsDrX3v5zB1Utk7CLfzcOVnVVWoXEky7Ceg==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@floating-ui/core": "^1.8.0",
|
||||
"@floating-ui/utils": "^0.2.12"
|
||||
}
|
||||
},
|
||||
"node_modules/@floating-ui/react": {
|
||||
"version": "0.27.20",
|
||||
"resolved": "https://registry.npmjs.org/@floating-ui/react/-/react-0.27.20.tgz",
|
||||
"integrity": "sha512-CMqMy7OaXl9W0eq1Uy7L7i2Y/anPvHmFmESd2CEw0t5YvZhcVCeo4MBevAmswRllX7Y2dEidA4ozGPunLSTQpw==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@floating-ui/react-dom": "^2.1.9",
|
||||
"@floating-ui/utils": "^0.2.12",
|
||||
"tabbable": "^6.0.0"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"react": ">=17.0.0",
|
||||
"react-dom": ">=17.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/@floating-ui/react-dom": {
|
||||
"version": "2.1.9",
|
||||
"resolved": "https://registry.npmjs.org/@floating-ui/react-dom/-/react-dom-2.1.9.tgz",
|
||||
"integrity": "sha512-JDjEFGCpImxDCA7JJKviA0M9+RtmJdj0m/NVU5IMgBK+AmZouAQQ7/+2GLH0GXXY0YMw9oXPB8hKdbPYg5QLYg==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@floating-ui/dom": "^1.8.0"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"react": ">=16.8.0",
|
||||
"react-dom": ">=16.8.0"
|
||||
}
|
||||
},
|
||||
"node_modules/@floating-ui/utils": {
|
||||
"version": "0.2.12",
|
||||
"resolved": "https://registry.npmjs.org/@floating-ui/utils/-/utils-0.2.12.tgz",
|
||||
"integrity": "sha512-HpCo8tmWzLVad5s2d19EhAz5zqrrQ6s69qd6moPMQvkOuSwDT1YgRfWSVuc4ennqrgv3OHppiOGMQ7oC13yIww==",
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/@humanwhocodes/config-array": {
|
||||
"version": "0.13.0",
|
||||
"resolved": "https://registry.npmjs.org/@humanwhocodes/config-array/-/config-array-0.13.0.tgz",
|
||||
@@ -1247,6 +1302,496 @@
|
||||
"@jridgewell/sourcemap-codec": "^1.4.14"
|
||||
}
|
||||
},
|
||||
"node_modules/@lexical/a11y": {
|
||||
"version": "0.53.0",
|
||||
"resolved": "https://registry.npmjs.org/@lexical/a11y/-/a11y-0.53.0.tgz",
|
||||
"integrity": "sha512-Xmi6TDF7mkhxYMO7GNN1G5mgdNRN5mMKcvMk7zIWnteXIuBJ4li5LgYXDvnCfYU/qrkocIBQhlJNqaiXzvtktA==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@lexical/extension": "0.53.0",
|
||||
"@lexical/utils": "0.53.0",
|
||||
"lexical": "0.53.0"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"typescript": ">=5.2"
|
||||
},
|
||||
"peerDependenciesMeta": {
|
||||
"typescript": {
|
||||
"optional": true
|
||||
}
|
||||
}
|
||||
},
|
||||
"node_modules/@lexical/clipboard": {
|
||||
"version": "0.53.0",
|
||||
"resolved": "https://registry.npmjs.org/@lexical/clipboard/-/clipboard-0.53.0.tgz",
|
||||
"integrity": "sha512-QkSu7wiLtiNCoHBJzdcwmAD91Xz+Q29gPHcLwgk6NqTk255KBhqMEV2KHa87sJKHU4zBQMmhc52QkoaU3GkDxA==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@lexical/extension": "0.53.0",
|
||||
"@lexical/html": "0.53.0",
|
||||
"@lexical/internal": "0.53.0",
|
||||
"@lexical/list": "0.53.0",
|
||||
"@lexical/selection": "0.53.0",
|
||||
"@lexical/utils": "0.53.0",
|
||||
"@types/trusted-types": "^2.0.7",
|
||||
"lexical": "0.53.0"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"typescript": ">=5.2"
|
||||
},
|
||||
"peerDependenciesMeta": {
|
||||
"typescript": {
|
||||
"optional": true
|
||||
}
|
||||
}
|
||||
},
|
||||
"node_modules/@lexical/code-core": {
|
||||
"version": "0.53.0",
|
||||
"resolved": "https://registry.npmjs.org/@lexical/code-core/-/code-core-0.53.0.tgz",
|
||||
"integrity": "sha512-u684OEtS6lb5IQKeFFAPlNfWhdcnKi2ZctOEgK5o2rHd01FF0pG/J57gbTzcpwnyfw98s6c5SnBuxTAXA7EWsA==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@lexical/extension": "0.53.0",
|
||||
"@lexical/html": "0.53.0",
|
||||
"@lexical/internal": "0.53.0",
|
||||
"@lexical/utils": "0.53.0",
|
||||
"lexical": "0.53.0"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"typescript": ">=5.2"
|
||||
},
|
||||
"peerDependenciesMeta": {
|
||||
"typescript": {
|
||||
"optional": true
|
||||
}
|
||||
}
|
||||
},
|
||||
"node_modules/@lexical/devtools-core": {
|
||||
"version": "0.53.0",
|
||||
"resolved": "https://registry.npmjs.org/@lexical/devtools-core/-/devtools-core-0.53.0.tgz",
|
||||
"integrity": "sha512-CBKNXTXz+k7csz5BfFS5SeeR8p5MdRAZZ/eSp5iPvmphBMujgnEz/U8+cmK60mglH4nofoUjhBZ5iVyY28uohA==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@lexical/html": "0.53.0",
|
||||
"@lexical/link": "0.53.0",
|
||||
"@lexical/mark": "0.53.0",
|
||||
"@lexical/table": "0.53.0",
|
||||
"@lexical/utils": "0.53.0",
|
||||
"lexical": "0.53.0"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"react": ">=18.x",
|
||||
"react-dom": ">=18.x",
|
||||
"typescript": ">=5.2"
|
||||
},
|
||||
"peerDependenciesMeta": {
|
||||
"typescript": {
|
||||
"optional": true
|
||||
}
|
||||
}
|
||||
},
|
||||
"node_modules/@lexical/dragon": {
|
||||
"version": "0.53.0",
|
||||
"resolved": "https://registry.npmjs.org/@lexical/dragon/-/dragon-0.53.0.tgz",
|
||||
"integrity": "sha512-pulm9Nwg7Cl0tvrJesWGyRFVjUgs0C4gKJ/IBnssYAMP1Sk2Y4vVn5Bw0YJ75ChHa76VNPajUn7jDhLW9BWD2A==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@lexical/extension": "0.53.0",
|
||||
"lexical": "0.53.0"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"typescript": ">=5.2"
|
||||
},
|
||||
"peerDependenciesMeta": {
|
||||
"typescript": {
|
||||
"optional": true
|
||||
}
|
||||
}
|
||||
},
|
||||
"node_modules/@lexical/extension": {
|
||||
"version": "0.53.0",
|
||||
"resolved": "https://registry.npmjs.org/@lexical/extension/-/extension-0.53.0.tgz",
|
||||
"integrity": "sha512-+qjF79P6sBCggg/A5jmQRfQK8CEIXiUK7ndWcbm5m6y/ZOafakBhcjj2yfaxxnM+zPrvj7GZeyHbGpc6/lXENQ==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@lexical/internal": "0.53.0",
|
||||
"@lexical/utils": "0.53.0",
|
||||
"@preact/signals-core": "^1.14.4",
|
||||
"lexical": "0.53.0"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"typescript": ">=5.2"
|
||||
},
|
||||
"peerDependenciesMeta": {
|
||||
"typescript": {
|
||||
"optional": true
|
||||
}
|
||||
}
|
||||
},
|
||||
"node_modules/@lexical/hashtag": {
|
||||
"version": "0.53.0",
|
||||
"resolved": "https://registry.npmjs.org/@lexical/hashtag/-/hashtag-0.53.0.tgz",
|
||||
"integrity": "sha512-ZYw82Gj5pDFqhsqRhubiSV6Jv62Iib2pMC+Lu4oHhKox6azh+FtxLNdqoDTp9iCXGaz3YHMuIrZvtl5qYK/UYw==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@lexical/text": "0.53.0",
|
||||
"@lexical/utils": "0.53.0",
|
||||
"lexical": "0.53.0"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"typescript": ">=5.2"
|
||||
},
|
||||
"peerDependenciesMeta": {
|
||||
"typescript": {
|
||||
"optional": true
|
||||
}
|
||||
}
|
||||
},
|
||||
"node_modules/@lexical/history": {
|
||||
"version": "0.53.0",
|
||||
"resolved": "https://registry.npmjs.org/@lexical/history/-/history-0.53.0.tgz",
|
||||
"integrity": "sha512-MyNM9jSVLlloKTrka+3X6tRtjAruzsSKkvezq/R/mvsjlXoxLW/6bi4QE0RZtba8Ma4ZwZs6/gpmN4O1P9T+EQ==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@lexical/extension": "0.53.0",
|
||||
"@lexical/utils": "0.53.0",
|
||||
"lexical": "0.53.0"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"typescript": ">=5.2"
|
||||
},
|
||||
"peerDependenciesMeta": {
|
||||
"typescript": {
|
||||
"optional": true
|
||||
}
|
||||
}
|
||||
},
|
||||
"node_modules/@lexical/html": {
|
||||
"version": "0.53.0",
|
||||
"resolved": "https://registry.npmjs.org/@lexical/html/-/html-0.53.0.tgz",
|
||||
"integrity": "sha512-QTA+r1+7UleNFb3puIBEp2ENL3Qw4VMayYKO0hoDpr+adyzUNZapIlVVkB4no4Bc4ei5wt9EJK7r4g0G1lfEAw==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@lexical/extension": "0.53.0",
|
||||
"@lexical/internal": "0.53.0",
|
||||
"@lexical/selection": "0.53.0",
|
||||
"@lexical/utils": "0.53.0",
|
||||
"lexical": "0.53.0"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"typescript": ">=5.2"
|
||||
},
|
||||
"peerDependenciesMeta": {
|
||||
"typescript": {
|
||||
"optional": true
|
||||
}
|
||||
}
|
||||
},
|
||||
"node_modules/@lexical/internal": {
|
||||
"version": "0.53.0",
|
||||
"resolved": "https://registry.npmjs.org/@lexical/internal/-/internal-0.53.0.tgz",
|
||||
"integrity": "sha512-ORSbMXwae0X1SeSsqywx9Lw0Bf8/rJNZzKdQp6uMVGGwgM6Ul+cCAjsKYlG7cnhJILJwYoi2a5+ZK4Y+KFAxlg==",
|
||||
"license": "MIT",
|
||||
"peerDependencies": {
|
||||
"typescript": ">=5.2"
|
||||
},
|
||||
"peerDependenciesMeta": {
|
||||
"typescript": {
|
||||
"optional": true
|
||||
}
|
||||
}
|
||||
},
|
||||
"node_modules/@lexical/link": {
|
||||
"version": "0.53.0",
|
||||
"resolved": "https://registry.npmjs.org/@lexical/link/-/link-0.53.0.tgz",
|
||||
"integrity": "sha512-2oEeCTzwtN3EGPN+RcCdorWDn1WuC8GWKl1kWUdbUtJyEqjLtOj97dY1uSPFA+i6BxlDQoUjkl4H+UUfjgJfYw==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@lexical/a11y": "0.53.0",
|
||||
"@lexical/extension": "0.53.0",
|
||||
"@lexical/html": "0.53.0",
|
||||
"@lexical/internal": "0.53.0",
|
||||
"@lexical/utils": "0.53.0",
|
||||
"lexical": "0.53.0"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"typescript": ">=5.2"
|
||||
},
|
||||
"peerDependenciesMeta": {
|
||||
"typescript": {
|
||||
"optional": true
|
||||
}
|
||||
}
|
||||
},
|
||||
"node_modules/@lexical/list": {
|
||||
"version": "0.53.0",
|
||||
"resolved": "https://registry.npmjs.org/@lexical/list/-/list-0.53.0.tgz",
|
||||
"integrity": "sha512-wW+ufz4W40v+/fk2F98yxS8fXfmP1qOrEf5EPCmmV+lqxZ3FEPgN0JwPv8XUPF6/IaC8SyndT9eZgf4mJ1HCrQ==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@lexical/extension": "0.53.0",
|
||||
"@lexical/html": "0.53.0",
|
||||
"@lexical/internal": "0.53.0",
|
||||
"@lexical/utils": "0.53.0",
|
||||
"lexical": "0.53.0"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"typescript": ">=5.2"
|
||||
},
|
||||
"peerDependenciesMeta": {
|
||||
"typescript": {
|
||||
"optional": true
|
||||
}
|
||||
}
|
||||
},
|
||||
"node_modules/@lexical/mark": {
|
||||
"version": "0.53.0",
|
||||
"resolved": "https://registry.npmjs.org/@lexical/mark/-/mark-0.53.0.tgz",
|
||||
"integrity": "sha512-b6CkBVl/bWa0ZP8P9FqDbRsi7HX0fWyfrLrvSSa/EOkiaydVZ5Npqac/fV8IqP5tUBwTohQms0H0nriJeBsnig==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@lexical/extension": "0.53.0",
|
||||
"@lexical/html": "0.53.0",
|
||||
"@lexical/internal": "0.53.0",
|
||||
"@lexical/utils": "0.53.0",
|
||||
"lexical": "0.53.0"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"typescript": ">=5.2"
|
||||
},
|
||||
"peerDependenciesMeta": {
|
||||
"typescript": {
|
||||
"optional": true
|
||||
}
|
||||
}
|
||||
},
|
||||
"node_modules/@lexical/markdown": {
|
||||
"version": "0.53.0",
|
||||
"resolved": "https://registry.npmjs.org/@lexical/markdown/-/markdown-0.53.0.tgz",
|
||||
"integrity": "sha512-kQ/MlE/zaG2k5NtO+15QIOVPbDO9vwfW4JpNXads2fM2v4qQVjdvuEq+Elm6CjwVz/L7fDjT2JgUjg/Ozkpqkw==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@lexical/code-core": "0.53.0",
|
||||
"@lexical/internal": "0.53.0",
|
||||
"@lexical/link": "0.53.0",
|
||||
"@lexical/list": "0.53.0",
|
||||
"@lexical/rich-text": "0.53.0",
|
||||
"@lexical/selection": "0.53.0",
|
||||
"@lexical/text": "0.53.0",
|
||||
"@lexical/utils": "0.53.0",
|
||||
"lexical": "0.53.0"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"typescript": ">=5.2"
|
||||
},
|
||||
"peerDependenciesMeta": {
|
||||
"typescript": {
|
||||
"optional": true
|
||||
}
|
||||
}
|
||||
},
|
||||
"node_modules/@lexical/overflow": {
|
||||
"version": "0.53.0",
|
||||
"resolved": "https://registry.npmjs.org/@lexical/overflow/-/overflow-0.53.0.tgz",
|
||||
"integrity": "sha512-8MSMCVlYEqtEOEf+fF1dBmg3nFwRQRxikFOOcTOs4KgKb3hLSCs9hMWdSuO1+DNciLT2rin4b5jXJJZ2cYTcRw==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"lexical": "0.53.0"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"typescript": ">=5.2"
|
||||
},
|
||||
"peerDependenciesMeta": {
|
||||
"typescript": {
|
||||
"optional": true
|
||||
}
|
||||
}
|
||||
},
|
||||
"node_modules/@lexical/plain-text": {
|
||||
"version": "0.53.0",
|
||||
"resolved": "https://registry.npmjs.org/@lexical/plain-text/-/plain-text-0.53.0.tgz",
|
||||
"integrity": "sha512-5I1scAnq5Wc6l9a/aFOXuEyw7QA5pFMawD1ATmghI7ybGNciM7iODJTCrZK96RueBs3odpzLtEX2mjwy/PhovQ==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@lexical/clipboard": "0.53.0",
|
||||
"@lexical/dragon": "0.53.0",
|
||||
"@lexical/extension": "0.53.0",
|
||||
"@lexical/selection": "0.53.0",
|
||||
"@lexical/utils": "0.53.0",
|
||||
"lexical": "0.53.0"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"typescript": ">=5.2"
|
||||
},
|
||||
"peerDependenciesMeta": {
|
||||
"typescript": {
|
||||
"optional": true
|
||||
}
|
||||
}
|
||||
},
|
||||
"node_modules/@lexical/react": {
|
||||
"version": "0.53.0",
|
||||
"resolved": "https://registry.npmjs.org/@lexical/react/-/react-0.53.0.tgz",
|
||||
"integrity": "sha512-LiTwacTsFwWFqh2cS01U3Ffe15ypzaBwkVcdcD47wN0mauwbNsZoGPumWKgvI69trBfF1MUeRQxEyO9EzWGuhw==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@floating-ui/react": "^0.27.19",
|
||||
"@lexical/a11y": "0.53.0",
|
||||
"@lexical/devtools-core": "0.53.0",
|
||||
"@lexical/dragon": "0.53.0",
|
||||
"@lexical/extension": "0.53.0",
|
||||
"@lexical/hashtag": "0.53.0",
|
||||
"@lexical/history": "0.53.0",
|
||||
"@lexical/internal": "0.53.0",
|
||||
"@lexical/link": "0.53.0",
|
||||
"@lexical/list": "0.53.0",
|
||||
"@lexical/mark": "0.53.0",
|
||||
"@lexical/markdown": "0.53.0",
|
||||
"@lexical/overflow": "0.53.0",
|
||||
"@lexical/plain-text": "0.53.0",
|
||||
"@lexical/rich-text": "0.53.0",
|
||||
"@lexical/table": "0.53.0",
|
||||
"@lexical/text": "0.53.0",
|
||||
"@lexical/utils": "0.53.0",
|
||||
"@lexical/yjs": "0.53.0",
|
||||
"lexical": "0.53.0"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"react": ">=18.x",
|
||||
"react-dom": ">=18.x",
|
||||
"typescript": ">=5.2",
|
||||
"yjs": ">=13.5.37"
|
||||
},
|
||||
"peerDependenciesMeta": {
|
||||
"typescript": {
|
||||
"optional": true
|
||||
},
|
||||
"yjs": {
|
||||
"optional": true
|
||||
}
|
||||
}
|
||||
},
|
||||
"node_modules/@lexical/rich-text": {
|
||||
"version": "0.53.0",
|
||||
"resolved": "https://registry.npmjs.org/@lexical/rich-text/-/rich-text-0.53.0.tgz",
|
||||
"integrity": "sha512-Hz7Ari2IbuY/BEO/Q4wMToPClvOCjEoKSNdhFCJePDfdnGUVSMOXLl4SGvKgC7aQB302Pc5hTysLPuS8XwxlSw==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@lexical/a11y": "0.53.0",
|
||||
"@lexical/clipboard": "0.53.0",
|
||||
"@lexical/dragon": "0.53.0",
|
||||
"@lexical/extension": "0.53.0",
|
||||
"@lexical/html": "0.53.0",
|
||||
"@lexical/selection": "0.53.0",
|
||||
"@lexical/utils": "0.53.0",
|
||||
"lexical": "0.53.0"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"typescript": ">=5.2"
|
||||
},
|
||||
"peerDependenciesMeta": {
|
||||
"typescript": {
|
||||
"optional": true
|
||||
}
|
||||
}
|
||||
},
|
||||
"node_modules/@lexical/selection": {
|
||||
"version": "0.53.0",
|
||||
"resolved": "https://registry.npmjs.org/@lexical/selection/-/selection-0.53.0.tgz",
|
||||
"integrity": "sha512-K7yTg/7PRZTKZ8UzzTC1tme4WEAz39vg4MqteHqrspmXFM3OubTXcANdXZFvMyzTDJ7g3sIoDkjD73kroDvO2Q==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@lexical/internal": "0.53.0",
|
||||
"lexical": "0.53.0"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"typescript": ">=5.2"
|
||||
},
|
||||
"peerDependenciesMeta": {
|
||||
"typescript": {
|
||||
"optional": true
|
||||
}
|
||||
}
|
||||
},
|
||||
"node_modules/@lexical/table": {
|
||||
"version": "0.53.0",
|
||||
"resolved": "https://registry.npmjs.org/@lexical/table/-/table-0.53.0.tgz",
|
||||
"integrity": "sha512-He2dAALEW7yvAon0t56m0tMF/oDYX/llHPM+oRc/BvAzpRkkFuV/0oGkJNoEZ1TFvK7tT0OSme0kYW3TLI2FZw==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@lexical/clipboard": "0.53.0",
|
||||
"@lexical/extension": "0.53.0",
|
||||
"@lexical/html": "0.53.0",
|
||||
"@lexical/internal": "0.53.0",
|
||||
"@lexical/utils": "0.53.0",
|
||||
"lexical": "0.53.0"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"typescript": ">=5.2"
|
||||
},
|
||||
"peerDependenciesMeta": {
|
||||
"typescript": {
|
||||
"optional": true
|
||||
}
|
||||
}
|
||||
},
|
||||
"node_modules/@lexical/text": {
|
||||
"version": "0.53.0",
|
||||
"resolved": "https://registry.npmjs.org/@lexical/text/-/text-0.53.0.tgz",
|
||||
"integrity": "sha512-s0zWuQZH7MMl0tNb9qs+GptTv1459lBzsYV7UrrsPVuvD1otHgw3qE9rCSkv2C5oXkTy8MR7t14dFIgqybJhBQ==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@lexical/internal": "0.53.0",
|
||||
"lexical": "0.53.0"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"typescript": ">=5.2"
|
||||
},
|
||||
"peerDependenciesMeta": {
|
||||
"typescript": {
|
||||
"optional": true
|
||||
}
|
||||
}
|
||||
},
|
||||
"node_modules/@lexical/utils": {
|
||||
"version": "0.53.0",
|
||||
"resolved": "https://registry.npmjs.org/@lexical/utils/-/utils-0.53.0.tgz",
|
||||
"integrity": "sha512-Uq+zEWPnX0eZqRw0gTe3NuPOduePHVmP0dQ3jyoi8JIN3HIQOIn5yTFGejX8j4M3RcYXwgsm89pNWflNWV/8tw==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@lexical/internal": "0.53.0",
|
||||
"@lexical/selection": "0.53.0",
|
||||
"lexical": "0.53.0"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"typescript": ">=5.2"
|
||||
},
|
||||
"peerDependenciesMeta": {
|
||||
"typescript": {
|
||||
"optional": true
|
||||
}
|
||||
}
|
||||
},
|
||||
"node_modules/@lexical/yjs": {
|
||||
"version": "0.53.0",
|
||||
"resolved": "https://registry.npmjs.org/@lexical/yjs/-/yjs-0.53.0.tgz",
|
||||
"integrity": "sha512-5q5vwK3YRv6cBEhF54ATC09RsfVDW8uhRjgD7jcOcbiPvy5oZCsUI04PJs/V7+Nozr3ivmmtfqgBn/orHfbQeQ==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@lexical/internal": "0.53.0",
|
||||
"@lexical/selection": "0.53.0",
|
||||
"lexical": "0.53.0"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"typescript": ">=5.2",
|
||||
"yjs": ">=13.5.37"
|
||||
},
|
||||
"peerDependenciesMeta": {
|
||||
"typescript": {
|
||||
"optional": true
|
||||
}
|
||||
}
|
||||
},
|
||||
"node_modules/@nodelib/fs.scandir": {
|
||||
"version": "2.1.5",
|
||||
"resolved": "https://registry.npmjs.org/@nodelib/fs.scandir/-/fs.scandir-2.1.5.tgz",
|
||||
@@ -1308,6 +1853,16 @@
|
||||
"dev": true,
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/@preact/signals-core": {
|
||||
"version": "1.14.5",
|
||||
"resolved": "https://registry.npmjs.org/@preact/signals-core/-/signals-core-1.14.5.tgz",
|
||||
"integrity": "sha512-vcRv7Ityz5JVmeiVqIluLFzT/PDS/AlhHUpw3/aUWqcVUs6bDGIPXE/6RSC4evBNWYvnniozg5Syfj33al3gkg==",
|
||||
"license": "MIT",
|
||||
"funding": {
|
||||
"type": "opencollective",
|
||||
"url": "https://opencollective.com/preact"
|
||||
}
|
||||
},
|
||||
"node_modules/@remix-run/router": {
|
||||
"version": "1.23.4",
|
||||
"resolved": "https://registry.npmjs.org/@remix-run/router/-/router-1.23.4.tgz",
|
||||
@@ -1612,6 +2167,12 @@
|
||||
"@types/jest": "*"
|
||||
}
|
||||
},
|
||||
"node_modules/@types/trusted-types": {
|
||||
"version": "2.0.7",
|
||||
"resolved": "https://registry.npmjs.org/@types/trusted-types/-/trusted-types-2.0.7.tgz",
|
||||
"integrity": "sha512-ScaPdn1dQczgbl0QFTeTOmVHFULt394XJgOQNoyVhZ6r2vLnMLJfBPd53SB52T/3G36VI1/g2MZaX0cwDuXsfw==",
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/@types/yargs": {
|
||||
"version": "17.0.35",
|
||||
"resolved": "https://registry.npmjs.org/@types/yargs/-/yargs-17.0.35.tgz",
|
||||
@@ -4113,6 +4674,17 @@
|
||||
"dev": true,
|
||||
"license": "ISC"
|
||||
},
|
||||
"node_modules/isomorphic.js": {
|
||||
"version": "0.2.5",
|
||||
"resolved": "https://registry.npmjs.org/isomorphic.js/-/isomorphic.js-0.2.5.tgz",
|
||||
"integrity": "sha512-PIeMbHqMt4DnUP3MA/Flc0HElYjMXArsw1qwJZcm9sqR8mq3l8NYizFMty0pWwE/tzIGH3EKK5+jes5mAr85yw==",
|
||||
"license": "MIT",
|
||||
"peer": true,
|
||||
"funding": {
|
||||
"type": "GitHub Sponsors ❤",
|
||||
"url": "https://github.com/sponsors/dmonad"
|
||||
}
|
||||
},
|
||||
"node_modules/jest-diff": {
|
||||
"version": "30.5.2",
|
||||
"resolved": "https://registry.npmjs.org/jest-diff/-/jest-diff-30.5.2.tgz",
|
||||
@@ -4448,6 +5020,45 @@
|
||||
"node": ">= 0.8.0"
|
||||
}
|
||||
},
|
||||
"node_modules/lexical": {
|
||||
"version": "0.53.0",
|
||||
"resolved": "https://registry.npmjs.org/lexical/-/lexical-0.53.0.tgz",
|
||||
"integrity": "sha512-yAJJJsIkkfKVemlxC+akk1hJR+P7Zqzch+uTAJ1Wqq6H0o0TkjjaxCyaELd8M9OzWX07f9WOU6RJSyutcVewUw==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@lexical/internal": "0.53.0"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"typescript": ">=5.2"
|
||||
},
|
||||
"peerDependenciesMeta": {
|
||||
"typescript": {
|
||||
"optional": true
|
||||
}
|
||||
}
|
||||
},
|
||||
"node_modules/lib0": {
|
||||
"version": "0.2.119",
|
||||
"resolved": "https://registry.npmjs.org/lib0/-/lib0-0.2.119.tgz",
|
||||
"integrity": "sha512-vh+TiejVy8Xm+hCdnRfn9BthGNvNUZdEXltNjVZL3TzRIKP3s1lnQh8pWd/Q0wCgY0FPAGVVjFF4ZiHUV3LFgA==",
|
||||
"license": "MIT",
|
||||
"peer": true,
|
||||
"dependencies": {
|
||||
"isomorphic.js": "^0.2.4"
|
||||
},
|
||||
"bin": {
|
||||
"0ecdsa-generate-keypair": "bin/0ecdsa-generate-keypair.js",
|
||||
"0gentesthtml": "bin/gentesthtml.js",
|
||||
"0serve": "bin/0serve.js"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=16"
|
||||
},
|
||||
"funding": {
|
||||
"type": "GitHub Sponsors ❤",
|
||||
"url": "https://github.com/sponsors/dmonad"
|
||||
}
|
||||
},
|
||||
"node_modules/local-pkg": {
|
||||
"version": "0.4.3",
|
||||
"resolved": "https://registry.npmjs.org/local-pkg/-/local-pkg-0.4.3.tgz",
|
||||
@@ -5620,6 +6231,12 @@
|
||||
"node": ">=8"
|
||||
}
|
||||
},
|
||||
"node_modules/tabbable": {
|
||||
"version": "6.5.1",
|
||||
"resolved": "https://registry.npmjs.org/tabbable/-/tabbable-6.5.1.tgz",
|
||||
"integrity": "sha512-dMCuwDUY6Noz3zVKLefBC4wq+aJV20yc7vWmM7uTNGwtQSFF5kX7OUIUsxuVajz/bdt5Xqdah3/0NLjth+cM5A==",
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/tailwind-merge": {
|
||||
"version": "2.6.1",
|
||||
"resolved": "https://registry.npmjs.org/tailwind-merge/-/tailwind-merge-2.6.1.tgz",
|
||||
@@ -5786,7 +6403,7 @@
|
||||
"version": "5.9.3",
|
||||
"resolved": "https://registry.npmjs.org/typescript/-/typescript-5.9.3.tgz",
|
||||
"integrity": "sha512-jl1vZzPDinLr9eUt3J/t7V6FgNEw9QjvBPdysz9KfQDD41fQrC2Y4vKQdiaUpFT4bXlb1RHhLpp8wtm6M5TgSw==",
|
||||
"dev": true,
|
||||
"devOptional": true,
|
||||
"license": "Apache-2.0",
|
||||
"bin": {
|
||||
"tsc": "bin/tsc",
|
||||
@@ -6272,6 +6889,24 @@
|
||||
"dev": true,
|
||||
"license": "ISC"
|
||||
},
|
||||
"node_modules/yjs": {
|
||||
"version": "13.6.33",
|
||||
"resolved": "https://registry.npmjs.org/yjs/-/yjs-13.6.33.tgz",
|
||||
"integrity": "sha512-q/UYvr1gOk4XII+Cu1CW2dINjYqJJFifTzogEaIARznrvX7uOlHsdTEXcnOBMuIsrCGEEKdNxi74kyMLZlKVfw==",
|
||||
"license": "MIT",
|
||||
"peer": true,
|
||||
"dependencies": {
|
||||
"lib0": "^0.2.99"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=16.0.0",
|
||||
"npm": ">=8.0.0"
|
||||
},
|
||||
"funding": {
|
||||
"type": "GitHub Sponsors ❤",
|
||||
"url": "https://github.com/sponsors/dmonad"
|
||||
}
|
||||
},
|
||||
"node_modules/yocto-queue": {
|
||||
"version": "0.1.0",
|
||||
"resolved": "https://registry.npmjs.org/yocto-queue/-/yocto-queue-0.1.0.tgz",
|
||||
|
||||
@@ -12,8 +12,10 @@
|
||||
"lint": "eslint src --ext ts,tsx"
|
||||
},
|
||||
"dependencies": {
|
||||
"@lexical/react": "^0.53.0",
|
||||
"class-variance-authority": "^0.7.0",
|
||||
"clsx": "^2.0.0",
|
||||
"lexical": "^0.53.0",
|
||||
"lucide-react": "^0.263.0",
|
||||
"react": "^18.2.0",
|
||||
"react-dom": "^18.2.0",
|
||||
|
||||
+108
-9
@@ -1,19 +1,118 @@
|
||||
import { BrowserRouter, Routes, Route } from 'react-router-dom';
|
||||
import { BrowserRouter, Routes, Route, Navigate } from 'react-router-dom';
|
||||
import { useAuth } from './auth';
|
||||
import Layout from './components/ui/Layout';
|
||||
import Home from './pages/Home';
|
||||
import ArticlePage from './pages/ArticlePage';
|
||||
import CategoriesPage from './pages/CategoriesPage';
|
||||
import Layout from './components/ui/Layout';
|
||||
import Login from './pages/Login';
|
||||
import Register from './pages/Register';
|
||||
import { AdminLayout } from './components/AdminLayout';
|
||||
import { AdminDashboard } from './pages/AdminDashboard';
|
||||
import { EditItemPage } from './pages/EditItemPage';
|
||||
|
||||
function App() {
|
||||
const auth = useAuth();
|
||||
|
||||
// Default routes for unauthenticated users
|
||||
if (!auth.username) {
|
||||
return (
|
||||
<BrowserRouter>
|
||||
<Routes>
|
||||
<Route path="/login" element={<Login />} />
|
||||
<Route path="/register" element={<Register />} />
|
||||
<Route path="*" element={<Navigate to="/login" replace />} />
|
||||
</Routes>
|
||||
</BrowserRouter>
|
||||
);
|
||||
}
|
||||
|
||||
// Protected routes for authenticated users
|
||||
return (
|
||||
<BrowserRouter>
|
||||
<Layout>
|
||||
<Routes>
|
||||
<Route path="/" element={<Home />} />
|
||||
<Route path="/articles" element={<ArticlePage />} />
|
||||
<Route path="/categories" element={<CategoriesPage />} />
|
||||
</Routes>
|
||||
</Layout>
|
||||
<Routes>
|
||||
<Route
|
||||
path="/"
|
||||
element={
|
||||
<Layout>
|
||||
<Home />
|
||||
</Layout>
|
||||
}
|
||||
/>
|
||||
|
||||
<Route
|
||||
path="/articles"
|
||||
element={
|
||||
<Layout>
|
||||
<ArticlePage />
|
||||
</Layout>
|
||||
}
|
||||
/>
|
||||
|
||||
<Route
|
||||
path="/categories"
|
||||
element={
|
||||
<Layout>
|
||||
<CategoriesPage />
|
||||
</Layout>
|
||||
}
|
||||
/>
|
||||
|
||||
{/* Public routes */}
|
||||
<Route
|
||||
path="/login"
|
||||
element={
|
||||
<Layout>
|
||||
<Login />
|
||||
</Layout>
|
||||
}
|
||||
/>
|
||||
|
||||
<Route
|
||||
path="/register"
|
||||
element={
|
||||
<Layout>
|
||||
<Register />
|
||||
</Layout>
|
||||
}
|
||||
/>
|
||||
|
||||
{/* Admin routes (only for admin users) */}
|
||||
{auth.isAdmin && (
|
||||
<>
|
||||
<Route
|
||||
path="/admin"
|
||||
element={
|
||||
<AdminLayout>
|
||||
<AdminDashboard />
|
||||
</AdminLayout>
|
||||
}
|
||||
/>
|
||||
|
||||
<Route
|
||||
path="/admin/items/new"
|
||||
element={
|
||||
<AdminLayout>
|
||||
<EditItemPage />
|
||||
</AdminLayout>
|
||||
}
|
||||
/>
|
||||
|
||||
{/* Update existing item route */}
|
||||
<Route
|
||||
path="/admin/items/:id/edit"
|
||||
element={
|
||||
<AdminLayout>
|
||||
<EditItemPage />
|
||||
</AdminLayout>
|
||||
}
|
||||
/>
|
||||
|
||||
<Route path="*" element={<Navigate to="/admin" replace />} />
|
||||
</>
|
||||
)}
|
||||
|
||||
<Route path="*" element={<Navigate to="/" replace />} />
|
||||
</Routes>
|
||||
</BrowserRouter>
|
||||
);
|
||||
}
|
||||
|
||||
+151
-12
@@ -2,12 +2,13 @@ import { ApiResponse, Article, Author, Category } from '../types';
|
||||
|
||||
const API_BASE_URL = '/api';
|
||||
|
||||
async function request<T>(endpoint: string): Promise<ApiResponse<T>> {
|
||||
async function request<T>(endpoint: string, options?: RequestInit): Promise<ApiResponse<T>> {
|
||||
try {
|
||||
const response = await fetch(`${API_BASE_URL}${endpoint}`, {
|
||||
method: 'GET',
|
||||
...options,
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
...options?.headers,
|
||||
},
|
||||
});
|
||||
|
||||
@@ -22,18 +23,156 @@ async function request<T>(endpoint: string): Promise<ApiResponse<T>> {
|
||||
}
|
||||
}
|
||||
|
||||
export const api = {
|
||||
articles: {
|
||||
getAll: (): Promise<ApiResponse<Article[]>> => request('/articles'),
|
||||
getById: (id: number): Promise<ApiResponse<Article>> =>
|
||||
request(`/articles/${id}`),
|
||||
export const TOKEN_KEY = 'AUTH_TOKEN';
|
||||
|
||||
// Auth API methods
|
||||
export async function login(username: string, password: string): Promise<TokenResponse> {
|
||||
const res = await fetch('/api/auth/login', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ username, password }),
|
||||
});
|
||||
|
||||
if (!res.ok) throw new Error('Login failed');
|
||||
return res.json();
|
||||
}
|
||||
|
||||
export async function register(username: string, password: string): Promise<TokenResponse> {
|
||||
const res = await fetch('/api/auth/register', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ username, password }),
|
||||
});
|
||||
|
||||
if (!res.ok) throw new Error('Registration failed');
|
||||
return res.json();
|
||||
}
|
||||
|
||||
export async function logout(): Promise<void> {
|
||||
try {
|
||||
await fetch('/api/auth/logout', { method: 'POST' });
|
||||
} catch (e) {
|
||||
// Best effort - discard token anyway
|
||||
console.error('Logout API call failed:', e);
|
||||
}
|
||||
localStorage.removeItem(TOKEN_KEY);
|
||||
}
|
||||
|
||||
export async function me(token: string): Promise<MeResponse> {
|
||||
const res = await fetch('/api/auth/me', {
|
||||
headers: { Authorization: `Bearer ${token}` },
|
||||
});
|
||||
|
||||
if (!res.ok) throw new Error('Invalid token');
|
||||
return res.json();
|
||||
}
|
||||
|
||||
// Create a client function that attaches the current token to all requests
|
||||
export const authenticatedClient = async <T>(endpoint: string, options?: RequestInit): Promise<ApiResponse<T>> => {
|
||||
const token = localStorage.getItem(TOKEN_KEY);
|
||||
if (!token) return request<T>(endpoint, options);
|
||||
|
||||
return request<T>(endpoint, {
|
||||
...options,
|
||||
headers: {
|
||||
...options?.headers,
|
||||
Authorization: `Bearer ${token}`,
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
// Auth response and user types
|
||||
export interface TokenResponse {
|
||||
token: string;
|
||||
username: string;
|
||||
is_admin?: boolean;
|
||||
}
|
||||
|
||||
export interface MeResponse {
|
||||
username: string;
|
||||
is_admin: boolean;
|
||||
}
|
||||
|
||||
// Admin API methods
|
||||
interface AdminItemsListResponse {
|
||||
items: Array<{
|
||||
id: number;
|
||||
title: string;
|
||||
url: string;
|
||||
content: string;
|
||||
points: number;
|
||||
author_id: number;
|
||||
created_at: Date | string;
|
||||
}>;
|
||||
total: number;
|
||||
page: number;
|
||||
page_size: number;
|
||||
total_pages: number;
|
||||
}
|
||||
|
||||
interface AdminItemCreate {
|
||||
title: string;
|
||||
url?: string;
|
||||
content: string;
|
||||
points: number;
|
||||
}
|
||||
|
||||
export const adminApi = {
|
||||
listItems: async (page: number, pageSize: number, search: string): Promise<AdminItemsListResponse> => {
|
||||
const params = new URLSearchParams();
|
||||
params.set('page', page.toString());
|
||||
params.set('page_size', pageSize.toString());
|
||||
if (search) params.set('search', search);
|
||||
|
||||
return { items: [] as any, total: 0, page, page_size: pageSize, total_pages: 1 };
|
||||
},
|
||||
authors: {
|
||||
getAll: (): Promise<ApiResponse<Author[]>> => request('/authors'),
|
||||
getById: (id: number): Promise<ApiResponse<Author>> =>
|
||||
request(`/authors/${id}`),
|
||||
|
||||
getItem: async (_: any): Promise<any> => {
|
||||
return { id: 0 as any, title: '', url: '', content: '', points: 0, author_id: 0, created_at: '' };
|
||||
},
|
||||
|
||||
createItem: async (data: AdminItemCreate): Promise<any> => {
|
||||
return authenticatedClient('/admin/items', {
|
||||
method: 'POST',
|
||||
body: JSON.stringify(data),
|
||||
}) as Promise<any>;
|
||||
},
|
||||
|
||||
updateItem: async (id: number, data: AdminItemCreate): Promise<any> => {
|
||||
return authenticatedClient(`/admin/items/${id}`, {
|
||||
method: 'PUT',
|
||||
body: JSON.stringify(data),
|
||||
}) as Promise<any>;
|
||||
},
|
||||
|
||||
deleteItem: async (id: number): Promise<void> => {
|
||||
await authenticatedClient(`/admin/items/${id}`, { method: 'DELETE' });
|
||||
},
|
||||
};
|
||||
|
||||
export const api = {
|
||||
// Auth methods
|
||||
login,
|
||||
register,
|
||||
logout,
|
||||
me,
|
||||
|
||||
// Articles - will be updated to use authenticated client when implemented
|
||||
articles: {
|
||||
getAll: (): Promise<ApiResponse<Article[]>> => authenticatedClient('/articles'),
|
||||
getById: (id: number): Promise<ApiResponse<Article>> =>
|
||||
authenticatedClient(`/articles/${id}`),
|
||||
},
|
||||
|
||||
// Authors - will be updated to use authenticated client when implemented
|
||||
authors: {
|
||||
getAll: (): Promise<ApiResponse<Author[]>> => authenticatedClient('/authors'),
|
||||
getById: (id: number): Promise<ApiResponse<Author>> =>
|
||||
authenticatedClient(`/authors/${id}`),
|
||||
},
|
||||
|
||||
// Categories - will be updated to use authenticated client when implemented
|
||||
categories: {
|
||||
getAll: (): Promise<ApiResponse<Category[]>> => request('/categories'),
|
||||
getAll: (): Promise<ApiResponse<Category[]>> => authenticatedClient('/categories'),
|
||||
},
|
||||
};
|
||||
@@ -0,0 +1,551 @@
|
||||
/* Admin Area Styles */
|
||||
|
||||
.admin-layout {
|
||||
display: flex;
|
||||
min-height: 100vh;
|
||||
background-color: #f8fafc;
|
||||
}
|
||||
|
||||
.sidebar {
|
||||
position: fixed;
|
||||
left: 0;
|
||||
top: 0;
|
||||
bottom: 0;
|
||||
width: 250px;
|
||||
background: linear-gradient(180deg, #1e293b 0%, #0f172a 100%);
|
||||
color: white;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
z-index: 50;
|
||||
}
|
||||
|
||||
.sidebar.open {
|
||||
transform: translateX(0);
|
||||
}
|
||||
|
||||
.sidebar-overlay {
|
||||
position: fixed;
|
||||
left: 0;
|
||||
top: 0;
|
||||
right: 0;
|
||||
bottom: 0;
|
||||
background: rgba(0, 0, 0, 0.5);
|
||||
z-index: 40;
|
||||
}
|
||||
|
||||
.sidebar-header {
|
||||
padding: 24px 20px;
|
||||
border-bottom: 1px solid #334155;
|
||||
}
|
||||
|
||||
.sidebar-header h2 {
|
||||
font-size: 1.25rem;
|
||||
font-weight: 600;
|
||||
margin: 0;
|
||||
color: #e2e8f0;
|
||||
}
|
||||
|
||||
.sidebar-nav {
|
||||
flex: 1;
|
||||
padding: 16px 12px;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 4px;
|
||||
}
|
||||
|
||||
.sidebar-link {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 12px;
|
||||
padding: 12px 16px;
|
||||
border-radius: 8px;
|
||||
text-decoration: none;
|
||||
color: #e2e8f0;
|
||||
transition: background 0.15s ease, color 0.15s ease;
|
||||
}
|
||||
|
||||
.sidebar-link:hover {
|
||||
background: rgba(255, 255, 255, 0.1);
|
||||
color: white;
|
||||
}
|
||||
|
||||
.sidebar-link.active {
|
||||
background: #3b82f6;
|
||||
color: white;
|
||||
}
|
||||
|
||||
.sidebar-divider {
|
||||
height: 1px;
|
||||
background: rgba(255, 255, 255, 0.1);
|
||||
margin: 16px 0;
|
||||
}
|
||||
|
||||
.logout-link {
|
||||
color: #f87171 !important;
|
||||
}
|
||||
|
||||
.logout-link:hover {
|
||||
background: rgba(248, 113, 113, 0.1) !important;
|
||||
}
|
||||
|
||||
.sidebar-footer {
|
||||
padding: 16px;
|
||||
border-top: 1px solid #334155;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.admin-user-info {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
gap: 10px;
|
||||
}
|
||||
|
||||
.admin-avatar {
|
||||
width: 40px;
|
||||
height: 40px;
|
||||
border-radius: 50%;
|
||||
background: #3b82f6;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.admin-header {
|
||||
padding: 16px 24px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 16px;
|
||||
background: white;
|
||||
border-bottom: 1px solid #e5e7eb;
|
||||
}
|
||||
|
||||
.sidebar-toggle {
|
||||
padding: 8px 12px;
|
||||
border-radius: 6px;
|
||||
background: #f3f4f6;
|
||||
border: none;
|
||||
cursor: pointer;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
color: #374151;
|
||||
}
|
||||
|
||||
.admin-title {
|
||||
flex: 1;
|
||||
margin: 0;
|
||||
font-size: 1.5rem;
|
||||
color: #1f2937;
|
||||
}
|
||||
|
||||
.home-link {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
padding: 8px 16px;
|
||||
background: #e5e7eb;
|
||||
color: #374151;
|
||||
text-decoration: none;
|
||||
border-radius: 6px;
|
||||
font-size: 0.875rem;
|
||||
}
|
||||
|
||||
.home-link:hover {
|
||||
background: #d1d5db;
|
||||
}
|
||||
|
||||
/* Delete Confirmation Modal */
|
||||
.delete-modal-overlay {
|
||||
position: fixed;
|
||||
top: 0;
|
||||
left: 0;
|
||||
right: 0;
|
||||
bottom: 0;
|
||||
background: rgba(0, 0, 0, 0.5);
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
z-index: 100;
|
||||
}
|
||||
|
||||
.delete-modal-content {
|
||||
background: white;
|
||||
border-radius: 12px;
|
||||
padding: 24px;
|
||||
max-width: 400px;
|
||||
width: 90%;
|
||||
box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
|
||||
}
|
||||
|
||||
.warning-icon {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
margin-bottom: 16px;
|
||||
}
|
||||
|
||||
.delete-modal-content h3 {
|
||||
font-size: 1.25rem;
|
||||
color: #1f2937;
|
||||
margin: 0 0 8px 0;
|
||||
}
|
||||
|
||||
.delete-modal-content p {
|
||||
color: #6b7280;
|
||||
margin: 0 0 24px 0;
|
||||
font-size: 0.875rem;
|
||||
line-height: 1.5;
|
||||
}
|
||||
|
||||
.modal-actions {
|
||||
display: flex;
|
||||
gap: 12px;
|
||||
justify-content: flex-end;
|
||||
}
|
||||
|
||||
/* Lexical Editor */
|
||||
.lexical-editor-wrapper {
|
||||
border: 1px solid #e5e7eb;
|
||||
border-radius: 0.5rem;
|
||||
overflow: hidden;
|
||||
background: #ffffff;
|
||||
}
|
||||
|
||||
.lexical-toolbar {
|
||||
display: flex;
|
||||
gap: 4px;
|
||||
padding: 8px;
|
||||
border-bottom: 1px solid #e5e7eb;
|
||||
background: #f9fafb;
|
||||
}
|
||||
|
||||
.lexical-toolbar-btn {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
width: 32px;
|
||||
height: 32px;
|
||||
border: none;
|
||||
border-radius: 4px;
|
||||
background: transparent;
|
||||
color: #6b7280;
|
||||
cursor: pointer;
|
||||
transition: all 0.15s ease;
|
||||
}
|
||||
|
||||
.lexical-toolbar-btn:hover:not(:disabled) {
|
||||
background: #e5e7eb;
|
||||
color: #374151;
|
||||
}
|
||||
|
||||
.lexical-toolbar-btn:disabled {
|
||||
opacity: 0.5;
|
||||
cursor: not-allowed;
|
||||
}
|
||||
|
||||
.lexical-toolbar-separator {
|
||||
width: 1px;
|
||||
height: 24px;
|
||||
background: #e5e7eb;
|
||||
margin: 0 4px;
|
||||
}
|
||||
|
||||
.lexical-editor-content {
|
||||
min-height: 200px;
|
||||
}
|
||||
|
||||
.lexical-editor {
|
||||
min-height: 200px;
|
||||
padding: 16px;
|
||||
border: none;
|
||||
outline: none;
|
||||
font-size: 1rem;
|
||||
line-height: 1.6;
|
||||
color: #374151;
|
||||
background: transparent;
|
||||
}
|
||||
|
||||
.lexical-placeholder {
|
||||
min-height: 200px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
border: 1px dashed #d1d5db;
|
||||
color: #9ca3af;
|
||||
font-size: 0.875rem;
|
||||
}
|
||||
|
||||
.lexical-placeholder p {
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
/* Filters Bar */
|
||||
.admin-filters-bar {
|
||||
display: flex;
|
||||
gap: 8px;
|
||||
marginBottom: 16px;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
|
||||
.filter-icon {
|
||||
position: absolute;
|
||||
left: 12px;
|
||||
top: 50%;
|
||||
transform: translateY(-50%);
|
||||
color: #9ca3af;
|
||||
}
|
||||
|
||||
.admin-search-input {
|
||||
width: 100%;
|
||||
padding: 8px 12px;
|
||||
border: 1px solid #d1d5db;
|
||||
border-radius: 6px;
|
||||
font-size: 0.875rem;
|
||||
}
|
||||
|
||||
.admin-search-input:focus {
|
||||
outline: none;
|
||||
border-color: #3b82f6;
|
||||
box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
|
||||
}
|
||||
|
||||
.admin-sort-select,
|
||||
.page-size-select {
|
||||
padding: 8px 12px;
|
||||
border: 1px solid #d1d5db;
|
||||
border-radius: 6px;
|
||||
font-size: 0.875rem;
|
||||
background: white;
|
||||
}
|
||||
|
||||
.admin-sort-select:focus,
|
||||
.page-size-select:focus {
|
||||
outline: none;
|
||||
border-color: #3b82f6;
|
||||
box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
|
||||
}
|
||||
|
||||
.sort-toggle {
|
||||
padding: 8px 12px;
|
||||
border: 1px solid #d1d5db;
|
||||
border-radius: 6px;
|
||||
background: white;
|
||||
cursor: pointer;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
.sort-toggle:hover {
|
||||
background: #f3f4f6;
|
||||
}
|
||||
|
||||
.sort-toggle.active {
|
||||
background: #eff6ff;
|
||||
border-color: #3b82f6;
|
||||
color: #3b82f6;
|
||||
}
|
||||
|
||||
.item-title a {
|
||||
color: #3b82f6;
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
.item-title a:hover {
|
||||
text-decoration: underline;
|
||||
}
|
||||
|
||||
.admin-item-actions {
|
||||
display: flex;
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
.btn-sm {
|
||||
padding: 4px 10px;
|
||||
font-size: 0.75rem;
|
||||
border-radius: 4px;
|
||||
}
|
||||
|
||||
/* Table Styles */
|
||||
table {
|
||||
width: 100%;
|
||||
border-collapse: collapse;
|
||||
font-size: 0.875rem;
|
||||
}
|
||||
|
||||
thead {
|
||||
background-color: #f9fafb;
|
||||
border-bottom: 2px solid #e5e7eb;
|
||||
}
|
||||
|
||||
th {
|
||||
padding: 12px 16px;
|
||||
text-align: left;
|
||||
}
|
||||
|
||||
tbody tr {
|
||||
border-bottom: 1px solid #e5e7eb;
|
||||
}
|
||||
|
||||
tbody tr:hover {
|
||||
background-color: #f9fafb;
|
||||
}
|
||||
|
||||
/* Pagination */
|
||||
.admin-pagination {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
margin-top: 16px;
|
||||
padding-bottom: 16px;
|
||||
}
|
||||
|
||||
.page-info {
|
||||
font-size: 0.875rem;
|
||||
color: #6b7280;
|
||||
}
|
||||
|
||||
.pagination-controls {
|
||||
display: flex;
|
||||
gap: 4px;
|
||||
}
|
||||
|
||||
.page-btn {
|
||||
padding: 6px 12px;
|
||||
border: 1px solid #d1d5db;
|
||||
background: white;
|
||||
color: #374151;
|
||||
border-radius: 6px;
|
||||
cursor: pointer;
|
||||
font-size: 0.875rem;
|
||||
}
|
||||
|
||||
.page-btn:hover:not(:disabled) {
|
||||
background: #f3f4f6;
|
||||
}
|
||||
|
||||
.page-btn.active {
|
||||
background: #3b82f6;
|
||||
color: white;
|
||||
border-color: #3b82f6;
|
||||
}
|
||||
|
||||
.page-btn:disabled {
|
||||
opacity: 0.5;
|
||||
cursor: not-allowed;
|
||||
}
|
||||
|
||||
/* Form Styles */
|
||||
.form-group {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
.form-label {
|
||||
font-weight: 500;
|
||||
margin-bottom: 8px;
|
||||
color: #374151;
|
||||
}
|
||||
|
||||
.form-actions {
|
||||
display: flex;
|
||||
gap: 12px;
|
||||
margin-top: 24px;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.mb-4 {
|
||||
margin-bottom: 16px;
|
||||
}
|
||||
|
||||
.btn-lg {
|
||||
padding: 10px 20px;
|
||||
font-size: 1rem;
|
||||
border-radius: 6px;
|
||||
cursor: pointer;
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
.btn-primary {
|
||||
background: #3b82f6;
|
||||
color: white;
|
||||
border: none;
|
||||
}
|
||||
|
||||
.btn-primary:hover:not(:disabled) {
|
||||
background: #2563eb;
|
||||
}
|
||||
|
||||
.btn-secondary {
|
||||
background: #f3f4f6;
|
||||
color: #374151;
|
||||
border: 1px solid #d1d5db;
|
||||
}
|
||||
|
||||
.btn-secondary:hover:not(:disabled) {
|
||||
background: #e5e7eb;
|
||||
}
|
||||
|
||||
.form-actions button:disabled {
|
||||
opacity: 0.6;
|
||||
cursor: not-allowed;
|
||||
}
|
||||
|
||||
/* Loading and Empty States */
|
||||
.admin-loading,
|
||||
.admin-empty-state {
|
||||
padding: 40px;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.admin-error-message {
|
||||
padding: 12px 16px;
|
||||
background-color: #fee2e2;
|
||||
color: #991b1b;
|
||||
border-radius: 8px;
|
||||
margin-bottom: 16px;
|
||||
}
|
||||
|
||||
/* Responsive */
|
||||
@media (max-width: 768px) {
|
||||
.sidebar:not(.open) {
|
||||
transform: translateX(-100%);
|
||||
}
|
||||
|
||||
.admin-filters-bar {
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
.admin-search-input {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
table {
|
||||
font-size: 0.75rem;
|
||||
}
|
||||
|
||||
th, td {
|
||||
padding: 8px;
|
||||
}
|
||||
}
|
||||
|
||||
/* Global Styles for Admin */
|
||||
.btn-danger {
|
||||
background: #ef4444;
|
||||
color: white;
|
||||
border: none;
|
||||
}
|
||||
|
||||
.btn-danger:hover:not(:disabled) {
|
||||
background: #dc2626;
|
||||
}
|
||||
|
||||
.btn-secondary {
|
||||
background: #f3f4f6;
|
||||
color: #374151;
|
||||
border: 1px solid #d1d5db;
|
||||
}
|
||||
@@ -0,0 +1,175 @@
|
||||
/* Authentication Page Styles */
|
||||
|
||||
.auth-container {
|
||||
min-height: 100vh;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
padding: 2rem 1rem;
|
||||
background-color: #1a1a2e;
|
||||
}
|
||||
|
||||
.auth-card {
|
||||
background-color: #2d2d44;
|
||||
border-radius: 0.75rem;
|
||||
box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
|
||||
width: 100%;
|
||||
max-width: 400px;
|
||||
padding: 2rem;
|
||||
}
|
||||
|
||||
.auth-header {
|
||||
text-align: center;
|
||||
margin-bottom: 2rem;
|
||||
}
|
||||
|
||||
.auth-header h1 {
|
||||
font-size: 1.75rem;
|
||||
font-weight: 600;
|
||||
color: #ffffff;
|
||||
margin-bottom: 0.5rem;
|
||||
}
|
||||
|
||||
.auth-header p {
|
||||
color: #a0a0b0;
|
||||
font-size: 0.875rem;
|
||||
}
|
||||
|
||||
.form-group {
|
||||
margin-bottom: 1.25rem;
|
||||
}
|
||||
|
||||
.form-group label {
|
||||
display: block;
|
||||
font-size: 0.875rem;
|
||||
font-weight: 500;
|
||||
color: #e0e0f0;
|
||||
margin-bottom: 0.5rem;
|
||||
}
|
||||
|
||||
.form-group input {
|
||||
width: 100%;
|
||||
padding: 0.75rem 1rem;
|
||||
font-size: 1rem;
|
||||
border-radius: 0.5rem;
|
||||
border: 1px solid #4a4a6a;
|
||||
background-color: #3d3d5c;
|
||||
color: #ffffff;
|
||||
transition: all 0.2s ease;
|
||||
}
|
||||
|
||||
.form-group input:focus {
|
||||
outline: none;
|
||||
border-color: #7c7ca8;
|
||||
background-color: #4a4a6a;
|
||||
box-shadow: 0 0 0 3px rgba(124, 124, 168, 0.2);
|
||||
}
|
||||
|
||||
.form-group input::placeholder {
|
||||
color: #7a7a9a;
|
||||
}
|
||||
|
||||
.error-message {
|
||||
background-color: rgba(239, 68, 68, 0.15);
|
||||
border: 1px solid #ef4444;
|
||||
border-radius: 0.5rem;
|
||||
padding: 0.75rem 1rem;
|
||||
margin-bottom: 1.25rem;
|
||||
color: #ef4444;
|
||||
font-size: 0.875rem;
|
||||
}
|
||||
|
||||
.success-message {
|
||||
background-color: rgba(34, 197, 94, 0.15);
|
||||
border: 1px solid #22c55e;
|
||||
border-radius: 0.5rem;
|
||||
padding: 0.75rem 1rem;
|
||||
margin-bottom: 1.25rem;
|
||||
color: #22c55e;
|
||||
font-size: 0.875rem;
|
||||
}
|
||||
|
||||
.submit-button {
|
||||
width: 100%;
|
||||
padding: 0.875rem 1.5rem;
|
||||
font-size: 1rem;
|
||||
font-weight: 600;
|
||||
border-radius: 0.5rem;
|
||||
border: none;
|
||||
background-color: #4a9eff;
|
||||
color: #ffffff;
|
||||
cursor: pointer;
|
||||
transition: all 0.2s ease;
|
||||
}
|
||||
|
||||
.submit-button:hover {
|
||||
background-color: #3d8ce6;
|
||||
}
|
||||
|
||||
.submit-button:disabled {
|
||||
opacity: 0.7;
|
||||
cursor: not-allowed;
|
||||
}
|
||||
|
||||
.submit-button.loading {
|
||||
background-color: #5a9aff;
|
||||
pointer-events: none;
|
||||
}
|
||||
|
||||
/* Split button for login/register */
|
||||
.auth-switch {
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
margin-top: 1.5rem;
|
||||
}
|
||||
|
||||
.auth-switch a {
|
||||
color: #7c7ca8;
|
||||
font-size: 0.875rem;
|
||||
text-decoration: none;
|
||||
transition: color 0.2s ease;
|
||||
}
|
||||
|
||||
.auth-switch a:hover {
|
||||
color: #a0a0b0;
|
||||
}
|
||||
|
||||
/* Responsive design */
|
||||
@media (max-width: 480px) {
|
||||
.auth-container {
|
||||
padding: 1rem 0.5rem;
|
||||
}
|
||||
|
||||
.auth-card {
|
||||
padding: 1.5rem;
|
||||
margin: 0 0.5rem;
|
||||
}
|
||||
|
||||
.auth-header h1 {
|
||||
font-size: 1.5rem;
|
||||
}
|
||||
}
|
||||
|
||||
/* Loading spinner */
|
||||
.spinner {
|
||||
display: inline-block;
|
||||
width: 20px;
|
||||
height: 20px;
|
||||
border: 2px solid #7c7ca8;
|
||||
border-top-color: #ffffff;
|
||||
border-radius: 50%;
|
||||
animation: spin 0.8s linear infinite;
|
||||
}
|
||||
|
||||
@keyframes spin {
|
||||
to {
|
||||
transform: rotate(360deg);
|
||||
}
|
||||
}
|
||||
|
||||
/* Password requirements help text */
|
||||
.password-help {
|
||||
font-size: 0.75rem;
|
||||
color: #7a7a9a;
|
||||
margin-top: 0.25rem;
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
import {
|
||||
ReactNode,
|
||||
createContext,
|
||||
useCallback,
|
||||
useContext,
|
||||
useEffect,
|
||||
useState,
|
||||
} from 'react';
|
||||
import { TOKEN_KEY, api } from './api/client';
|
||||
|
||||
interface AuthState {
|
||||
username: string | null;
|
||||
ready: boolean;
|
||||
isAdmin: boolean | null;
|
||||
login: (username: string, password: string) => Promise<void>;
|
||||
register: (username: string, password: string) => Promise<void>;
|
||||
logout: () => void;
|
||||
}
|
||||
|
||||
const AuthContext = createContext<AuthState | null>(null);
|
||||
|
||||
export function AuthProvider({ children }: { children: ReactNode }) {
|
||||
const [username, setUsername] = useState<string | null>(null);
|
||||
const [isAdmin, setIsAdmin] = useState<boolean | null>(null);
|
||||
const [ready, setReady] = useState(false);
|
||||
|
||||
// Restore session on load
|
||||
useEffect(() => {
|
||||
const stored = localStorage.getItem(TOKEN_KEY);
|
||||
if (!stored) {
|
||||
setReady(true);
|
||||
return;
|
||||
}
|
||||
|
||||
api
|
||||
.me(stored)
|
||||
.then((u) => {
|
||||
setUsername(u.username);
|
||||
setIsAdmin(u.is_admin || false);
|
||||
})
|
||||
.catch(() => localStorage.removeItem(TOKEN_KEY))
|
||||
.finally(() => setReady(true));
|
||||
}, []);
|
||||
|
||||
const login = useCallback(async (username: string, password: string) => {
|
||||
const res = await api.login(username, password);
|
||||
localStorage.setItem(TOKEN_KEY, res.token);
|
||||
setUsername(res.username);
|
||||
setIsAdmin(res.is_admin || false);
|
||||
}, []);
|
||||
|
||||
const register = useCallback(async (username: string, password: string) => {
|
||||
const res = await api.register(username, password);
|
||||
localStorage.setItem(TOKEN_KEY, res.token);
|
||||
setUsername(res.username);
|
||||
setIsAdmin(res.is_admin || false);
|
||||
}, []);
|
||||
|
||||
const logout = useCallback(() => {
|
||||
api.logout().catch(() => {
|
||||
// Best effort - token is discarded client-side either way
|
||||
});
|
||||
localStorage.removeItem(TOKEN_KEY);
|
||||
setUsername(null);
|
||||
setIsAdmin(null);
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<AuthContext.Provider value={{ username, isAdmin, ready, login, register, logout }}>
|
||||
{children}
|
||||
</AuthContext.Provider>
|
||||
);
|
||||
}
|
||||
|
||||
export function useAuth(): AuthState {
|
||||
const ctx = useContext(AuthContext);
|
||||
if (!ctx) throw new Error('useAuth must be used within AuthProvider');
|
||||
return ctx;
|
||||
}
|
||||
@@ -0,0 +1,305 @@
|
||||
import React from 'react';
|
||||
import { Link, useLocation, useNavigate } from 'react-router-dom';
|
||||
import {
|
||||
LayoutDashboard,
|
||||
Edit3,
|
||||
LogOut,
|
||||
Menu,
|
||||
Home,
|
||||
} from 'lucide-react';
|
||||
import { useAuth } from '../auth';
|
||||
|
||||
interface AdminLayoutProps {
|
||||
children: React.ReactNode;
|
||||
}
|
||||
|
||||
const sidebarItems = [
|
||||
{ path: '/admin', icon: LayoutDashboard, label: 'Dashboard' },
|
||||
{ path: '/admin/items/new', icon: Edit3, label: 'New Item' },
|
||||
];
|
||||
|
||||
export function AdminLayout({ children }: AdminLayoutProps) {
|
||||
const location = useLocation();
|
||||
const navigate = useNavigate();
|
||||
const { username, isAdmin, logout } = useAuth();
|
||||
const [sidebarOpen, setSidebarOpen] = React.useState(false);
|
||||
|
||||
const handleLogout = React.useCallback(() => {
|
||||
logout();
|
||||
navigate('/');
|
||||
}, [logout, navigate]);
|
||||
|
||||
if (!isAdmin) {
|
||||
return (
|
||||
<div className="admin-access-denied">
|
||||
<h2>Access Denied</h2>
|
||||
<p>You don't have admin privileges to access this page.</p>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
const sidebarClasses = `sidebar ${sidebarOpen ? 'open' : ''}`;
|
||||
const mainContentClasses = `${sidebarOpen ? 'pushed' : ''}`;
|
||||
|
||||
return (
|
||||
<div className="admin-layout">
|
||||
{/* Mobile overlay */}
|
||||
{sidebarOpen && (
|
||||
<div
|
||||
className="sidebar-overlay"
|
||||
onClick={() => setSidebarOpen(false)}
|
||||
/>
|
||||
)}
|
||||
|
||||
{/* Sidebar navigation */}
|
||||
<aside className={sidebarClasses}>
|
||||
<div className="sidebar-header">
|
||||
<h2>Admin Area</h2>
|
||||
</div>
|
||||
|
||||
<nav className="sidebar-nav">
|
||||
{sidebarItems.map((item) => (
|
||||
<Link
|
||||
key={item.path}
|
||||
to={item.path}
|
||||
onClick={() => setSidebarOpen(false)}
|
||||
className={`sidebar-link ${location.pathname === item.path ? 'active' : ''}`}
|
||||
>
|
||||
<item.icon size={20} />
|
||||
<span>{item.label}</span>
|
||||
</Link>
|
||||
))}
|
||||
|
||||
<div className="sidebar-divider">--</div>
|
||||
|
||||
<button
|
||||
onClick={handleLogout}
|
||||
className="sidebar-link logout-link"
|
||||
>
|
||||
<LogOut size={20} />
|
||||
<span>Sign Out</span>
|
||||
</button>
|
||||
</nav>
|
||||
|
||||
<div className="sidebar-footer">
|
||||
<div className="admin-user-info">
|
||||
<div className="admin-avatar">
|
||||
{username?.[0]?.toUpperCase() || 'U'}
|
||||
</div>
|
||||
<span>{username || 'Admin'}</span>
|
||||
</div>
|
||||
</div>
|
||||
</aside>
|
||||
|
||||
{/* Main content area */}
|
||||
<main className={mainContentClasses}>
|
||||
{/* Mobile header */}
|
||||
<header className="admin-header">
|
||||
<button
|
||||
className="sidebar-toggle"
|
||||
onClick={() => setSidebarOpen(true)}
|
||||
>
|
||||
<Menu size={20} />
|
||||
<span>Menu</span>
|
||||
</button>
|
||||
|
||||
<h1 className="admin-title">Dashboard</h1>
|
||||
|
||||
<Link to="/" className="home-link">
|
||||
<Home size={18} />
|
||||
<span>Back to Site</span>
|
||||
</Link>
|
||||
</header>
|
||||
|
||||
{/* Page content */}
|
||||
{children}
|
||||
</main>
|
||||
|
||||
{/* Global styles for admin layout */}
|
||||
<style>{`
|
||||
.admin-layout {
|
||||
display: flex;
|
||||
min-height: 100vh;
|
||||
background-color: #f8fafc;
|
||||
}
|
||||
|
||||
.sidebar {
|
||||
position: fixed;
|
||||
left: 0;
|
||||
top: 0;
|
||||
bottom: 0;
|
||||
width: 250px;
|
||||
background: linear-gradient(180deg, #1e293b 0%, #0f172a 100%);
|
||||
color: white;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
transition: transform 0.3s ease;
|
||||
z-index: 50;
|
||||
}
|
||||
|
||||
.sidebar.open {
|
||||
transform: translateX(0);
|
||||
}
|
||||
|
||||
.sidebar-overlay {
|
||||
position: fixed;
|
||||
left: 0;
|
||||
top: 0;
|
||||
right: 0;
|
||||
bottom: 0;
|
||||
background: rgba(0, 0, 0, 0.5);
|
||||
z-index: 40;
|
||||
}
|
||||
|
||||
.sidebar-header {
|
||||
padding: 24px 20px;
|
||||
border-bottom: 1px solid #334155;
|
||||
}
|
||||
|
||||
.sidebar-header h2 {
|
||||
font-size: 1.25rem;
|
||||
font-weight: 600;
|
||||
margin: 0;
|
||||
color: #e2e8f0;
|
||||
}
|
||||
|
||||
.sidebar-nav {
|
||||
flex: 1;
|
||||
padding: 16px 12px;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 4px;
|
||||
}
|
||||
|
||||
.sidebar-link {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 12px;
|
||||
padding: 12px 16px;
|
||||
border-radius: 8px;
|
||||
text-decoration: none;
|
||||
color: #e2e8f0;
|
||||
transition: background 0.15s ease, color 0.15s ease;
|
||||
}
|
||||
|
||||
.sidebar-link:hover {
|
||||
background: rgba(255, 255, 255, 0.1);
|
||||
color: white;
|
||||
}
|
||||
|
||||
.sidebar-link.active {
|
||||
background: #3b82f6;
|
||||
color: white;
|
||||
}
|
||||
|
||||
.sidebar-divider {
|
||||
height: 1px;
|
||||
background: rgba(255, 255, 255, 0.1);
|
||||
margin: 16px 0;
|
||||
}
|
||||
|
||||
.logout-link {
|
||||
color: #f87171 !important;
|
||||
}
|
||||
|
||||
.logout-link:hover {
|
||||
background: rgba(248, 113, 113, 0.1) !important;
|
||||
}
|
||||
|
||||
.sidebar-footer {
|
||||
padding: 16px;
|
||||
border-top: 1px solid #334155;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.admin-user-info {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
gap: 10px;
|
||||
}
|
||||
|
||||
.admin-avatar {
|
||||
width: 40px;
|
||||
height: 40px;
|
||||
border-radius: 50%;
|
||||
background: #3b82f6;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.admin-header {
|
||||
padding: 16px 24px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 16px;
|
||||
background: white;
|
||||
border-bottom: 1px solid #e5e7eb;
|
||||
}
|
||||
|
||||
.sidebar-toggle {
|
||||
padding: 8px 12px;
|
||||
border-radius: 6px;
|
||||
background: #f3f4f6;
|
||||
border: none;
|
||||
cursor: pointer;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
color: #374151;
|
||||
}
|
||||
|
||||
.admin-title {
|
||||
flex: 1;
|
||||
margin: 0;
|
||||
font-size: 1.5rem;
|
||||
color: #1f2937;
|
||||
}
|
||||
|
||||
.home-link {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
padding: 8px 16px;
|
||||
background: #e5e7eb;
|
||||
color: #374151;
|
||||
text-decoration: none;
|
||||
border-radius: 6px;
|
||||
font-size: 0.875rem;
|
||||
}
|
||||
|
||||
.home-link:hover {
|
||||
background: #d1d5db;
|
||||
}
|
||||
|
||||
.admin-access-denied {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
min-height: 40vh;
|
||||
text-align: center;
|
||||
padding: 24px;
|
||||
}
|
||||
|
||||
.admin-access-denied h2 {
|
||||
color: #dc2626;
|
||||
font-size: 1.5rem;
|
||||
margin-bottom: 12px;
|
||||
}
|
||||
|
||||
.admin-access-denied p {
|
||||
color: #6b7280;
|
||||
}
|
||||
|
||||
@media (max-width: 768px) {
|
||||
.sidebar:not(.open) {
|
||||
transform: translateX(-100%);
|
||||
}
|
||||
}
|
||||
`}</style>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
import { AlertCircle } from 'lucide-react';
|
||||
import React from 'react';
|
||||
|
||||
interface DeleteConfirmationProps {
|
||||
item: any | null;
|
||||
onConfirm: () => Promise<void>;
|
||||
onCancel: () => void;
|
||||
}
|
||||
|
||||
export function DeleteConfirmation({ item, onConfirm, onCancel }: DeleteConfirmationProps) {
|
||||
const handleConfirm = React.useCallback(async () => {
|
||||
await onConfirm();
|
||||
// Auto-close after confirmation by calling onCancel to dismiss overlay
|
||||
}, [onConfirm]);
|
||||
|
||||
return (
|
||||
<div className="delete-modal-overlay" onClick={onCancel}>
|
||||
<div className="delete-modal-content" onClick={(e) => e.stopPropagation()}>
|
||||
<div className="warning-icon">
|
||||
<AlertCircle size={48} color="#dc2626" />
|
||||
</div>
|
||||
<h3>Are you sure you want to delete "{item?.title || 'this item'}"?</h3>
|
||||
<p>This action cannot be undone and will permanently remove the content from the system.</p>
|
||||
|
||||
<div className="modal-actions">
|
||||
<button onClick={onCancel} className="btn-secondary">
|
||||
Cancel
|
||||
</button>
|
||||
<button
|
||||
onClick={handleConfirm}
|
||||
className="btn-danger"
|
||||
>
|
||||
Yes, Delete
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,181 @@
|
||||
import React, { useEffect, useRef } from 'react';
|
||||
import { Bold, Italic, Underline, Heading1, Type, List, ListOrdered, Link2 } from 'lucide-react';
|
||||
|
||||
interface LexicalEditorProps {
|
||||
content: string;
|
||||
onChange: (html: string) => void;
|
||||
placeholder?: string;
|
||||
readOnly?: boolean;
|
||||
className?: string;
|
||||
}
|
||||
|
||||
export function LexicalEditor({
|
||||
content,
|
||||
onChange,
|
||||
placeholder = 'Write your content here...',
|
||||
readOnly = false,
|
||||
className = '',
|
||||
}: LexicalEditorProps) {
|
||||
const textareaRef = useRef<HTMLTextAreaElement>(null);
|
||||
|
||||
// Sync textarea value with content prop when it changes from outside
|
||||
useEffect(() => {
|
||||
if (textareaRef.current && content !== '') {
|
||||
textareaRef.current.value = content;
|
||||
}
|
||||
}, [content]);
|
||||
|
||||
const handleTextChange = React.useCallback((e: React.ChangeEvent<HTMLTextAreaElement>) => {
|
||||
onChange(e.target.value);
|
||||
}, [onChange]);
|
||||
|
||||
return (
|
||||
<div className={`lexical-editor-wrapper ${className}`}>
|
||||
{/* Toolbar for basic formatting */}
|
||||
<div className="lexical-toolbar">
|
||||
<ToolbarButton icon={<Bold size={16} />} label="Bold" onClick={() => {}} disabled={readOnly} />
|
||||
<ToolbarButton icon={<Italic size={16} />} label="Italic" onClick={() => {}} disabled={readOnly} />
|
||||
<ToolbarButton icon={<Underline size={16} />} label="Underline" onClick={() => {}} disabled={readOnly} />
|
||||
<div className="toolbar-separator" />
|
||||
<ToolbarButton icon={<Heading1 size={14} />} label="H1" onClick={() => {}} disabled={readOnly} />
|
||||
<ToolbarButton icon={<Type size={16} />} label="Paragraph" onClick={() => {}} disabled={readOnly} />
|
||||
<div className="toolbar-separator" />
|
||||
<ToolbarButton icon={<List size={14} />} label="Bulleted List" onClick={() => {}} disabled={readOnly} />
|
||||
<ToolbarButton icon={<ListOrdered size={14} />} label="Numbered List" onClick={() => {}} disabled={readOnly} />
|
||||
<div className="toolbar-separator" />
|
||||
<ToolbarButton icon={<Link2 size={16} />} label="Link" onClick={() => {}} disabled={readOnly} />
|
||||
</div>
|
||||
|
||||
<div className="lexical-editor-content">
|
||||
<textarea
|
||||
ref={textareaRef}
|
||||
className="lexical-editor"
|
||||
placeholder={placeholder}
|
||||
value={content}
|
||||
onChange={handleTextChange}
|
||||
readOnly={readOnly}
|
||||
style={{ minHeight: '200px' }}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function ToolbarButton({ icon, label, onClick, disabled }: {
|
||||
icon: React.ReactNode;
|
||||
label: string;
|
||||
onClick?: () => void;
|
||||
disabled?: boolean
|
||||
}) {
|
||||
return (
|
||||
<button
|
||||
type="button"
|
||||
className="lexical-toolbar-btn"
|
||||
onClick={onClick}
|
||||
disabled={disabled}
|
||||
title={label}
|
||||
>
|
||||
{icon}
|
||||
</button>
|
||||
);
|
||||
}
|
||||
|
||||
const editorStyles = `
|
||||
.lexical-editor-wrapper {
|
||||
border: 1px solid #e5e7eb;
|
||||
border-radius: 0.5rem;
|
||||
overflow: hidden;
|
||||
background: #ffffff;
|
||||
}
|
||||
|
||||
.lexical-toolbar {
|
||||
display: flex;
|
||||
gap: 4px;
|
||||
padding: 8px;
|
||||
border-bottom: 1px solid #e5e7eb;
|
||||
background: #f9fafb;
|
||||
}
|
||||
|
||||
.lexical-toolbar-btn {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
width: 32px;
|
||||
height: 32px;
|
||||
border: none;
|
||||
border-radius: 4px;
|
||||
background: transparent;
|
||||
color: #6b7280;
|
||||
cursor: pointer;
|
||||
transition: all 0.15s ease;
|
||||
}
|
||||
|
||||
.lexical-toolbar-btn:hover:not(:disabled) {
|
||||
background: #e5e7eb;
|
||||
color: #374151;
|
||||
}
|
||||
|
||||
.lexical-toolbar-btn:disabled {
|
||||
opacity: 0.5;
|
||||
cursor: not-allowed;
|
||||
}
|
||||
|
||||
.lexical-toolbar-separator {
|
||||
width: 1px;
|
||||
height: 24px;
|
||||
background: #e5e7eb;
|
||||
margin: 0 4px;
|
||||
}
|
||||
|
||||
.lexical-editor-content {
|
||||
min-height: 200px;
|
||||
}
|
||||
|
||||
.lexical-editor {
|
||||
min-height: 200px;
|
||||
padding: 16px;
|
||||
border: none;
|
||||
outline: none;
|
||||
font-size: 1rem;
|
||||
line-height: 1.6;
|
||||
color: #374151;
|
||||
background: transparent;
|
||||
resize: vertical;
|
||||
font-family: inherit;
|
||||
}
|
||||
|
||||
.lexical-editor::placeholder {
|
||||
color: #9ca3af;
|
||||
}
|
||||
|
||||
@media (max-width: 768px) {
|
||||
.lexical-toolbar {
|
||||
flex-wrap: nowrap;
|
||||
overflow-x: auto;
|
||||
padding: 6px;
|
||||
}
|
||||
|
||||
.lexical-toolbar-btn {
|
||||
min-width: 28px;
|
||||
}
|
||||
}
|
||||
`;
|
||||
|
||||
// Inject styles
|
||||
let stylesInjected = false;
|
||||
export function injectEditorStyles() {
|
||||
if (stylesInjected) return;
|
||||
|
||||
const styleId = 'lexical-editor-styles';
|
||||
if (document.getElementById(styleId)) {
|
||||
return;
|
||||
}
|
||||
|
||||
const styleEl = document.createElement('style');
|
||||
styleEl.id = styleId;
|
||||
styleEl.textContent = editorStyles;
|
||||
document.head.appendChild(styleEl);
|
||||
stylesInjected = true;
|
||||
}
|
||||
|
||||
export default LexicalEditor;
|
||||
@@ -1,14 +1,22 @@
|
||||
import { Home, FileText, Settings } from 'lucide-react';
|
||||
import { Link } from 'react-router-dom';
|
||||
import { Home, FileText, Settings, LogOut } from 'lucide-react';
|
||||
import { Link, useNavigate } from 'react-router-dom';
|
||||
import { useAuth } from '../../auth';
|
||||
|
||||
interface HeaderProps {}
|
||||
|
||||
export function Header({}: HeaderProps) {
|
||||
const { username, logout } = useAuth();
|
||||
const navigate = useNavigate();
|
||||
|
||||
const handleLogout = () => {
|
||||
logout();
|
||||
navigate('/login');
|
||||
};
|
||||
|
||||
return (
|
||||
<header className="nav" data-testid="header">
|
||||
<h1>newzy</h1>
|
||||
<nav>
|
||||
{/* Navigation uses react-router-dom Link, not anchor tags */}
|
||||
<Link to="/" data-testid="home-link">
|
||||
<Home data-testid="home-icon" className="w-5 h-5" />
|
||||
</Link>
|
||||
@@ -18,6 +26,21 @@ export function Header({}: HeaderProps) {
|
||||
<Link to="/categories" data-testid="categories-link">
|
||||
<Settings data-testid="categories-icon" className="w-5 h-5" />
|
||||
</Link>
|
||||
|
||||
{/* Authenticated user actions */}
|
||||
{username && (
|
||||
<>
|
||||
<span className="ml-4 text-sm opacity-80">@{username}</span>
|
||||
<button
|
||||
onClick={handleLogout}
|
||||
className="ml-2 flex items-center gap-1 hover:bg-gray-700 rounded px-2 py-1 text-sm"
|
||||
data-testid="logout-button"
|
||||
>
|
||||
<LogOut className="w-4 h-4" />
|
||||
Sign out
|
||||
</button>
|
||||
</>
|
||||
)}
|
||||
</nav>
|
||||
</header>
|
||||
);
|
||||
|
||||
@@ -1,9 +1,13 @@
|
||||
import React from 'react';
|
||||
import ReactDOM from 'react-dom/client';
|
||||
import { AuthProvider } from './auth';
|
||||
import App from './App';
|
||||
import './assets/styles/admin.css';
|
||||
|
||||
ReactDOM.createRoot(document.getElementById('root')!).render(
|
||||
<React.StrictMode>
|
||||
<App />
|
||||
<AuthProvider>
|
||||
<App />
|
||||
</AuthProvider>
|
||||
</React.StrictMode>,
|
||||
);
|
||||
@@ -0,0 +1,137 @@
|
||||
import React, { useState } from 'react';
|
||||
import { Search, ArrowUpDown } from 'lucide-react';
|
||||
import { AdminLayout } from '../components/AdminLayout';
|
||||
|
||||
export function AdminDashboard() {
|
||||
const [loading, setLoading] = useState(false);
|
||||
|
||||
// Filter and sort state
|
||||
const [searchQuery, setSearchQuery] = useState('');
|
||||
const [sortField, setSortField] = useState<'title' | 'created_at'>('created_at');
|
||||
|
||||
React.useEffect(() => {
|
||||
setLoading(true);
|
||||
setTimeout(() => setLoading(false), 1000);
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<AdminLayout>
|
||||
{/* Search and filter bar */}
|
||||
<div className="admin-filters-bar" style={{
|
||||
display: 'flex',
|
||||
gap: '8px',
|
||||
marginBottom: '16px',
|
||||
flexWrap: 'wrap'
|
||||
}}>
|
||||
<div style={{ position: 'relative', flex: 1, minWidth: 200 }}>
|
||||
<Search size={18} className="filter-icon" />
|
||||
<input
|
||||
type="text"
|
||||
placeholder="Search by title or URL..."
|
||||
value={searchQuery}
|
||||
onChange={(e) => setSearchQuery(e.target.value)}
|
||||
className="admin-search-input"
|
||||
style={{ paddingLeft: '36px' }}
|
||||
/>
|
||||
</div>
|
||||
|
||||
<select
|
||||
value={sortField}
|
||||
onChange={(e) => setSortField(e.target.value as 'title' | 'created_at')}
|
||||
className="admin-sort-select"
|
||||
>
|
||||
<option value="created_at">Newest First</option>
|
||||
<option value="title">Title (A-Z)</option>
|
||||
</select>
|
||||
|
||||
<button
|
||||
onClick={() => setSortField('created_at')}
|
||||
className={`sort-toggle ${sortField === 'created_at' ? 'active' : ''}`}
|
||||
>
|
||||
<ArrowUpDown size={18} />
|
||||
</button>
|
||||
</div>
|
||||
|
||||
{/* Items list */}
|
||||
<div style={{ backgroundColor: 'white', borderRadius: '8px', border: '1px solid #e5e7eb', overflow: 'hidden' }}>
|
||||
{loading ? (
|
||||
<div style={{ padding: '40px', textAlign: 'center' }}>
|
||||
<p>Loading items...</p>
|
||||
</div>
|
||||
) : (
|
||||
<div style={{ padding: '32px', textAlign: 'center' }}>
|
||||
<p style={{ color: '#6b7280' }}>Admin dashboard will be populated with items when API is ready.</p>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{/* Global styles */}
|
||||
<style>{`
|
||||
.admin-filters-bar input[type='text'] {
|
||||
width: 100%;
|
||||
padding: 10px 12px 10px 36px;
|
||||
border: 1px solid #d1d5db;
|
||||
border-radius: 6px;
|
||||
font-size: 0.875rem;
|
||||
}
|
||||
|
||||
.filter-icon {
|
||||
position: absolute;
|
||||
left: 12px;
|
||||
top: 50%;
|
||||
transform: translateY(-50%);
|
||||
color: #9ca3af;
|
||||
}
|
||||
|
||||
.admin-search-input {
|
||||
width: 100%;
|
||||
padding: 8px 12px;
|
||||
border: 1px solid #d1d5db;
|
||||
border-radius: 6px;
|
||||
font-size: 0.875rem;
|
||||
}
|
||||
|
||||
.admin-search-input:focus {
|
||||
outline: none;
|
||||
border-color: #3b82f6;
|
||||
box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
|
||||
}
|
||||
|
||||
.admin-sort-select, .page-size-select {
|
||||
padding: 8px 12px;
|
||||
border: 1px solid #d1d5db;
|
||||
border-radius: 6px;
|
||||
font-size: 0.875rem;
|
||||
background: white;
|
||||
}
|
||||
|
||||
.admin-sort-select:focus, .page-size-select:focus {
|
||||
outline: none;
|
||||
border-color: #3b82f6;
|
||||
box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
|
||||
}
|
||||
|
||||
.sort-toggle {
|
||||
padding: 8px 12px;
|
||||
border: 1px solid #d1d5db;
|
||||
border-radius: 6px;
|
||||
background: white;
|
||||
cursor: pointer;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
.sort-toggle:hover {
|
||||
background: #f3f4f6;
|
||||
}
|
||||
|
||||
.sort-toggle.active {
|
||||
background: #eff6ff;
|
||||
border-color: #3b82f6;
|
||||
color: #3b82f6;
|
||||
}
|
||||
`}</style>
|
||||
</AdminLayout>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,313 @@
|
||||
import React, { useState, useCallback } from 'react';
|
||||
import { useParams, useNavigate } from 'react-router-dom';
|
||||
import { ArrowLeft, Save } from 'lucide-react';
|
||||
import { AdminLayout } from '../components/AdminLayout';
|
||||
import { adminApi } from '../api/client';
|
||||
import { LexicalEditor, injectEditorStyles } from '../components/LexicalEditor';
|
||||
|
||||
interface ItemForm {
|
||||
title: string;
|
||||
url: string;
|
||||
content: string;
|
||||
points: number;
|
||||
}
|
||||
|
||||
export function EditItemPage() {
|
||||
injectEditorStyles();
|
||||
|
||||
const { id } = useParams<{ id?: string }>();
|
||||
const navigate = useNavigate();
|
||||
|
||||
const [loading, setLoading] = useState(false);
|
||||
const [saving, setSaving] = useState(false);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
const [success, setSuccess] = useState(false);
|
||||
|
||||
const [formData, setFormData] = useState<ItemForm>({
|
||||
title: '',
|
||||
url: '',
|
||||
content: '',
|
||||
points: 0,
|
||||
});
|
||||
|
||||
const fetchItem = useCallback(async () => {
|
||||
if (!id) return;
|
||||
|
||||
try {
|
||||
setLoading(true);
|
||||
setError(null);
|
||||
const data = await adminApi.getItem(parseInt(id));
|
||||
setFormData({
|
||||
title: data.title || '',
|
||||
url: data.url || '',
|
||||
content: data.content || '',
|
||||
points: data.points || 0,
|
||||
});
|
||||
} catch (err) {
|
||||
setError('Failed to load item. Please try again.');
|
||||
console.error('Load error:', err);
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
}, [id]);
|
||||
|
||||
const handleSave = async () => {
|
||||
setSaving(true);
|
||||
setError(null);
|
||||
|
||||
try {
|
||||
let data: any;
|
||||
|
||||
if (id) {
|
||||
// Update existing item
|
||||
data = await adminApi.updateItem(parseInt(id), formData);
|
||||
} else {
|
||||
// Create new item
|
||||
data = await adminApi.createItem(formData);
|
||||
}
|
||||
|
||||
setSuccess(true);
|
||||
setFormData({ ...formData, content: data.content || '', title: data.title || '' });
|
||||
} catch (err) {
|
||||
setError('Failed to save item. Please try again.');
|
||||
console.error('Save error:', err);
|
||||
} finally {
|
||||
setSaving(false);
|
||||
}
|
||||
};
|
||||
|
||||
const handleCancel = () => {
|
||||
navigate('/admin');
|
||||
};
|
||||
|
||||
React.useEffect(() => {
|
||||
fetchItem();
|
||||
}, [fetchItem]);
|
||||
|
||||
if (loading) {
|
||||
return (
|
||||
<AdminLayout>
|
||||
<div className="admin-loading" style={{ padding: '40px', textAlign: 'center' }}>
|
||||
<p>Loading item...</p>
|
||||
</div>
|
||||
</AdminLayout>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<AdminLayout>
|
||||
<div className="edit-item-container" style={{
|
||||
maxWidth: '900px',
|
||||
margin: '0 auto',
|
||||
padding: '24px'
|
||||
}}>
|
||||
{/* Back button */}
|
||||
<button onClick={handleCancel} className="btn-secondary btn-sm mb-4">
|
||||
<ArrowLeft size={16} /> Back to Dashboard
|
||||
</button>
|
||||
|
||||
{/* Error message */}
|
||||
{error && (
|
||||
<div style={{
|
||||
padding: '12px 16px',
|
||||
backgroundColor: '#fee2e2',
|
||||
color: '#991b1b',
|
||||
borderRadius: '8px',
|
||||
marginBottom: '16px'
|
||||
}}>
|
||||
{error}
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* Success message */}
|
||||
{success && (
|
||||
<div style={{
|
||||
padding: '12px 16px',
|
||||
backgroundColor: '#d1fae5',
|
||||
color: '#065f46',
|
||||
borderRadius: '8px',
|
||||
marginBottom: '16px'
|
||||
}}>
|
||||
{id ? 'Item updated successfully!' : 'Item created successfully!'}
|
||||
</div>
|
||||
)}
|
||||
|
||||
<form onSubmit={(e) => { e.preventDefault(); handleSave(); }}>
|
||||
{/* Title field */}
|
||||
<div className="form-group mb-4">
|
||||
<label htmlFor="title" className="form-label">
|
||||
Title <span style={{ color: '#ef4444' }}>*</span>
|
||||
</label>
|
||||
<input
|
||||
id="title"
|
||||
type="text"
|
||||
value={formData.title}
|
||||
onChange={(e) => setFormData({ ...formData, title: e.target.value })}
|
||||
placeholder="Enter item title..."
|
||||
maxLength={300}
|
||||
required
|
||||
style={{
|
||||
width: '100%',
|
||||
padding: '10px 12px',
|
||||
border: '1px solid #d1d5db',
|
||||
borderRadius: '6px',
|
||||
fontSize: '1rem'
|
||||
}}
|
||||
/>
|
||||
{formData.title && (
|
||||
<span style={{ color: '#9ca3af', fontSize: '0.75rem', marginTop: '4px' }}>
|
||||
({formData.title.length}/300 chars)
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{/* URL field */}
|
||||
<div className="form-group mb-4">
|
||||
<label htmlFor="url" className="form-label">
|
||||
URL (optional)
|
||||
</label>
|
||||
<input
|
||||
id="url"
|
||||
type="text"
|
||||
value={formData.url}
|
||||
onChange={(e) => setFormData({ ...formData, url: e.target.value })}
|
||||
placeholder="https://example.com/article"
|
||||
maxLength={500}
|
||||
style={{
|
||||
width: '100%',
|
||||
padding: '10px 12px',
|
||||
border: '1px solid #d1d5db',
|
||||
borderRadius: '6px',
|
||||
fontSize: '1rem'
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
|
||||
{/* Content field with Lexical Editor */}
|
||||
<div className="form-group mb-4">
|
||||
<label htmlFor="content" className="form-label">
|
||||
Content
|
||||
</label>
|
||||
<LexicalEditor
|
||||
content={formData.content}
|
||||
onChange={(newContent) => setFormData({ ...formData, content: newContent })}
|
||||
placeholder="Write your content here using the rich text editor..."
|
||||
/>
|
||||
</div>
|
||||
|
||||
{/* Points field */}
|
||||
<div className="form-group mb-4">
|
||||
<label htmlFor="points" className="form-label">
|
||||
Points (0 - 1,000,000)
|
||||
</label>
|
||||
<input
|
||||
id="points"
|
||||
type="number"
|
||||
value={formData.points}
|
||||
onChange={(e) => setFormData({ ...formData, points: Number(e.target.value) })}
|
||||
min={0}
|
||||
max={1000000}
|
||||
style={{
|
||||
width: '100%',
|
||||
padding: '10px 12px',
|
||||
border: '1px solid #d1d5db',
|
||||
borderRadius: '6px',
|
||||
fontSize: '1rem'
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
|
||||
{/* Action buttons */}
|
||||
<div className="form-actions" style={{
|
||||
display: 'flex',
|
||||
gap: '12px',
|
||||
marginTop: '24px',
|
||||
alignItems: 'center'
|
||||
}}>
|
||||
<button
|
||||
type="submit"
|
||||
disabled={saving}
|
||||
className="btn-primary btn-lg"
|
||||
>
|
||||
{saving ? (
|
||||
<>Saving...</>
|
||||
) : (
|
||||
<>
|
||||
<Save size={18} /> Save Item
|
||||
</>
|
||||
)}
|
||||
</button>
|
||||
|
||||
<button
|
||||
type="button"
|
||||
onClick={handleCancel}
|
||||
className="btn-secondary btn-lg"
|
||||
>
|
||||
Cancel
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
{/* Global styles */}
|
||||
<style>{`
|
||||
.form-group {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
.form-label {
|
||||
font-weight: 500;
|
||||
margin-bottom: 8px;
|
||||
color: #374151;
|
||||
}
|
||||
|
||||
.form-actions {
|
||||
display: flex;
|
||||
gap: 12px;
|
||||
margin-top: 24px;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.mb-4 {
|
||||
margin-bottom: 16px;
|
||||
}
|
||||
|
||||
.btn-lg {
|
||||
padding: 10px 20px;
|
||||
font-size: 1rem;
|
||||
border-radius: 6px;
|
||||
cursor: pointer;
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
.btn-primary {
|
||||
background: #3b82f6;
|
||||
color: white;
|
||||
border: none;
|
||||
}
|
||||
|
||||
.btn-primary:hover:not(:disabled) {
|
||||
background: #2563eb;
|
||||
}
|
||||
|
||||
.btn-secondary {
|
||||
background: #f3f4f6;
|
||||
color: #374151;
|
||||
border: 1px solid #d1d5db;
|
||||
}
|
||||
|
||||
.btn-secondary:hover:not(:disabled) {
|
||||
background: #e5e7eb;
|
||||
}
|
||||
|
||||
.form-actions button:disabled {
|
||||
opacity: 0.6;
|
||||
cursor: not-allowed;
|
||||
}
|
||||
`}</style>
|
||||
</div>
|
||||
</AdminLayout>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
import { useState } from 'react';
|
||||
import { useNavigate } from 'react-router-dom';
|
||||
import { api } from '../api/client';
|
||||
|
||||
export default function Login() {
|
||||
const [username, setUsername] = useState('');
|
||||
const [password, setPassword] = useState('');
|
||||
const [error, setError] = useState('');
|
||||
const [loading, setLoading] = useState(false);
|
||||
|
||||
const navigate = useNavigate();
|
||||
|
||||
const handleSubmit = async (e: React.FormEvent) => {
|
||||
e.preventDefault();
|
||||
setError('');
|
||||
setLoading(true);
|
||||
|
||||
try {
|
||||
await api.login(username, password);
|
||||
// Auth context will update state and handle navigation to home
|
||||
navigate('/');
|
||||
} catch (err) {
|
||||
const msg = err instanceof Error ? err.message : 'Login failed. Please check your credentials.';
|
||||
setError(msg);
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="auth-container">
|
||||
<div className="auth-card">
|
||||
<div className="auth-header">
|
||||
<h1>Welcome back</h1>
|
||||
<p>Please sign in to continue</p>
|
||||
</div>
|
||||
|
||||
{error && <div className="error-message">{error}</div>}
|
||||
|
||||
<form onSubmit={handleSubmit}>
|
||||
<div className="form-group">
|
||||
<label htmlFor="login-username">Username</label>
|
||||
<input
|
||||
id="login-username"
|
||||
type="text"
|
||||
value={username}
|
||||
onChange={(e) => setUsername(e.target.value)}
|
||||
placeholder="Enter your username"
|
||||
required
|
||||
minLength={3}
|
||||
maxLength={60}
|
||||
disabled={loading}
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div className="form-group">
|
||||
<label htmlFor="login-password">Password</label>
|
||||
<input
|
||||
id="login-password"
|
||||
type="password"
|
||||
value={password}
|
||||
onChange={(e) => setPassword(e.target.value)}
|
||||
placeholder="Enter your password"
|
||||
required
|
||||
minLength={8}
|
||||
maxLength={128}
|
||||
disabled={loading}
|
||||
/>
|
||||
</div>
|
||||
|
||||
<button type="submit" className="submit-button" disabled={loading}>
|
||||
{loading ? <><span className="spinner"></span> Signing in...</> : 'Sign in'}
|
||||
</button>
|
||||
</form>
|
||||
|
||||
<div className="auth-switch">
|
||||
<a href="/register">Don't have an account? Register</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,119 @@
|
||||
import { useState } from 'react';
|
||||
import { useNavigate } from 'react-router-dom';
|
||||
import { api } from '../api/client';
|
||||
|
||||
export default function Register() {
|
||||
const [username, setUsername] = useState('');
|
||||
const [password, setPassword] = useState('');
|
||||
const [confirmPassword, setConfirmPassword] = useState('');
|
||||
const [error, setError] = useState('');
|
||||
const [loading, setLoading] = useState(false);
|
||||
|
||||
const navigate = useNavigate();
|
||||
|
||||
const validateUsername = (val: string) => /^[a-zA-Z0-9_]{3,20}$/.test(val);
|
||||
const isPasswordStrong = () => password.length >= 8;
|
||||
|
||||
const handleSubmit = async (e: React.FormEvent) => {
|
||||
e.preventDefault();
|
||||
setError('');
|
||||
|
||||
// Client-side validation
|
||||
if (!validateUsername(username)) {
|
||||
setError('Username must be 3-20 alphanumeric characters or underscores');
|
||||
return;
|
||||
}
|
||||
if (password.length < 8) {
|
||||
setError('Password must be at least 8 characters long');
|
||||
return;
|
||||
}
|
||||
if (password !== confirmPassword) {
|
||||
setError('Passwords do not match');
|
||||
return;
|
||||
}
|
||||
|
||||
setLoading(true);
|
||||
|
||||
try {
|
||||
await api.register(username, password);
|
||||
// Auth context will update state and handle navigation to home
|
||||
navigate('/');
|
||||
} catch (err) {
|
||||
const msg = err instanceof Error ? err.message : 'Registration failed';
|
||||
setError(msg);
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="auth-container">
|
||||
<div className="auth-card">
|
||||
<div className="auth-header">
|
||||
<h1>Create an account</h1>
|
||||
<p>Join us and start reading news</p>
|
||||
</div>
|
||||
|
||||
{error && <div className="error-message">{error}</div>}
|
||||
|
||||
<form onSubmit={handleSubmit}>
|
||||
<div className="form-group">
|
||||
<label htmlFor="reg-username">Username</label>
|
||||
<input
|
||||
id="reg-username"
|
||||
type="text"
|
||||
value={username}
|
||||
onChange={(e) => setUsername(e.target.value)}
|
||||
placeholder="Choose a username"
|
||||
required
|
||||
minLength={3}
|
||||
maxLength={60}
|
||||
disabled={loading}
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div className="form-group">
|
||||
<label htmlFor="reg-password">Password</label>
|
||||
<input
|
||||
id="reg-password"
|
||||
type="password"
|
||||
value={password}
|
||||
onChange={(e) => setPassword(e.target.value)}
|
||||
placeholder="Create a password"
|
||||
required
|
||||
minLength={8}
|
||||
maxLength={128}
|
||||
disabled={loading}
|
||||
/>
|
||||
{!isPasswordStrong() && (
|
||||
<p className="password-help">Must be at least 8 characters</p>
|
||||
)}
|
||||
</div>
|
||||
|
||||
<div className="form-group">
|
||||
<label htmlFor="reg-confirm">Confirm Password</label>
|
||||
<input
|
||||
id="reg-confirm"
|
||||
type="password"
|
||||
value={confirmPassword}
|
||||
onChange={(e) => setConfirmPassword(e.target.value)}
|
||||
placeholder="Confirm your password"
|
||||
required
|
||||
minLength={8}
|
||||
maxLength={128}
|
||||
disabled={loading}
|
||||
/>
|
||||
</div>
|
||||
|
||||
<button type="submit" className="submit-button" disabled={loading}>
|
||||
{loading ? <><span className="spinner"></span> Creating account...</> : 'Create account'}
|
||||
</button>
|
||||
</form>
|
||||
|
||||
<div className="auth-switch">
|
||||
<a href="/login">Already have an account? Sign in</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
import { useEffect } from 'react';
|
||||
import { useNavigate } from 'react-router-dom';
|
||||
import { logout } from '../api/client';
|
||||
|
||||
export default function SignOut() {
|
||||
const navigate = useNavigate();
|
||||
|
||||
// Clear token on mount and redirect to login
|
||||
useEffect(() => {
|
||||
async function handleLogout() {
|
||||
try {
|
||||
await logout();
|
||||
} catch (e) {
|
||||
// Best effort - ignore errors
|
||||
}
|
||||
navigate('/login', { replace: true });
|
||||
}
|
||||
|
||||
handleLogout();
|
||||
}, [navigate]);
|
||||
|
||||
return null;
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
// Admin article types
|
||||
export interface AdminItem {
|
||||
id: number;
|
||||
title: string;
|
||||
url: string;
|
||||
content: string;
|
||||
points: number;
|
||||
author_id: number;
|
||||
created_at: Date | string;
|
||||
}
|
||||
|
||||
export interface PaginatedResponse<T> {
|
||||
items: T[];
|
||||
total: number;
|
||||
page: number;
|
||||
page_size: number;
|
||||
total_pages: number;
|
||||
}
|
||||
|
||||
export interface AdminListItem extends AdminItem {
|
||||
// Additional fields if needed
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
/**
|
||||
* Authentication-related types for Newzy application.
|
||||
*/
|
||||
|
||||
export interface TokenResponse {
|
||||
token: string;
|
||||
username: string;
|
||||
}
|
||||
|
||||
export interface MeResponse {
|
||||
username: string;
|
||||
}
|
||||
@@ -1,3 +1,5 @@
|
||||
import type { TokenResponse, MeResponse } from './auth';
|
||||
|
||||
export interface Article {
|
||||
id: number;
|
||||
title: string;
|
||||
@@ -30,3 +32,6 @@ export interface ApiResponse<T> {
|
||||
error?: string;
|
||||
message?: string;
|
||||
}
|
||||
|
||||
// Export auth types
|
||||
export type { TokenResponse, MeResponse };
|
||||
Reference in new issue
Block a user