From b81eebf6c3b25cf1b2301a4d4996fdf94aee3139 Mon Sep 17 00:00:00 2001 From: Philipp Traber Date: Wed, 16 Oct 2024 21:42:08 +0200 Subject: [PATCH] add functionality to pin page && refactoring --- package-lock.json | 162 ++++++++++----------- package.json | 3 +- prisma/schema.prisma | 58 +++++--- src/actions/block_actions.ts | 6 +- src/actions/page_actions.ts | 39 +++++ src/app/[shortcode]/page.tsx | 19 +-- src/app/globals.css | 10 +- src/app/page.tsx | 11 +- src/app/~/dash/[uuid]/page.tsx | 66 +++++---- src/app/~/dash/layout.tsx | 2 +- src/app/~/dash/page.tsx | 11 +- src/components/CustomPageComponent.tsx | 12 +- src/components/CustomPageDashboard.tsx | 10 +- src/components/LinkFavicon.tsx | 2 +- src/components/PageListComponent.tsx | 21 ++- src/components/forms/pinPageToRootForm.tsx | 21 +++ 16 files changed, 277 insertions(+), 176 deletions(-) create mode 100644 src/components/forms/pinPageToRootForm.tsx diff --git a/package-lock.json b/package-lock.json index a7420f6..324b178 100644 --- a/package-lock.json +++ b/package-lock.json @@ -8,9 +8,10 @@ "name": "short", "version": "0.1.0", "dependencies": { + "@heroicons/react": "^2.1.5", "@prisma/client": "^5.18.0", "js-sha256": "^0.11.0", - "next": "^15.0.0-canary.135", + "next": "^15.0.0-canary.195", "ua-parser-js": "^1.0.38", "zod": "^3.23.8" }, @@ -109,6 +110,15 @@ "node": "^12.22.0 || ^14.17.0 || >=16.0.0" } }, + "node_modules/@heroicons/react": { + "version": "2.1.5", + "resolved": "https://registry.npmjs.org/@heroicons/react/-/react-2.1.5.tgz", + "integrity": "sha512-FuzFN+BsHa+7OxbvAERtgBTNeZpUjgM/MIizfVkSCL2/edriN0Hx/DWRCR//aPYwO5QX/YlgLGXk+E3PcfZwjA==", + "license": "MIT", + "peerDependencies": { + "react": ">= 16" + } + }, "node_modules/@humanwhocodes/config-array": { "version": "0.11.14", "resolved": "https://registry.npmjs.org/@humanwhocodes/config-array/-/config-array-0.11.14.tgz", @@ -609,9 +619,9 @@ } }, "node_modules/@next/env": { - "version": "15.0.0-canary.135", - "resolved": "https://registry.npmjs.org/@next/env/-/env-15.0.0-canary.135.tgz", - "integrity": "sha512-EpElU9xdz+WWkZw1SJfLK8hAoP6vFbImbkln++9VqElJhJhKsgs0fRVFS6HwZNxfnb1XsnaSDhHBzrBughgsxg==", + "version": "15.0.0-canary.195", + "resolved": "https://registry.npmjs.org/@next/env/-/env-15.0.0-canary.195.tgz", + "integrity": "sha512-GMG3ZeIq5nw+SBjH58wCMf7n3adT9NzeSs8fTb2LLTUPrdceYqombKmufRuPL2svwGByZGnyARCK8B0WEa1Z1w==", "license": "MIT" }, "node_modules/@next/eslint-plugin-next": { @@ -625,9 +635,9 @@ } }, "node_modules/@next/swc-darwin-arm64": { - "version": "15.0.0-canary.135", - "resolved": "https://registry.npmjs.org/@next/swc-darwin-arm64/-/swc-darwin-arm64-15.0.0-canary.135.tgz", - "integrity": "sha512-A8OS4H3DdGRsq0qEgTbVrF1Lba6UOZPHxhB38fq3gxhMJqz9h7+zaxXslIue7EJm15RSHXumsb/CLeucaid9Gw==", + "version": "15.0.0-canary.195", + "resolved": "https://registry.npmjs.org/@next/swc-darwin-arm64/-/swc-darwin-arm64-15.0.0-canary.195.tgz", + "integrity": "sha512-JK+VB2+AjP8iwe4t8vv3ta6oHlMxegCnSymnSonCtA5HoqRuE7cWe60vbMdk7xmRvl4oy1Josc5+hMei6SN7ZA==", "cpu": [ "arm64" ], @@ -641,9 +651,9 @@ } }, "node_modules/@next/swc-darwin-x64": { - "version": "15.0.0-canary.135", - "resolved": "https://registry.npmjs.org/@next/swc-darwin-x64/-/swc-darwin-x64-15.0.0-canary.135.tgz", - "integrity": "sha512-EwdzHu0iZt832W4aQrn5EXUbIjxpQWrNa/oIuAz/VT0qt8Kb87+EsAcGds4i43hMO17/yNyi4QUauA6wrdP2ag==", + "version": "15.0.0-canary.195", + "resolved": "https://registry.npmjs.org/@next/swc-darwin-x64/-/swc-darwin-x64-15.0.0-canary.195.tgz", + "integrity": "sha512-M0FTKKvKk3Uhe5rj9jmVv5qmdVDQ7Rc1Ex5BGziNscQVsPrE5tVX768yq6boVvH+WQyt3u2XjZCmIbdTtLAzyg==", "cpu": [ "x64" ], @@ -657,9 +667,9 @@ } }, "node_modules/@next/swc-linux-arm64-gnu": { - "version": "15.0.0-canary.135", - "resolved": "https://registry.npmjs.org/@next/swc-linux-arm64-gnu/-/swc-linux-arm64-gnu-15.0.0-canary.135.tgz", - "integrity": "sha512-Ri0+Tun75AzlvbpnDvro++MJZfnfRJlzkrR5bdXsYdBQHecjOW8RSKkJT98TwcLuUhgXuPUyZEoWi5tiShC+mA==", + "version": "15.0.0-canary.195", + "resolved": "https://registry.npmjs.org/@next/swc-linux-arm64-gnu/-/swc-linux-arm64-gnu-15.0.0-canary.195.tgz", + "integrity": "sha512-PZaECZ98Ul+dP+azmF3DhH3k4y4vbMH+LtPrRgxas2F8zMDeCfBfYm3MjNc3t7NHAoylVN/+8oxCJrfQ2e8/cw==", "cpu": [ "arm64" ], @@ -673,9 +683,9 @@ } }, "node_modules/@next/swc-linux-arm64-musl": { - "version": "15.0.0-canary.135", - "resolved": "https://registry.npmjs.org/@next/swc-linux-arm64-musl/-/swc-linux-arm64-musl-15.0.0-canary.135.tgz", - "integrity": "sha512-5irtGwLGf3D3ykXoKN+MlZOH+02CHKtdR3R/EYfW1P0fkb4/bvJOPtVCWAwy1aPWIsVScBKsjYE5Wn0BWH9R9g==", + "version": "15.0.0-canary.195", + "resolved": "https://registry.npmjs.org/@next/swc-linux-arm64-musl/-/swc-linux-arm64-musl-15.0.0-canary.195.tgz", + "integrity": "sha512-AX6pO2RQlBMGrrv/uv4exo2AKRN77a3uRHRrWlrpdQcxrjRWfuS+/7NsCzojGWHX6pUzwvCCcdgKPQpVzAQjzw==", "cpu": [ "arm64" ], @@ -689,9 +699,9 @@ } }, "node_modules/@next/swc-linux-x64-gnu": { - "version": "15.0.0-canary.135", - "resolved": "https://registry.npmjs.org/@next/swc-linux-x64-gnu/-/swc-linux-x64-gnu-15.0.0-canary.135.tgz", - "integrity": "sha512-A5iNfPGls67pEsx91QikTKd9mEjYw6ZZthbmGhtgheeY8xgTHRxx1zhbLVbcz/BAqA7wkTlyGOiQ/OKfSaIEFg==", + "version": "15.0.0-canary.195", + "resolved": "https://registry.npmjs.org/@next/swc-linux-x64-gnu/-/swc-linux-x64-gnu-15.0.0-canary.195.tgz", + "integrity": "sha512-n651qe/lmps2wgqImkBmde/ygAcrn2mXa5D825NilasjOY02NiJV+crlMO9bB+pOdVgS8P6UDCvPhy/HYFN/YA==", "cpu": [ "x64" ], @@ -705,9 +715,9 @@ } }, "node_modules/@next/swc-linux-x64-musl": { - "version": "15.0.0-canary.135", - "resolved": "https://registry.npmjs.org/@next/swc-linux-x64-musl/-/swc-linux-x64-musl-15.0.0-canary.135.tgz", - "integrity": "sha512-lUTcgWTk6w5rp7PC4IwZCXeB3yFpc9ITtIShLP4nM95U8szyR8WFeiMm2KcidwZkqY6FpRHTigR9GW3y87mfYQ==", + "version": "15.0.0-canary.195", + "resolved": "https://registry.npmjs.org/@next/swc-linux-x64-musl/-/swc-linux-x64-musl-15.0.0-canary.195.tgz", + "integrity": "sha512-HTJ3KwAodiBM6pgYKU5X+awNHuVwNxSSDQ9lNMRO3CJwwL0wI1yLXphx8Pko2RjtQkADLM+1cKdI7metypMxPQ==", "cpu": [ "x64" ], @@ -721,9 +731,9 @@ } }, "node_modules/@next/swc-win32-arm64-msvc": { - "version": "15.0.0-canary.135", - "resolved": "https://registry.npmjs.org/@next/swc-win32-arm64-msvc/-/swc-win32-arm64-msvc-15.0.0-canary.135.tgz", - "integrity": "sha512-KleCymA34fOPOhuk7EqhmOhiYuNKcpVSty/dNWuyChh5kpc03nlw3Z5LfwkxOHXSMDMPAk1DnUmG5UwUDfGBvQ==", + "version": "15.0.0-canary.195", + "resolved": "https://registry.npmjs.org/@next/swc-win32-arm64-msvc/-/swc-win32-arm64-msvc-15.0.0-canary.195.tgz", + "integrity": "sha512-U1VSVP5nyWxAaJ6PPMko7xvCCu6gsmB8OMQ/2ADlCP0duNSZ+TRdPlzsdN7YpBhcHwucVj1hVfbj/hjk3lwaiw==", "cpu": [ "arm64" ], @@ -736,26 +746,10 @@ "node": ">= 10" } }, - "node_modules/@next/swc-win32-ia32-msvc": { - "version": "15.0.0-canary.135", - "resolved": "https://registry.npmjs.org/@next/swc-win32-ia32-msvc/-/swc-win32-ia32-msvc-15.0.0-canary.135.tgz", - "integrity": "sha512-bppVsMMECcgYyuoR1SAoRMT1/Yr6n1VpnxOPxLyoikTzbkG3oMRqCgZrf9F73eowetb0RqwFg/stRbkFBKlSzA==", - "cpu": [ - "ia32" - ], - "license": "MIT", - "optional": true, - "os": [ - "win32" - ], - "engines": { - "node": ">= 10" - } - }, "node_modules/@next/swc-win32-x64-msvc": { - "version": "15.0.0-canary.135", - "resolved": "https://registry.npmjs.org/@next/swc-win32-x64-msvc/-/swc-win32-x64-msvc-15.0.0-canary.135.tgz", - "integrity": "sha512-/dkaXBPo0vz7iTWif74AZL7VP8QgVXpRvEOyHK3ir+r+OHir0Q7A+pBGQg5cb4JtmLP+KdeznMu442nLFqsyXQ==", + "version": "15.0.0-canary.195", + "resolved": "https://registry.npmjs.org/@next/swc-win32-x64-msvc/-/swc-win32-x64-msvc-15.0.0-canary.195.tgz", + "integrity": "sha512-FMzMlpmwvjrAstBuTULJ9+0sFEO632Zy0zG1UZZ4SaL5pxd1FfUaVWq4AsyeObzHY9YxlaK8hBqKyewYoMJ4+g==", "cpu": [ "x64" ], @@ -828,9 +822,9 @@ } }, "node_modules/@prisma/client": { - "version": "5.19.0", - "resolved": "https://registry.npmjs.org/@prisma/client/-/client-5.19.0.tgz", - "integrity": "sha512-CzOpau+q1kEWQyoQMvlnXIHqPvwmWbh48xZ4n8KWbAql0p8PC0BIgSTYW5ncxXa4JSEff0tcoxSZB874wDstdg==", + "version": "5.21.0", + "resolved": "https://registry.npmjs.org/@prisma/client/-/client-5.21.0.tgz", + "integrity": "sha512-Qf2YleB3dsCRXiKSQZ+j0aF5E+ojpfqF8ExXaNAWBbAhKapMduwNvgo13K2pEuTiQq8voG2aQPQnxjsO9fOpTQ==", "hasInstallScript": true, "license": "Apache-2.0", "engines": { @@ -909,9 +903,9 @@ "license": "Apache-2.0" }, "node_modules/@swc/helpers": { - "version": "0.5.12", - "resolved": "https://registry.npmjs.org/@swc/helpers/-/helpers-0.5.12.tgz", - "integrity": "sha512-KMZNXiGibsW9kvZAO1Pam2JPTDBm+KSHMMHWdsyI/1DbIZjT2A6Gy3hblVXUMEDvUAKq+e0vL0X0o54owWji7g==", + "version": "0.5.13", + "resolved": "https://registry.npmjs.org/@swc/helpers/-/helpers-0.5.13.tgz", + "integrity": "sha512-UoKGxQ3r5kYI9dALKJapMmuK+1zWM/H17Z1+iwnNmzcJRnfFuevZs375TA5rW31pu4BS4NoSy1fRsexDXfWn5w==", "license": "Apache-2.0", "dependencies": { "tslib": "^2.4.0" @@ -2975,6 +2969,7 @@ "version": "4.2.11", "resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.2.11.tgz", "integrity": "sha512-RbJ5/jmFcNNCcDV5o9eTnBLJ/HszWV0P73bc+Ff4nS/rJj+YaS6IGyiOL0VoBYX+l1Wrl3k63h/KrH+nhJ0XvQ==", + "dev": true, "license": "ISC" }, "node_modules/graphemer": { @@ -3642,7 +3637,6 @@ "version": "4.0.0", "resolved": "https://registry.npmjs.org/js-tokens/-/js-tokens-4.0.0.tgz", "integrity": "sha512-RdJUflcE3cUzKiMqQgsCu06FPu9UdIJO0beYbPhHN4k6apgJtifcoCtT9bcxOpYBtpD2kCM6Sbzg4CausW/PKQ==", - "dev": true, "license": "MIT" }, "node_modules/js-yaml": { @@ -3796,7 +3790,6 @@ "version": "1.4.0", "resolved": "https://registry.npmjs.org/loose-envify/-/loose-envify-1.4.0.tgz", "integrity": "sha512-lyuxPGr/Wfhrlem2CL/UcnUc1zcqKAImBDzukY7Y5F/yQiNdko6+fRLevlw1HgMySw7f611UIY408EtxRSoK3Q==", - "dev": true, "license": "MIT", "dependencies": { "js-tokens": "^3.0.0 || ^4.0.0" @@ -3914,17 +3907,16 @@ "license": "MIT" }, "node_modules/next": { - "version": "15.0.0-canary.135", - "resolved": "https://registry.npmjs.org/next/-/next-15.0.0-canary.135.tgz", - "integrity": "sha512-xR6MUpaVS2H8Ktp7ZDICHFvdDdvD/VfzSFfuvZLMMTluTZL2NuM4CVS9bHXIlMPo897MyWTfFFoPoamHXItxQw==", + "version": "15.0.0-canary.195", + "resolved": "https://registry.npmjs.org/next/-/next-15.0.0-canary.195.tgz", + "integrity": "sha512-6oFt67faSIAcXthtj37IIVETENBReNrrxwJ4ggDL72rULoONhmvohJhg6S/cCxfkw9lVqh7CHG0rjj1zhH6mUA==", "license": "MIT", "dependencies": { - "@next/env": "15.0.0-canary.135", + "@next/env": "15.0.0-canary.195", "@swc/counter": "0.1.3", - "@swc/helpers": "0.5.12", + "@swc/helpers": "0.5.13", "busboy": "1.6.0", "caniuse-lite": "^1.0.30001579", - "graceful-fs": "^4.2.11", "postcss": "8.4.31", "styled-jsx": "5.1.6" }, @@ -3935,23 +3927,22 @@ "node": ">=18.18.0" }, "optionalDependencies": { - "@next/swc-darwin-arm64": "15.0.0-canary.135", - "@next/swc-darwin-x64": "15.0.0-canary.135", - "@next/swc-linux-arm64-gnu": "15.0.0-canary.135", - "@next/swc-linux-arm64-musl": "15.0.0-canary.135", - "@next/swc-linux-x64-gnu": "15.0.0-canary.135", - "@next/swc-linux-x64-musl": "15.0.0-canary.135", - "@next/swc-win32-arm64-msvc": "15.0.0-canary.135", - "@next/swc-win32-ia32-msvc": "15.0.0-canary.135", - "@next/swc-win32-x64-msvc": "15.0.0-canary.135", - "sharp": "^0.33.4" + "@next/swc-darwin-arm64": "15.0.0-canary.195", + "@next/swc-darwin-x64": "15.0.0-canary.195", + "@next/swc-linux-arm64-gnu": "15.0.0-canary.195", + "@next/swc-linux-arm64-musl": "15.0.0-canary.195", + "@next/swc-linux-x64-gnu": "15.0.0-canary.195", + "@next/swc-linux-x64-musl": "15.0.0-canary.195", + "@next/swc-win32-arm64-msvc": "15.0.0-canary.195", + "@next/swc-win32-x64-msvc": "15.0.0-canary.195", + "sharp": "^0.33.5" }, "peerDependencies": { "@opentelemetry/api": "^1.1.0", "@playwright/test": "^1.41.2", "babel-plugin-react-compiler": "*", - "react": "19.0.0-rc-7771d3a7-20240827", - "react-dom": "19.0.0-rc-7771d3a7-20240827", + "react": "^18.2.0 || 19.0.0-rc-cd22717c-20241013", + "react-dom": "^18.2.0 || 19.0.0-rc-cd22717c-20241013", "sass": "^1.3.0" }, "peerDependenciesMeta": { @@ -4576,26 +4567,30 @@ "license": "MIT" }, "node_modules/react": { - "version": "19.0.0-rc-7771d3a7-20240827", - "resolved": "https://registry.npmjs.org/react/-/react-19.0.0-rc-7771d3a7-20240827.tgz", - "integrity": "sha512-Xg6LoxgPpT4efYHzRB2gUUQCoNXu2df3sOBRgiUvzTVT1qQNOV611/w80JiOmnTWlIyCaUfSkNrMG8OUO/D+AA==", + "version": "18.3.1", + "resolved": "https://registry.npmjs.org/react/-/react-18.3.1.tgz", + "integrity": "sha512-wS+hAgJShR0KhEvPJArfuPVN1+Hz1t0Y6n5jLrGQbkb4urgPE/0Rve+1kMB1v/oWgHgm4WIcV+i7F2pTVj+2iQ==", "license": "MIT", "peer": true, + "dependencies": { + "loose-envify": "^1.1.0" + }, "engines": { "node": ">=0.10.0" } }, "node_modules/react-dom": { - "version": "19.0.0-rc-7771d3a7-20240827", - "resolved": "https://registry.npmjs.org/react-dom/-/react-dom-19.0.0-rc-7771d3a7-20240827.tgz", - "integrity": "sha512-EMgZJX6EEQEr+pso+9ySkrEMPv3N7zF2fbi0f6uB+X7r8E+O2GqPRcIHtFigMdW8uS0XCVFHAocMnIc4yPULYQ==", + "version": "18.3.1", + "resolved": "https://registry.npmjs.org/react-dom/-/react-dom-18.3.1.tgz", + "integrity": "sha512-5m4nQKp+rZRb09LNH59GM4BxTh9251/ylbKIbpe7TpGxfJ+9kv6BLkLBXIjjspbgbnIBNqlI23tRnTWT0snUIw==", "license": "MIT", "peer": true, "dependencies": { - "scheduler": "0.25.0-rc-7771d3a7-20240827" + "loose-envify": "^1.1.0", + "scheduler": "^0.23.2" }, "peerDependencies": { - "react": "19.0.0-rc-7771d3a7-20240827" + "react": "^18.3.1" } }, "node_modules/react-is": { @@ -4819,11 +4814,14 @@ } }, "node_modules/scheduler": { - "version": "0.25.0-rc-7771d3a7-20240827", - "resolved": "https://registry.npmjs.org/scheduler/-/scheduler-0.25.0-rc-7771d3a7-20240827.tgz", - "integrity": "sha512-n4nHmAoerbIOSrH24w0+fcdCUwQ4Npm7yXfsrn09FL01OWIaxpuo4P0rj3qPyLFgsJDbn18sWvLVB/e/KPnR+A==", + "version": "0.23.2", + "resolved": "https://registry.npmjs.org/scheduler/-/scheduler-0.23.2.tgz", + "integrity": "sha512-UOShsPwz7NrMUqhR6t0hWjFduvOzbtv7toDH1/hIrfRNIDBnnBWd0CwJTGvTpngVlmwGCdP9/Zl/tVrDqcuYzQ==", "license": "MIT", - "peer": true + "peer": true, + "dependencies": { + "loose-envify": "^1.1.0" + } }, "node_modules/semver": { "version": "7.6.3", diff --git a/package.json b/package.json index d687471..2229bc3 100644 --- a/package.json +++ b/package.json @@ -9,9 +9,10 @@ "lint": "next lint" }, "dependencies": { + "@heroicons/react": "^2.1.5", "@prisma/client": "^5.18.0", "js-sha256": "^0.11.0", - "next": "^15.0.0-canary.135", + "next": "^15.0.0-canary.195", "ua-parser-js": "^1.0.38", "zod": "^3.23.8" }, diff --git a/prisma/schema.prisma b/prisma/schema.prisma index 7150577..f7466b7 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -11,25 +11,26 @@ datasource db { model Page { uuid String @id @default(uuid()) shortcode String @unique - created_at DateTime @default(now()) - updated_at DateTime @updatedAt - RedirectPage RedirectPage[] - CustomPage CustomPage[] - Stat Stat[] + createdAt DateTime @default(now()) + updatedAt DateTime @updatedAt + redirectPage RedirectPage[] + customPage CustomPage[] + stat Stat[] + pinnedPage PinnedPage? @@index([shortcode]) } // The redirect page for the url shortener model RedirectPage { - uuid String @id @default(uuid()) - created_at DateTime @default(now()) - updated_at DateTime @updatedAt - dest String + uuid String @id @default(uuid()) + createdAt DateTime @default(now()) + updatedAt DateTime @updatedAt + dest String page Page @relation(fields: [pageUuid], references: [uuid]) pageUuid String - LinkBlock LinkBlock[] + linkBlock LinkBlock[] } // The custom page to display mutliple blocks of text and links @@ -42,20 +43,20 @@ model CustomPage { page Page @relation(fields: [pageUuid], references: [uuid]) pageUuid String - TextBlock TextBlock[] - LinkBlock LinkBlock[] + textBlock TextBlock[] + linkBlock LinkBlock[] } // Text block to be displayed on the custom page // To provide additional information model TextBlock { - uuid String @id @default(uuid()) - order Int - text String - created_at DateTime @default(now()) - updated_at DateTime @updatedAt + uuid String @id @default(uuid()) + order Int + text String + createdAt DateTime @default(now()) + updatedAt DateTime @updatedAt - custom_page CustomPage @relation(fields: [customPageUuid], references: [uuid]) + customPage CustomPage @relation(fields: [customPageUuid], references: [uuid]) customPageUuid String } @@ -65,19 +66,28 @@ model LinkBlock { order Int title String - custom_page CustomPage @relation(fields: [customPageUuid], references: [uuid]) - redirect_page RedirectPage @relation(fields: [redirectPageUuid], references: [uuid]) + customPage CustomPage @relation(fields: [customPageUuid], references: [uuid]) + redirectPage RedirectPage @relation(fields: [redirectPageUuid], references: [uuid]) customPageUuid String redirectPageUuid String } // Statts to track the links being accessed model Stat { - uuid String @id @default(uuid()) - accessed_at DateTime @default(now()) - hash String? @db.VarChar(64) - user_agent String? @db.Text + uuid String @id @default(uuid()) + accessedAt DateTime @default(now()) + hash String? @db.VarChar(64) + userAgent String? @db.Text page Page @relation(fields: [pageUuid], references: [uuid]) pageUuid String } + +model PinnedPage { + id Int @id @default(1) + createdAt DateTime @default(now()) + updatedAt DateTime @updatedAt + + page Page @relation(fields: [pageUuid], references: [uuid]) + pageUuid String @unique +} diff --git a/src/actions/block_actions.ts b/src/actions/block_actions.ts index bcd424f..757d962 100644 --- a/src/actions/block_actions.ts +++ b/src/actions/block_actions.ts @@ -3,8 +3,6 @@ import { z } from "zod"; import prisma from "../../prisma/prisma"; import { revalidatePath } from "next/cache"; -import { title } from "process"; - export async function createLinkBlock(prevState: any, formData: FormData) { @@ -44,9 +42,9 @@ export async function createLinkBlock(prevState: any, formData: FormData) { const page = await prisma.page.findUnique({ where: { shortcode: data.data.redirectPageShortcode }, - include: { RedirectPage: true } + include: { redirectPage: true } }); - const redirectPage = page?.RedirectPage[0] + const redirectPage = page?.redirectPage[0] if (!redirectPage) { return { message: "Redirect page not found", diff --git a/src/actions/page_actions.ts b/src/actions/page_actions.ts index ca111e3..7206d3c 100644 --- a/src/actions/page_actions.ts +++ b/src/actions/page_actions.ts @@ -3,6 +3,7 @@ import { z } from "zod"; import prisma from "../../prisma/prisma"; import { revalidatePath } from "next/cache"; +import { error } from "console"; export async function createCustomPage(prevState: any, fromData: FormData) { const schema = z.object({ @@ -146,4 +147,42 @@ export async function deletePage(prevState: any, fromData: FormData) { message: "Page deleted", }; +} + +export async function pinPageToRoot(prevState: any, fromData: FormData) { + const schema = z.object({ + uuid: z.string().uuid() + }); + + const data = schema.safeParse({ + uuid: fromData.get("uuid") + }); + + if (!data.success) { + return { + message: "Invalid data", + error: data.error.flatten().fieldErrors, + }; + } + + await prisma.pinnedPage.upsert({ + where: { + id: 1 + }, + update: { + pageUuid: data.data.uuid + }, + create: { + id: 1, + pageUuid: data.data.uuid + } + }); + + revalidatePath("/dash"); + revalidatePath("/"); + + return { + message: "Page pinned", + }; + } \ No newline at end of file diff --git a/src/app/[shortcode]/page.tsx b/src/app/[shortcode]/page.tsx index cc4f8c6..f93efd6 100644 --- a/src/app/[shortcode]/page.tsx +++ b/src/app/[shortcode]/page.tsx @@ -6,12 +6,13 @@ import CustomPageComponent from "@/components/CustomPageComponent"; export default async function RedirectToUrl({ params }: { params: { shortcode: string } }) { + const { shortcode } = await params; const page = await prisma.page.findUnique({ - where: {shortcode: params.shortcode}, + where: {shortcode: shortcode}, include: { - RedirectPage: true, - CustomPage: true + redirectPage: true, + customPage: true } }); @@ -21,7 +22,7 @@ export default async function RedirectToUrl({ params }: { params: { shortcode: s } // Logg the visit - const requestHeaders = headers(); + const requestHeaders = await headers(); const userAgent = requestHeaders.get('user-agent') || 'unknown'; const ip = requestHeaders.get('x-forwarded-for') || 'unknown'; const anonymIp = ip.replace(/(\d+)\.(\d+)\.(\d+)\.(\d+)/, '$1.$2.$3.0'); @@ -29,21 +30,21 @@ export default async function RedirectToUrl({ params }: { params: { shortcode: s await prisma.stat.create({ data: { pageUuid: page.uuid, - user_agent: userAgent, + userAgent: userAgent, hash: hash } }); - if (page.RedirectPage.length>0) { + if (page.redirectPage.length>0) { // Redirect to the destination - const redirectPage = page.RedirectPage[0]; + const redirectPage = page.redirectPage[0]; redirect(redirectPage.dest); - }else if (page.CustomPage.length>0) { + }else if (page.customPage.length>0) { // Show the custom page - const customPage = page.CustomPage[0]; + const customPage = page.customPage[0]; return } else { diff --git a/src/app/globals.css b/src/app/globals.css index 85e46c0..d38c1e0 100644 --- a/src/app/globals.css +++ b/src/app/globals.css @@ -4,7 +4,7 @@ body { - @apply text-gray-300 bg-gray-900 m-10 + @apply text-gray-300 bg-gray-900 } h1 { @@ -45,4 +45,12 @@ label { button { @apply rounded bg-green-600 hover:bg-green-700 text-white py-2 px-4 disabled:opacity-50 +} + +.zebra { + @apply odd:bg-slate-800 p-2 rounded +} + +.common-red { + @apply text-red-500 } \ No newline at end of file diff --git a/src/app/page.tsx b/src/app/page.tsx index eb2e999..96a6cea 100644 --- a/src/app/page.tsx +++ b/src/app/page.tsx @@ -1,7 +1,16 @@ import Image from "next/image"; import Link from "next/link"; +import prisma from "../../prisma/prisma"; +import { redirect } from "next/navigation"; + +export default async function Home() { + + const pinnedPage = await prisma.pinnedPage.findFirst({where: {id: 1}, include: {page: true}}); + + if (pinnedPage) { + redirect(pinnedPage.page.shortcode); + } -export default function Home() { return ( (<>

Home

diff --git a/src/app/~/dash/[uuid]/page.tsx b/src/app/~/dash/[uuid]/page.tsx index 56598ff..3ddb87a 100644 --- a/src/app/~/dash/[uuid]/page.tsx +++ b/src/app/~/dash/[uuid]/page.tsx @@ -1,44 +1,48 @@ -import Image from "next/image"; import prisma from "../../../../../prisma/prisma"; import { redirect } from "next/navigation"; -import DeletePageForm from "@/components/forms/deletePageForm"; -import { hashToColor } from "@/utils"; import Link from "next/link"; -import CreateCustomPageForm from "@/components/forms/createCustomPageForm"; -import CreateLinkBlockForm from "@/components/forms/createLinkBlockForm"; +import Image from "next/image"; +import DeletePageForm from "@/components/forms/deletePageForm"; import CustomPageDashboard from "@/components/CustomPageDashboard"; import LinkFavicon from "@/components/LinkFavicon"; +import { hashToColor } from "@/utils"; +import PinPageToRootForm from "@/components/forms/pinPageToRootForm"; export default async function DetailedStats({ params }: { params: { uuid: string } }) { + + const { uuid } = await params; const page = await prisma.page.findUnique({ - where: { uuid: params.uuid }, + where: { uuid: uuid }, include: { - RedirectPage: true, - CustomPage: true, - Stat: { orderBy: { accessed_at: "desc" } }, + pinnedPage: true, + redirectPage: true, + customPage: true, + stat: { orderBy: { accessedAt: "desc" } }, _count: { - select: { Stat: true } + select: { stat: true } } } }); + + // group stats by hash const stats = await prisma.stat.groupBy({ - by: ['hash', 'user_agent'], + by: ['hash', 'userAgent'], where: { - pageUuid: params.uuid + pageUuid: uuid }, _count: { uuid: true }, _max: { - accessed_at: true + accessedAt: true }, orderBy: { _max: { - accessed_at: "desc" + accessedAt: "desc" } } }); @@ -48,8 +52,8 @@ export default async function DetailedStats({ params }: { params: { uuid: string //return notFound(); } - const redirectPage = page.RedirectPage[0]; - const customPage = page.CustomPage[0]; + const redirectPage = page.redirectPage[0]; + const customPage = page.customPage[0]; // get shortcodes if the page is a custom page to use in the link block form const linkPages = customPage ? await prisma.redirectPage.findMany({ include: { page: true } }) : undefined @@ -66,18 +70,25 @@ export default async function DetailedStats({ params }: { params: { uuid: string width={100} height={100} alt=" " + className="rounded-full" />} : ""}

Shortcode: {page.shortcode}

- {page.RedirectPage.length > 0 ? -

{page.RedirectPage[0].dest}

: ""} + {page.redirectPage.length > 0 ? +

{page.redirectPage[0].dest}

: ""} +
+
+ {page.pinnedPage ?

Pinned to root

: ""}
+
+ +
@@ -87,23 +98,22 @@ export default async function DetailedStats({ params }: { params: { uuid: string {customPage ? : ""}

Stats

-

All visits (not unique): {page._count.Stat}

+

All visits (not unique): {page._count.stat}



Visitors

- {stats.map((stat) => (
-

{stat.user_agent}

+ {stats.map((stat) => (
+

{stat.userAgent}

{stat.hash}

Visits: {"" + stat._count.uuid}

-

Last Visit: {stat._max.accessed_at?.toDateString()}

+

Last Visit: {stat._max.accessedAt?.toDateString()}

))} -

All Visits

- - {page.Stat.map((stat) => (
-

{stat.accessed_at.toDateString()}

-

{stat.user_agent}

+ {/*

All Visits

+ {page.stat.map((stat) => (
+

{stat.accessedAt.toDateString()}

+

{stat.userAgent}

{stat.hash}

-
))} +
))} */}
); } \ No newline at end of file diff --git a/src/app/~/dash/layout.tsx b/src/app/~/dash/layout.tsx index d6f67cf..920f436 100644 --- a/src/app/~/dash/layout.tsx +++ b/src/app/~/dash/layout.tsx @@ -6,7 +6,7 @@ import React, { ReactNode } from 'react'; export default function Dashboard({ children }: { children: ReactNode }) { return ( -
+

Dashboard

diff --git a/src/app/~/dash/page.tsx b/src/app/~/dash/page.tsx index 1783ff8..c308955 100644 --- a/src/app/~/dash/page.tsx +++ b/src/app/~/dash/page.tsx @@ -9,16 +9,17 @@ export default async function Dashboard() { const pages = await prisma.page.findMany({ include: { - RedirectPage: true, - CustomPage: true, + pinnedPage: true, + redirectPage: true, + customPage: true, _count: { - select: { Stat: true } + select: { stat: true } } } }); - const redirectPages = pages.filter((page) => page.RedirectPage.length > 0); - const customPages = pages.filter((page) => page.CustomPage.length > 0); + const redirectPages = pages.filter((page) => page.redirectPage.length > 0); + const customPages = pages.filter((page) => page.customPage.length > 0); return (<>

Redirect Pages

diff --git a/src/components/CustomPageComponent.tsx b/src/components/CustomPageComponent.tsx index 97d2111..aec2c6a 100644 --- a/src/components/CustomPageComponent.tsx +++ b/src/components/CustomPageComponent.tsx @@ -14,12 +14,12 @@ export default async function CustomPageComponent(params: { customPage: CustomPa order: "asc" }, include: { - redirect_page: { include: { page: true } } + redirectPage: { include: { page: true } } } }); return ( -
+

{customPage.title}

-
+
{linkBlocks.map((block) => ( -
diff --git a/src/components/LinkFavicon.tsx b/src/components/LinkFavicon.tsx index bda1930..d75a02c 100644 --- a/src/components/LinkFavicon.tsx +++ b/src/components/LinkFavicon.tsx @@ -3,7 +3,6 @@ import Image from "next/image"; export default function LinkFavicon({ url }: { url: string }) { const hostname = new URL(url).hostname; - console.log(hostname); return (
); diff --git a/src/components/PageListComponent.tsx b/src/components/PageListComponent.tsx index 13daf9f..cc86cae 100644 --- a/src/components/PageListComponent.tsx +++ b/src/components/PageListComponent.tsx @@ -1,25 +1,26 @@ import React from 'react'; import type { Prisma } from '@prisma/client'; -import DeletePageForm from './forms/deletePageForm'; import Image from 'next/image'; import Link from 'next/link'; -import prisma from '../../prisma/prisma'; import LinkFavicon from './LinkFavicon'; +import PinPageToRootForm from './forms/pinPageToRootForm'; type PageWithRelations = Prisma.PageGetPayload<{ include: { - RedirectPage: true; - CustomPage: true; + pinnedPage: true; + redirectPage: true; + customPage: true; _count: { - select: { Stat: true } + select: { stat: true } } } }> export default async function PageListComponent({ page }: { page: PageWithRelations }) { - const redirectPage = page.RedirectPage[0]; - const customPage = page.CustomPage[0]; + const redirectPage = page.redirectPage[0]; + const customPage = page.customPage[0]; + return ( @@ -32,6 +33,7 @@ export default async function PageListComponent({ page }: { page: PageWithRelati height={100} src={`data:image/png;base64,${customPage.image}`} alt="icon" + className="rounded-full" />}
@@ -39,8 +41,11 @@ export default async function PageListComponent({ page }: { page: PageWithRelati

{redirectPage ? redirectPage.dest : customPage.title}

+
+ {page.pinnedPage ?

Pinned to root

: ""} +
- {page._count.Stat ?

{page._count.Stat} visits

: ""} + {page._count.stat ?

{page._count.stat} visits

: ""} {// }
diff --git a/src/components/forms/pinPageToRootForm.tsx b/src/components/forms/pinPageToRootForm.tsx new file mode 100644 index 0000000..9d34fe6 --- /dev/null +++ b/src/components/forms/pinPageToRootForm.tsx @@ -0,0 +1,21 @@ +"use client" +import { pinPageToRoot } from "@/actions/page_actions"; +import { BookmarkIcon } from "@heroicons/react/24/solid"; +import { useActionState, useState } from "react"; + +export default function PinPageToRootForm({ pageUuid, disabled }: { pageUuid: string, disabled: boolean }) { + + const initialState = { + message: "", + error: {} + }; + + const [state, formAction] = useActionState(pinPageToRoot, initialState); + + + return (
+ + {/*

{state.message}

*/} + +
) +} \ No newline at end of file