Merge branch 'dev' of https://github.com/linkwarden/linkwarden into feat/single-file
This commit is contained in:
commit
359d22e61b
10
.env.sample
10
.env.sample
|
@ -21,6 +21,8 @@ ARCHIVE_TAKE_COUNT=
|
||||||
BROWSER_TIMEOUT=
|
BROWSER_TIMEOUT=
|
||||||
IGNORE_UNAUTHORIZED_CA=
|
IGNORE_UNAUTHORIZED_CA=
|
||||||
IGNORE_HTTPS_ERRORS=
|
IGNORE_HTTPS_ERRORS=
|
||||||
|
IGNORE_URL_SIZE_LIMIT=
|
||||||
|
ADMINISTRATOR=
|
||||||
|
|
||||||
# AWS S3 Settings
|
# AWS S3 Settings
|
||||||
SPACES_KEY=
|
SPACES_KEY=
|
||||||
|
@ -34,6 +36,7 @@ SPACES_FORCE_PATH_STYLE=
|
||||||
NEXT_PUBLIC_EMAIL_PROVIDER=
|
NEXT_PUBLIC_EMAIL_PROVIDER=
|
||||||
EMAIL_FROM=
|
EMAIL_FROM=
|
||||||
EMAIL_SERVER=
|
EMAIL_SERVER=
|
||||||
|
BASE_URL=
|
||||||
|
|
||||||
# Proxy settings
|
# Proxy settings
|
||||||
PROXY=
|
PROXY=
|
||||||
|
@ -79,6 +82,13 @@ AUTH0_ISSUER=
|
||||||
AUTH0_CLIENT_SECRET=
|
AUTH0_CLIENT_SECRET=
|
||||||
AUTH0_CLIENT_ID=
|
AUTH0_CLIENT_ID=
|
||||||
|
|
||||||
|
# Authelia
|
||||||
|
NEXT_PUBLIC_AUTHELIA_ENABLED=""
|
||||||
|
AUTHELIA_CLIENT_ID=""
|
||||||
|
AUTHELIA_CLIENT_SECRET=""
|
||||||
|
AUTHELIA_WELLKNOWN_URL=""
|
||||||
|
|
||||||
|
|
||||||
# Authentik
|
# Authentik
|
||||||
NEXT_PUBLIC_AUTHENTIK_ENABLED=
|
NEXT_PUBLIC_AUTHENTIK_ENABLED=
|
||||||
AUTHENTIK_CUSTOM_NAME=
|
AUTHENTIK_CUSTOM_NAME=
|
||||||
|
|
|
@ -0,0 +1,143 @@
|
||||||
|
name: Linkwarden Playwright Tests
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- main
|
||||||
|
- qacomet/**
|
||||||
|
pull_request:
|
||||||
|
workflow_dispatch:
|
||||||
|
|
||||||
|
env:
|
||||||
|
PGHOST: localhost
|
||||||
|
PGPORT: 5432
|
||||||
|
PGUSER: postgres
|
||||||
|
PGPASSWORD: password
|
||||||
|
PGDATABASE: postgres
|
||||||
|
|
||||||
|
TEST_POSTGRES_USER: test_linkwarden_user
|
||||||
|
TEST_POSTGRES_PASSWORD: password
|
||||||
|
TEST_POSTGRES_DATABASE: test_linkwarden_db
|
||||||
|
TEST_POSTGRES_DATABASE_TEMPLATE: test_linkwarden_db_template
|
||||||
|
TEST_POSTGRES_HOST: localhost
|
||||||
|
TEST_POSTGREST_PORT: 5432
|
||||||
|
PRODUCTION_POSTGRES_DATABASE: linkwarden_db
|
||||||
|
|
||||||
|
NEXTAUTH_SECRET: very_sensitive_secret
|
||||||
|
NEXTAUTH_URL: http://localhost:3000/api/v1/auth
|
||||||
|
|
||||||
|
# Manual installation database settings
|
||||||
|
DATABASE_URL: postgresql://test_linkwarden_user:password@localhost:5432/test_linkwarden_db
|
||||||
|
|
||||||
|
# Docker installation database settings
|
||||||
|
POSTGRES_PASSWORD: password
|
||||||
|
|
||||||
|
TEST_USERNAME: test-user
|
||||||
|
TEST_PASSWORD: password
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
playwright-test-runner:
|
||||||
|
strategy:
|
||||||
|
matrix:
|
||||||
|
test_case: ['@login']
|
||||||
|
timeout-minutes: 20
|
||||||
|
runs-on:
|
||||||
|
- ubuntu-22.04
|
||||||
|
services:
|
||||||
|
postgres:
|
||||||
|
image: postgres:16-alpine
|
||||||
|
env:
|
||||||
|
POSTGRES_USER: postgres
|
||||||
|
POSTGRES_PASSWORD: password
|
||||||
|
POSTGRES_DB: postgres
|
||||||
|
ports:
|
||||||
|
- 5432:5432
|
||||||
|
options: >-
|
||||||
|
--health-cmd pg_isready
|
||||||
|
--health-interval 10s
|
||||||
|
--health-timeout 5s
|
||||||
|
--health-retries 5
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v2
|
||||||
|
|
||||||
|
- name: Use Node.js
|
||||||
|
uses: actions/setup-node@v3
|
||||||
|
with:
|
||||||
|
node-version: "18"
|
||||||
|
cache: 'yarn'
|
||||||
|
|
||||||
|
- name: Initialize PostgreSQL
|
||||||
|
run: |
|
||||||
|
echo "Initializing Databases"
|
||||||
|
psql -h localhost -U postgres -d postgres -c "CREATE USER ${{ env.TEST_POSTGRES_USER }} WITH PASSWORD '${{ env.TEST_POSTGRES_PASSWORD }}';"
|
||||||
|
psql -h localhost -U postgres -d postgres -c "CREATE DATABASE ${{ env.TEST_POSTGRES_DATABASE }} OWNER ${{ env.TEST_POSTGRES_USER }};"
|
||||||
|
|
||||||
|
- name: Install packages
|
||||||
|
run: yarn install -y
|
||||||
|
|
||||||
|
- name: Cache playwright dependencies
|
||||||
|
uses: awalsh128/cache-apt-pkgs-action@latest
|
||||||
|
with:
|
||||||
|
packages: |
|
||||||
|
ffmpeg fonts-freefont-ttf fonts-ipafont-gothic fonts-tlwg-loma-otf
|
||||||
|
fonts-unifont fonts-wqy-zenhei gstreamer1.0-libav gstreamer1.0-plugins-bad
|
||||||
|
gstreamer1.0-plugins-base gstreamer1.0-plugins-good libaa1 libass9
|
||||||
|
libasyncns0 libavc1394-0 libavcodec58 libavdevice58 libavfilter7
|
||||||
|
libavformat58 libavutil56 libbluray2 libbs2b0 libcaca0 libcdio-cdda2
|
||||||
|
libcdio-paranoia2 libcdio19 libcdparanoia0 libchromaprint1 libcodec2-1.0
|
||||||
|
libdc1394-25 libdca0 libdecor-0-0 libdv4 libdvdnav4 libdvdread8 libegl-mesa0
|
||||||
|
libegl1 libevdev2 libevent-2.1-7 libfaad2 libffi7 libflac8 libflite1
|
||||||
|
libfluidsynth3 libfreeaptx0 libgles2 libgme0 libgsm1 libgssdp-1.2-0
|
||||||
|
libgstreamer-gl1.0-0 libgstreamer-plugins-bad1.0-0
|
||||||
|
libgstreamer-plugins-base1.0-0 libgstreamer-plugins-good1.0-0 libgupnp-1.2-1
|
||||||
|
libgupnp-igd-1.0-4 libharfbuzz-icu0 libhyphen0 libiec61883-0
|
||||||
|
libinstpatch-1.0-2 libjack-jackd2-0 libkate1 libldacbt-enc2 liblilv-0-0
|
||||||
|
libltc11 libmanette-0.2-0 libmfx1 libmjpegutils-2.1-0 libmodplug1
|
||||||
|
libmp3lame0 libmpcdec6 libmpeg2encpp-2.1-0 libmpg123-0 libmplex2-2.1-0
|
||||||
|
libmysofa1 libnice10 libnotify4 libopenal-data libopenal1 libopengl0
|
||||||
|
libopenh264-6 libopenmpt0 libopenni2-0 libopus0 liborc-0.4-0
|
||||||
|
libpocketsphinx3 libpostproc55 libpulse0 libqrencode4 libraw1394-11
|
||||||
|
librubberband2 libsamplerate0 libsbc1 libsdl2-2.0-0 libserd-0-0 libshine3
|
||||||
|
libshout3 libsndfile1 libsndio7.0 libsord-0-0 libsoundtouch1 libsoup-3.0-0
|
||||||
|
libsoup-3.0-common libsoxr0 libspandsp2 libspeex1 libsphinxbase3
|
||||||
|
libsratom-0-0 libsrt1.4-gnutls libsrtp2-1 libssh-gcrypt-4 libswresample3
|
||||||
|
libswscale5 libtag1v5 libtag1v5-vanilla libtheora0 libtwolame0 libudfread0
|
||||||
|
libv4l-0 libv4lconvert0 libva-drm2 libva-x11-2 libva2 libvdpau1
|
||||||
|
libvidstab1.1 libvisual-0.4-0 libvo-aacenc0 libvo-amrwbenc0 libvorbisenc2
|
||||||
|
libvpx7 libwavpack1 libwebrtc-audio-processing1 libwildmidi2 libwoff1
|
||||||
|
libx264-163 libxcb-shape0 libxv1 libxvidcore4 libzbar0 libzimg2
|
||||||
|
libzvbi-common libzvbi0 libzxingcore1 ocl-icd-libopencl1 timgm6mb-soundfont
|
||||||
|
xfonts-cyrillic xfonts-encodings xfonts-scalable xfonts-utils
|
||||||
|
|
||||||
|
- name: Cache playwright browsers
|
||||||
|
id: cache-playwright
|
||||||
|
uses: actions/cache@v4
|
||||||
|
with:
|
||||||
|
path: ~/.cache/
|
||||||
|
key: ${{ runner.os }}-playwright-${{ hashFiles('**/yarn.lock') }}
|
||||||
|
restore-keys: |
|
||||||
|
${{ runner.os }}-playwright-
|
||||||
|
|
||||||
|
- name: Install playwright
|
||||||
|
if: steps.cache-playwright.outputs.cache-hit != 'true'
|
||||||
|
run: yarn playwright install --with-deps
|
||||||
|
|
||||||
|
- name: Setup project
|
||||||
|
run: |
|
||||||
|
yarn prisma generate
|
||||||
|
yarn build
|
||||||
|
yarn prisma migrate deploy
|
||||||
|
|
||||||
|
- name: Start linkwarden server and worker
|
||||||
|
run: yarn start &
|
||||||
|
|
||||||
|
- name: Run Tests
|
||||||
|
run: npx playwright test --grep ${{ matrix.test_case }}
|
||||||
|
|
||||||
|
- uses: actions/upload-artifact@v3
|
||||||
|
if: always()
|
||||||
|
with:
|
||||||
|
name: playwright-report
|
||||||
|
path: test-results
|
||||||
|
retention-days: 30
|
|
@ -42,9 +42,15 @@ prisma/dev.db
|
||||||
# tests
|
# tests
|
||||||
/tests
|
/tests
|
||||||
/test-results/
|
/test-results/
|
||||||
|
/blob-report/
|
||||||
/playwright-report/
|
/playwright-report/
|
||||||
/playwright/.cache/
|
/playwright/.cache/
|
||||||
|
/playwright/.auth/
|
||||||
|
|
||||||
# docker
|
# docker
|
||||||
pgdata
|
pgdata
|
||||||
certificates
|
certificates
|
||||||
|
/test-results/
|
||||||
|
/playwright-report/
|
||||||
|
/blob-report/
|
||||||
|
/playwright/.cache/
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
node_modules
|
node_modules
|
||||||
.next
|
.next
|
||||||
public
|
/public
|
||||||
|
|
||||||
*.lock
|
*.lock
|
||||||
*.log
|
*.log
|
||||||
|
|
|
@ -1 +1,6 @@
|
||||||
{}
|
{
|
||||||
|
"tailwindCSS.experimental.classRegex": [
|
||||||
|
["cva\\(([^)]*)\\)", "[\"'`]([^\"'`]*).*?[\"'`]"],
|
||||||
|
["cx\\(([^)]*)\\)", "(?:'|\"|`)([^']*)(?:'|\"|`)"]
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
|
@ -1,29 +0,0 @@
|
||||||
type Props = {
|
|
||||||
onClick?: Function;
|
|
||||||
label: string;
|
|
||||||
loading?: boolean;
|
|
||||||
className?: string;
|
|
||||||
type?: "button" | "submit" | "reset" | undefined;
|
|
||||||
};
|
|
||||||
|
|
||||||
export default function AccentSubmitButton({
|
|
||||||
onClick,
|
|
||||||
label,
|
|
||||||
loading,
|
|
||||||
className,
|
|
||||||
type,
|
|
||||||
}: Props) {
|
|
||||||
return (
|
|
||||||
<button
|
|
||||||
type={type ? type : undefined}
|
|
||||||
className={`border primary-btn-gradient select-none duration-200 bg-black border-[oklch(var(--p))] hover:border-[#0070b5] rounded-lg text-center px-4 py-2 text-white active:scale-95 tracking-wider w-fit flex justify-center items-center gap-2 ${
|
|
||||||
className || ""
|
|
||||||
}`}
|
|
||||||
onClick={() => {
|
|
||||||
if (loading !== undefined && !loading && onClick) onClick();
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<p className="font-bold">{label}</p>
|
|
||||||
</button>
|
|
||||||
);
|
|
||||||
}
|
|
|
@ -0,0 +1,39 @@
|
||||||
|
import Link from "next/link";
|
||||||
|
import React, { MouseEventHandler } from "react";
|
||||||
|
import { Trans } from "next-i18next";
|
||||||
|
|
||||||
|
type Props = {
|
||||||
|
toggleAnnouncementBar: MouseEventHandler<HTMLButtonElement>;
|
||||||
|
};
|
||||||
|
|
||||||
|
export default function Announcement({ toggleAnnouncementBar }: Props) {
|
||||||
|
const announcementId = localStorage.getItem("announcementId");
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="fixed left-0 right-0 bottom-20 sm:bottom-10 w-full p-5 z-30">
|
||||||
|
<div className="mx-auto w-full p-2 flex justify-between gap-2 items-center border border-primary shadow-xl rounded-xl bg-base-300 backdrop-blur-sm bg-opacity-80 max-w-md">
|
||||||
|
<i className="bi-stars text-2xl text-yellow-600 dark:text-yellow-500"></i>
|
||||||
|
<p className="w-4/5 text-center text-sm sm:text-base">
|
||||||
|
<Trans
|
||||||
|
i18nKey="new_version_announcement"
|
||||||
|
values={{ version: announcementId }}
|
||||||
|
components={[
|
||||||
|
<Link
|
||||||
|
href={`https://blog.linkwarden.app/releases/${announcementId}`}
|
||||||
|
target="_blank"
|
||||||
|
className="underline"
|
||||||
|
key={0}
|
||||||
|
/>,
|
||||||
|
]}
|
||||||
|
/>
|
||||||
|
</p>
|
||||||
|
<button
|
||||||
|
onClick={toggleAnnouncementBar}
|
||||||
|
className="btn btn-ghost btn-square btn-sm"
|
||||||
|
>
|
||||||
|
<i className="bi-x text-xl"></i>
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
|
@ -1,33 +0,0 @@
|
||||||
import Link from "next/link";
|
|
||||||
import React, { MouseEventHandler } from "react";
|
|
||||||
|
|
||||||
type Props = {
|
|
||||||
toggleAnnouncementBar: MouseEventHandler<HTMLButtonElement>;
|
|
||||||
};
|
|
||||||
|
|
||||||
export default function AnnouncementBar({ toggleAnnouncementBar }: Props) {
|
|
||||||
return (
|
|
||||||
<div className="fixed w-full z-20 bg-base-200">
|
|
||||||
<div className="w-full h-10 rainbow flex items-center justify-center">
|
|
||||||
<div className="w-fit font-semibold">
|
|
||||||
🎉️ See what's new in{" "}
|
|
||||||
<Link
|
|
||||||
href="https://blog.linkwarden.app/releases/v2.5"
|
|
||||||
target="_blank"
|
|
||||||
className="underline hover:opacity-50 duration-100"
|
|
||||||
>
|
|
||||||
Linkwarden v2.5
|
|
||||||
</Link>
|
|
||||||
! 🥳️
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<button
|
|
||||||
className="fixed right-3 hover:opacity-50 duration-100"
|
|
||||||
onClick={toggleAnnouncementBar}
|
|
||||||
>
|
|
||||||
<i className="bi-x text-neutral text-2xl"></i>
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
}
|
|
|
@ -8,19 +8,38 @@ type Props = {
|
||||||
onMount?: (rect: DOMRect) => void;
|
onMount?: (rect: DOMRect) => void;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
function getZIndex(element: HTMLElement): number {
|
||||||
|
let zIndex = 0;
|
||||||
|
while (element) {
|
||||||
|
const zIndexStyle = window
|
||||||
|
.getComputedStyle(element)
|
||||||
|
.getPropertyValue("z-index");
|
||||||
|
const numericZIndex = Number(zIndexStyle);
|
||||||
|
if (zIndexStyle !== "auto" && !isNaN(numericZIndex)) {
|
||||||
|
zIndex = numericZIndex;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
element = element.parentElement as HTMLElement;
|
||||||
|
}
|
||||||
|
return zIndex;
|
||||||
|
}
|
||||||
|
|
||||||
function useOutsideAlerter(
|
function useOutsideAlerter(
|
||||||
ref: RefObject<HTMLElement>,
|
ref: RefObject<HTMLElement>,
|
||||||
onClickOutside: Function
|
onClickOutside: Function
|
||||||
) {
|
) {
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
function handleClickOutside(event: Event) {
|
function handleClickOutside(event: MouseEvent) {
|
||||||
if (
|
const clickedElement = event.target as HTMLElement;
|
||||||
ref.current &&
|
if (ref.current && !ref.current.contains(clickedElement)) {
|
||||||
!ref.current.contains(event.target as HTMLInputElement)
|
const refZIndex = getZIndex(ref.current);
|
||||||
) {
|
const clickedZIndex = getZIndex(clickedElement);
|
||||||
|
if (clickedZIndex <= refZIndex) {
|
||||||
onClickOutside(event);
|
onClickOutside(event);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
document.addEventListener("mousedown", handleClickOutside);
|
document.addEventListener("mousedown", handleClickOutside);
|
||||||
return () => {
|
return () => {
|
||||||
document.removeEventListener("mousedown", handleClickOutside);
|
document.removeEventListener("mousedown", handleClickOutside);
|
||||||
|
|
|
@ -10,6 +10,7 @@ import EditCollectionModal from "./ModalContent/EditCollectionModal";
|
||||||
import EditCollectionSharingModal from "./ModalContent/EditCollectionSharingModal";
|
import EditCollectionSharingModal from "./ModalContent/EditCollectionSharingModal";
|
||||||
import DeleteCollectionModal from "./ModalContent/DeleteCollectionModal";
|
import DeleteCollectionModal from "./ModalContent/DeleteCollectionModal";
|
||||||
import { dropdownTriggerer } from "@/lib/client/utils";
|
import { dropdownTriggerer } from "@/lib/client/utils";
|
||||||
|
import { useTranslation } from "next-i18next";
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
collection: CollectionIncludingMembersAndLinkCount;
|
collection: CollectionIncludingMembersAndLinkCount;
|
||||||
|
@ -17,6 +18,7 @@ type Props = {
|
||||||
};
|
};
|
||||||
|
|
||||||
export default function CollectionCard({ collection, className }: Props) {
|
export default function CollectionCard({ collection, className }: Props) {
|
||||||
|
const { t } = useTranslation();
|
||||||
const { settings } = useLocalSettingsStore();
|
const { settings } = useLocalSettingsStore();
|
||||||
const { account } = useAccountStore();
|
const { account } = useAccountStore();
|
||||||
|
|
||||||
|
@ -78,8 +80,8 @@ export default function CollectionCard({ collection, className }: Props) {
|
||||||
>
|
>
|
||||||
<i className="bi-three-dots text-xl" title="More"></i>
|
<i className="bi-three-dots text-xl" title="More"></i>
|
||||||
</div>
|
</div>
|
||||||
<ul className="dropdown-content z-[1] menu shadow bg-base-200 border border-neutral-content rounded-box w-52 mt-1">
|
<ul className="dropdown-content z-[30] menu shadow bg-base-200 border border-neutral-content rounded-box w-52 mt-1">
|
||||||
{permissions === true ? (
|
{permissions === true && (
|
||||||
<li>
|
<li>
|
||||||
<div
|
<div
|
||||||
role="button"
|
role="button"
|
||||||
|
@ -89,10 +91,10 @@ export default function CollectionCard({ collection, className }: Props) {
|
||||||
setEditCollectionModal(true);
|
setEditCollectionModal(true);
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
Edit Collection Info
|
{t("edit_collection_info")}
|
||||||
</div>
|
</div>
|
||||||
</li>
|
</li>
|
||||||
) : undefined}
|
)}
|
||||||
<li>
|
<li>
|
||||||
<div
|
<div
|
||||||
role="button"
|
role="button"
|
||||||
|
@ -102,7 +104,9 @@ export default function CollectionCard({ collection, className }: Props) {
|
||||||
setEditCollectionSharingModal(true);
|
setEditCollectionSharingModal(true);
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{permissions === true ? "Share and Collaborate" : "View Team"}
|
{permissions === true
|
||||||
|
? t("share_and_collaborate")
|
||||||
|
: t("view_team")}
|
||||||
</div>
|
</div>
|
||||||
</li>
|
</li>
|
||||||
<li>
|
<li>
|
||||||
|
@ -114,7 +118,9 @@ export default function CollectionCard({ collection, className }: Props) {
|
||||||
setDeleteCollectionModal(true);
|
setDeleteCollectionModal(true);
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{permissions === true ? "Delete Collection" : "Leave Collection"}
|
{permissions === true
|
||||||
|
? t("delete_collection")
|
||||||
|
: t("leave_collection")}
|
||||||
</div>
|
</div>
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
|
|
|
@ -16,12 +16,14 @@ import { CollectionIncludingMembersAndLinkCount } from "@/types/global";
|
||||||
import { useRouter } from "next/router";
|
import { useRouter } from "next/router";
|
||||||
import useAccountStore from "@/store/account";
|
import useAccountStore from "@/store/account";
|
||||||
import toast from "react-hot-toast";
|
import toast from "react-hot-toast";
|
||||||
|
import { useTranslation } from "next-i18next";
|
||||||
|
|
||||||
interface ExtendedTreeItem extends TreeItem {
|
interface ExtendedTreeItem extends TreeItem {
|
||||||
data: Collection;
|
data: Collection;
|
||||||
}
|
}
|
||||||
|
|
||||||
const CollectionListing = () => {
|
const CollectionListing = () => {
|
||||||
|
const { t } = useTranslation();
|
||||||
const { collections, updateCollection } = useCollectionStore();
|
const { collections, updateCollection } = useCollectionStore();
|
||||||
const { account, updateAccount } = useAccountStore();
|
const { account, updateAccount } = useAccountStore();
|
||||||
|
|
||||||
|
@ -141,9 +143,7 @@ const CollectionListing = () => {
|
||||||
(destinationCollection?.ownerId !== account.id &&
|
(destinationCollection?.ownerId !== account.id &&
|
||||||
destination.parentId !== "root")
|
destination.parentId !== "root")
|
||||||
) {
|
) {
|
||||||
return toast.error(
|
return toast.error(t("cant_change_collection_you_dont_own"));
|
||||||
"You can't make change to a collection you don't own."
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
setTree((currentTree) => moveItemOnTree(currentTree!, source, destination));
|
setTree((currentTree) => moveItemOnTree(currentTree!, source, destination));
|
||||||
|
@ -201,7 +201,11 @@ const CollectionListing = () => {
|
||||||
};
|
};
|
||||||
|
|
||||||
if (!tree) {
|
if (!tree) {
|
||||||
return <></>;
|
return (
|
||||||
|
<p className="text-neutral text-xs font-semibold truncate w-full px-2 mt-5 mb-8">
|
||||||
|
{t("you_have_no_collections")}
|
||||||
|
</p>
|
||||||
|
);
|
||||||
} else
|
} else
|
||||||
return (
|
return (
|
||||||
<Tree
|
<Tree
|
||||||
|
|
|
@ -9,12 +9,12 @@ export default function dashboardItem({
|
||||||
}) {
|
}) {
|
||||||
return (
|
return (
|
||||||
<div className="flex items-center">
|
<div className="flex items-center">
|
||||||
<div className="w-[4.7rem] aspect-square flex justify-center items-center bg-primary/20 rounded-xl select-none">
|
<div className="w-[4rem] aspect-square flex justify-center items-center bg-primary/20 rounded-xl select-none">
|
||||||
<i className={`${icon} text-primary text-4xl drop-shadow`}></i>
|
<i className={`${icon} text-primary text-3xl drop-shadow`}></i>
|
||||||
</div>
|
</div>
|
||||||
<div className="ml-4 flex flex-col justify-center">
|
<div className="ml-4 flex flex-col justify-center">
|
||||||
<p className="text-neutral text-xs tracking-wider">{name}</p>
|
<p className="text-neutral text-xs tracking-wider">{name}</p>
|
||||||
<p className="font-thin text-6xl text-primary mt-0.5">{value}</p>
|
<p className="font-thin text-5xl text-primary mt-0.5">{value}</p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
import { dropdownTriggerer } from "@/lib/client/utils";
|
import { dropdownTriggerer } from "@/lib/client/utils";
|
||||||
import React from "react";
|
import React from "react";
|
||||||
|
import { useTranslation } from "next-i18next";
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
setSearchFilter: Function;
|
setSearchFilter: Function;
|
||||||
|
@ -16,6 +17,8 @@ export default function FilterSearchDropdown({
|
||||||
setSearchFilter,
|
setSearchFilter,
|
||||||
searchFilter,
|
searchFilter,
|
||||||
}: Props) {
|
}: Props) {
|
||||||
|
const { t } = useTranslation();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="dropdown dropdown-bottom dropdown-end">
|
<div className="dropdown dropdown-bottom dropdown-end">
|
||||||
<div
|
<div
|
||||||
|
@ -38,11 +41,11 @@ export default function FilterSearchDropdown({
|
||||||
name="search-filter-checkbox"
|
name="search-filter-checkbox"
|
||||||
className="checkbox checkbox-primary"
|
className="checkbox checkbox-primary"
|
||||||
checked={searchFilter.name}
|
checked={searchFilter.name}
|
||||||
onChange={() => {
|
onChange={() =>
|
||||||
setSearchFilter({ ...searchFilter, name: !searchFilter.name });
|
setSearchFilter({ ...searchFilter, name: !searchFilter.name })
|
||||||
}}
|
}
|
||||||
/>
|
/>
|
||||||
<span className="label-text">Name</span>
|
<span className="label-text">{t("name")}</span>
|
||||||
</label>
|
</label>
|
||||||
</li>
|
</li>
|
||||||
<li>
|
<li>
|
||||||
|
@ -56,11 +59,11 @@ export default function FilterSearchDropdown({
|
||||||
name="search-filter-checkbox"
|
name="search-filter-checkbox"
|
||||||
className="checkbox checkbox-primary"
|
className="checkbox checkbox-primary"
|
||||||
checked={searchFilter.url}
|
checked={searchFilter.url}
|
||||||
onChange={() => {
|
onChange={() =>
|
||||||
setSearchFilter({ ...searchFilter, url: !searchFilter.url });
|
setSearchFilter({ ...searchFilter, url: !searchFilter.url })
|
||||||
}}
|
}
|
||||||
/>
|
/>
|
||||||
<span className="label-text">Link</span>
|
<span className="label-text">{t("link")}</span>
|
||||||
</label>
|
</label>
|
||||||
</li>
|
</li>
|
||||||
<li>
|
<li>
|
||||||
|
@ -74,14 +77,14 @@ export default function FilterSearchDropdown({
|
||||||
name="search-filter-checkbox"
|
name="search-filter-checkbox"
|
||||||
className="checkbox checkbox-primary"
|
className="checkbox checkbox-primary"
|
||||||
checked={searchFilter.description}
|
checked={searchFilter.description}
|
||||||
onChange={() => {
|
onChange={() =>
|
||||||
setSearchFilter({
|
setSearchFilter({
|
||||||
...searchFilter,
|
...searchFilter,
|
||||||
description: !searchFilter.description,
|
description: !searchFilter.description,
|
||||||
});
|
})
|
||||||
}}
|
}
|
||||||
/>
|
/>
|
||||||
<span className="label-text">Description</span>
|
<span className="label-text">{t("description")}</span>
|
||||||
</label>
|
</label>
|
||||||
</li>
|
</li>
|
||||||
<li>
|
<li>
|
||||||
|
@ -95,14 +98,11 @@ export default function FilterSearchDropdown({
|
||||||
name="search-filter-checkbox"
|
name="search-filter-checkbox"
|
||||||
className="checkbox checkbox-primary"
|
className="checkbox checkbox-primary"
|
||||||
checked={searchFilter.tags}
|
checked={searchFilter.tags}
|
||||||
onChange={() => {
|
onChange={() =>
|
||||||
setSearchFilter({
|
setSearchFilter({ ...searchFilter, tags: !searchFilter.tags })
|
||||||
...searchFilter,
|
}
|
||||||
tags: !searchFilter.tags,
|
|
||||||
});
|
|
||||||
}}
|
|
||||||
/>
|
/>
|
||||||
<span className="label-text">Tags</span>
|
<span className="label-text">{t("tags")}</span>
|
||||||
</label>
|
</label>
|
||||||
</li>
|
</li>
|
||||||
<li>
|
<li>
|
||||||
|
@ -116,16 +116,17 @@ export default function FilterSearchDropdown({
|
||||||
name="search-filter-checkbox"
|
name="search-filter-checkbox"
|
||||||
className="checkbox checkbox-primary"
|
className="checkbox checkbox-primary"
|
||||||
checked={searchFilter.textContent}
|
checked={searchFilter.textContent}
|
||||||
onChange={() => {
|
onChange={() =>
|
||||||
setSearchFilter({
|
setSearchFilter({
|
||||||
...searchFilter,
|
...searchFilter,
|
||||||
textContent: !searchFilter.textContent,
|
textContent: !searchFilter.textContent,
|
||||||
});
|
})
|
||||||
}}
|
}
|
||||||
/>
|
/>
|
||||||
<span className="label-text">Full Content</span>
|
<span className="label-text">{t("full_content")}</span>
|
||||||
|
<div className="ml-auto badge badge-sm badge-neutral">
|
||||||
<div className="ml-auto badge badge-sm badge-neutral">Slower</div>
|
{t("slower")}
|
||||||
|
</div>
|
||||||
</label>
|
</label>
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
|
|
|
@ -0,0 +1,54 @@
|
||||||
|
import { isPWA } from "@/lib/client/utils";
|
||||||
|
import React, { useState } from "react";
|
||||||
|
import { Trans } from "next-i18next";
|
||||||
|
|
||||||
|
type Props = {};
|
||||||
|
|
||||||
|
const InstallApp = (props: Props) => {
|
||||||
|
const [isOpen, setIsOpen] = useState(true);
|
||||||
|
|
||||||
|
return isOpen && !isPWA() ? (
|
||||||
|
<div className="absolute left-0 right-0 bottom-10 w-full p-5">
|
||||||
|
<div className="mx-auto w-fit p-2 flex justify-between gap-2 items-center border border-neutral-content rounded-xl bg-base-300 backdrop-blur-md bg-opacity-80 max-w-md">
|
||||||
|
<svg
|
||||||
|
xmlns="http://www.w3.org/2000/svg"
|
||||||
|
className="w-8 h-8"
|
||||||
|
viewBox="0 0 50 50"
|
||||||
|
>
|
||||||
|
<path
|
||||||
|
fill="currentColor"
|
||||||
|
d="M30.3 13.7L25 8.4l-5.3 5.3l-1.4-1.4L25 5.6l6.7 6.7z"
|
||||||
|
/>
|
||||||
|
<path fill="currentColor" d="M24 7h2v21h-2z" />
|
||||||
|
<path
|
||||||
|
fill="currentColor"
|
||||||
|
d="M35 40H15c-1.7 0-3-1.3-3-3V19c0-1.7 1.3-3 3-3h7v2h-7c-.6 0-1 .4-1 1v18c0 .6.4 1 1 1h20c.6 0 1-.4 1-1V19c0-.6-.4-1-1-1h-7v-2h7c1.7 0 3 1.3 3 3v18c0 1.7-1.3 3-3 3"
|
||||||
|
/>
|
||||||
|
</svg>
|
||||||
|
<p className="w-4/5 text-[0.92rem]">
|
||||||
|
<Trans
|
||||||
|
i18nKey="pwa_install_prompt"
|
||||||
|
components={[
|
||||||
|
<a
|
||||||
|
className="underline"
|
||||||
|
target="_blank"
|
||||||
|
href="https://docs.linkwarden.app/getting-started/pwa-installation"
|
||||||
|
key={0}
|
||||||
|
/>,
|
||||||
|
]}
|
||||||
|
/>
|
||||||
|
</p>
|
||||||
|
<button
|
||||||
|
onClick={() => setIsOpen(false)}
|
||||||
|
className="btn btn-ghost btn-square btn-sm"
|
||||||
|
>
|
||||||
|
<i className="bi-x text-xl"></i>
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
) : (
|
||||||
|
<></>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default InstallApp;
|
|
@ -0,0 +1,203 @@
|
||||||
|
import React, { Dispatch, SetStateAction, useEffect, useState } from "react";
|
||||||
|
import FilterSearchDropdown from "./FilterSearchDropdown";
|
||||||
|
import SortDropdown from "./SortDropdown";
|
||||||
|
import ViewDropdown from "./ViewDropdown";
|
||||||
|
import { TFunction } from "i18next";
|
||||||
|
import BulkDeleteLinksModal from "./ModalContent/BulkDeleteLinksModal";
|
||||||
|
import BulkEditLinksModal from "./ModalContent/BulkEditLinksModal";
|
||||||
|
import toast from "react-hot-toast";
|
||||||
|
import useCollectivePermissions from "@/hooks/useCollectivePermissions";
|
||||||
|
import { useRouter } from "next/router";
|
||||||
|
import useLinkStore from "@/store/links";
|
||||||
|
import { Sort } from "@/types/global";
|
||||||
|
|
||||||
|
type Props = {
|
||||||
|
children: React.ReactNode;
|
||||||
|
t: TFunction<"translation", undefined>;
|
||||||
|
viewMode: string;
|
||||||
|
setViewMode: Dispatch<SetStateAction<string>>;
|
||||||
|
searchFilter?: {
|
||||||
|
name: boolean;
|
||||||
|
url: boolean;
|
||||||
|
description: boolean;
|
||||||
|
tags: boolean;
|
||||||
|
textContent: boolean;
|
||||||
|
};
|
||||||
|
setSearchFilter?: (filter: {
|
||||||
|
name: boolean;
|
||||||
|
url: boolean;
|
||||||
|
description: boolean;
|
||||||
|
tags: boolean;
|
||||||
|
textContent: boolean;
|
||||||
|
}) => void;
|
||||||
|
sortBy: Sort;
|
||||||
|
setSortBy: Dispatch<SetStateAction<Sort>>;
|
||||||
|
editMode?: boolean;
|
||||||
|
setEditMode?: (mode: boolean) => void;
|
||||||
|
};
|
||||||
|
|
||||||
|
const LinkListOptions = ({
|
||||||
|
children,
|
||||||
|
t,
|
||||||
|
viewMode,
|
||||||
|
setViewMode,
|
||||||
|
searchFilter,
|
||||||
|
setSearchFilter,
|
||||||
|
sortBy,
|
||||||
|
setSortBy,
|
||||||
|
editMode,
|
||||||
|
setEditMode,
|
||||||
|
}: Props) => {
|
||||||
|
const { links, selectedLinks, setSelectedLinks, deleteLinksById } =
|
||||||
|
useLinkStore();
|
||||||
|
|
||||||
|
const router = useRouter();
|
||||||
|
|
||||||
|
const [bulkDeleteLinksModal, setBulkDeleteLinksModal] = useState(false);
|
||||||
|
const [bulkEditLinksModal, setBulkEditLinksModal] = useState(false);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (editMode && setEditMode) return setEditMode(false);
|
||||||
|
}, [router]);
|
||||||
|
|
||||||
|
const collectivePermissions = useCollectivePermissions(
|
||||||
|
selectedLinks.map((link) => link.collectionId as number)
|
||||||
|
);
|
||||||
|
|
||||||
|
const handleSelectAll = () => {
|
||||||
|
if (selectedLinks.length === links.length) {
|
||||||
|
setSelectedLinks([]);
|
||||||
|
} else {
|
||||||
|
setSelectedLinks(links.map((link) => link));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const bulkDeleteLinks = async () => {
|
||||||
|
const load = toast.loading(t("deleting_selections"));
|
||||||
|
|
||||||
|
const response = await deleteLinksById(
|
||||||
|
selectedLinks.map((link) => link.id as number)
|
||||||
|
);
|
||||||
|
|
||||||
|
toast.dismiss(load);
|
||||||
|
|
||||||
|
response.ok &&
|
||||||
|
toast.success(
|
||||||
|
selectedLinks.length === 1
|
||||||
|
? t("link_deleted")
|
||||||
|
: t("links_deleted", { count: selectedLinks.length })
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<div className="flex justify-between items-center">
|
||||||
|
{children}
|
||||||
|
|
||||||
|
<div className="flex gap-3 items-center justify-end">
|
||||||
|
<div className="flex gap-2 items-center mt-2">
|
||||||
|
{links.length > 0 && editMode !== undefined && setEditMode && (
|
||||||
|
<div
|
||||||
|
role="button"
|
||||||
|
onClick={() => {
|
||||||
|
setEditMode(!editMode);
|
||||||
|
setSelectedLinks([]);
|
||||||
|
}}
|
||||||
|
className={`btn btn-square btn-sm btn-ghost ${
|
||||||
|
editMode
|
||||||
|
? "bg-primary/20 hover:bg-primary/20"
|
||||||
|
: "hover:bg-neutral/20"
|
||||||
|
}`}
|
||||||
|
>
|
||||||
|
<i className="bi-pencil-fill text-neutral text-xl"></i>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
{searchFilter && setSearchFilter && (
|
||||||
|
<FilterSearchDropdown
|
||||||
|
searchFilter={searchFilter}
|
||||||
|
setSearchFilter={setSearchFilter}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
<SortDropdown sortBy={sortBy} setSort={setSortBy} t={t} />
|
||||||
|
<ViewDropdown viewMode={viewMode} setViewMode={setViewMode} />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{editMode && links.length > 0 && (
|
||||||
|
<div className="w-full flex justify-between items-center min-h-[32px]">
|
||||||
|
{links.length > 0 && (
|
||||||
|
<div className="flex gap-3 ml-3">
|
||||||
|
<input
|
||||||
|
type="checkbox"
|
||||||
|
className="checkbox checkbox-primary"
|
||||||
|
onChange={() => handleSelectAll()}
|
||||||
|
checked={
|
||||||
|
selectedLinks.length === links.length && links.length > 0
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
{selectedLinks.length > 0 ? (
|
||||||
|
<span>
|
||||||
|
{selectedLinks.length === 1
|
||||||
|
? t("link_selected")
|
||||||
|
: t("links_selected", { count: selectedLinks.length })}
|
||||||
|
</span>
|
||||||
|
) : (
|
||||||
|
<span>{t("nothing_selected")}</span>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
<div className="flex gap-3">
|
||||||
|
<button
|
||||||
|
onClick={() => setBulkEditLinksModal(true)}
|
||||||
|
className="btn btn-sm btn-accent text-white w-fit ml-auto"
|
||||||
|
disabled={
|
||||||
|
selectedLinks.length === 0 ||
|
||||||
|
!(
|
||||||
|
collectivePermissions === true ||
|
||||||
|
collectivePermissions?.canUpdate
|
||||||
|
)
|
||||||
|
}
|
||||||
|
>
|
||||||
|
{t("edit")}
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
onClick={(e) => {
|
||||||
|
(document?.activeElement as HTMLElement)?.blur();
|
||||||
|
e.shiftKey ? bulkDeleteLinks() : setBulkDeleteLinksModal(true);
|
||||||
|
}}
|
||||||
|
className="btn btn-sm bg-red-500 hover:bg-red-400 text-white w-fit ml-auto"
|
||||||
|
disabled={
|
||||||
|
selectedLinks.length === 0 ||
|
||||||
|
!(
|
||||||
|
collectivePermissions === true ||
|
||||||
|
collectivePermissions?.canDelete
|
||||||
|
)
|
||||||
|
}
|
||||||
|
>
|
||||||
|
{t("delete")}
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{bulkDeleteLinksModal && (
|
||||||
|
<BulkDeleteLinksModal
|
||||||
|
onClose={() => {
|
||||||
|
setBulkDeleteLinksModal(false);
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{bulkEditLinksModal && (
|
||||||
|
<BulkEditLinksModal
|
||||||
|
onClose={() => {
|
||||||
|
setBulkEditLinksModal(false);
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default LinkListOptions;
|
|
@ -13,7 +13,7 @@ export default function CardView({
|
||||||
isLoading?: boolean;
|
isLoading?: boolean;
|
||||||
}) {
|
}) {
|
||||||
return (
|
return (
|
||||||
<div className="grid min-[1900px]:grid-cols-4 xl:grid-cols-3 sm:grid-cols-2 grid-cols-1 gap-5">
|
<div className="grid min-[1901px]:grid-cols-5 min-[1501px]:grid-cols-4 min-[881px]:grid-cols-3 min-[551px]:grid-cols-2 grid-cols-1 gap-5 pb-5">
|
||||||
{links.map((e, i) => {
|
{links.map((e, i) => {
|
||||||
return (
|
return (
|
||||||
<LinkCard
|
<LinkCard
|
||||||
|
|
|
@ -1,16 +0,0 @@
|
||||||
import LinkGrid from "@/components/LinkViews/LinkGrid";
|
|
||||||
import { LinkIncludingShortenedCollectionAndTags } from "@/types/global";
|
|
||||||
|
|
||||||
export default function GridView({
|
|
||||||
links,
|
|
||||||
}: {
|
|
||||||
links: LinkIncludingShortenedCollectionAndTags[];
|
|
||||||
}) {
|
|
||||||
return (
|
|
||||||
<div className="grid 2xl:grid-cols-3 xl:grid-cols-2 grid-cols-1 gap-5">
|
|
||||||
{links.map((e, i) => {
|
|
||||||
return <LinkGrid link={e} count={i} key={i} />;
|
|
||||||
})}
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
}
|
|
|
@ -0,0 +1,58 @@
|
||||||
|
import LinkMasonry from "@/components/LinkViews/LinkMasonry";
|
||||||
|
import { LinkIncludingShortenedCollectionAndTags } from "@/types/global";
|
||||||
|
import { GridLoader } from "react-spinners";
|
||||||
|
import Masonry from "react-masonry-css";
|
||||||
|
import resolveConfig from "tailwindcss/resolveConfig";
|
||||||
|
import tailwindConfig from "../../../tailwind.config.js";
|
||||||
|
import { useMemo } from "react";
|
||||||
|
|
||||||
|
export default function MasonryView({
|
||||||
|
links,
|
||||||
|
editMode,
|
||||||
|
isLoading,
|
||||||
|
}: {
|
||||||
|
links: LinkIncludingShortenedCollectionAndTags[];
|
||||||
|
editMode?: boolean;
|
||||||
|
isLoading?: boolean;
|
||||||
|
}) {
|
||||||
|
const fullConfig = resolveConfig(tailwindConfig as any);
|
||||||
|
|
||||||
|
const breakpointColumnsObj = useMemo(() => {
|
||||||
|
return {
|
||||||
|
default: 5,
|
||||||
|
1900: 4,
|
||||||
|
1500: 3,
|
||||||
|
880: 2,
|
||||||
|
550: 1,
|
||||||
|
};
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Masonry
|
||||||
|
breakpointCols={breakpointColumnsObj}
|
||||||
|
columnClassName="flex flex-col gap-5 !w-full"
|
||||||
|
className="grid min-[1901px]:grid-cols-5 min-[1501px]:grid-cols-4 min-[881px]:grid-cols-3 min-[551px]:grid-cols-2 grid-cols-1 gap-5 pb-5"
|
||||||
|
>
|
||||||
|
{links.map((e, i) => {
|
||||||
|
return (
|
||||||
|
<LinkMasonry
|
||||||
|
key={i}
|
||||||
|
link={e}
|
||||||
|
count={i}
|
||||||
|
flipDropdown={i === links.length - 1}
|
||||||
|
editMode={editMode}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
})}
|
||||||
|
|
||||||
|
{isLoading && links.length > 0 && (
|
||||||
|
<GridLoader
|
||||||
|
color="oklch(var(--p))"
|
||||||
|
loading={true}
|
||||||
|
size={20}
|
||||||
|
className="fixed top-5 right-5 opacity-50 z-30"
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
</Masonry>
|
||||||
|
);
|
||||||
|
}
|
|
@ -19,6 +19,8 @@ import { generateLinkHref } from "@/lib/client/generateLinkHref";
|
||||||
import useAccountStore from "@/store/account";
|
import useAccountStore from "@/store/account";
|
||||||
import usePermissions from "@/hooks/usePermissions";
|
import usePermissions from "@/hooks/usePermissions";
|
||||||
import toast from "react-hot-toast";
|
import toast from "react-hot-toast";
|
||||||
|
import LinkTypeBadge from "./LinkComponents/LinkTypeBadge";
|
||||||
|
import { useTranslation } from "next-i18next";
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
link: LinkIncludingShortenedCollectionAndTags;
|
link: LinkIncludingShortenedCollectionAndTags;
|
||||||
|
@ -29,6 +31,9 @@ type Props = {
|
||||||
};
|
};
|
||||||
|
|
||||||
export default function LinkCard({ link, flipDropdown, editMode }: Props) {
|
export default function LinkCard({ link, flipDropdown, editMode }: Props) {
|
||||||
|
const { t } = useTranslation();
|
||||||
|
|
||||||
|
const viewMode = localStorage.getItem("viewMode") || "card";
|
||||||
const { collections } = useCollectionStore();
|
const { collections } = useCollectionStore();
|
||||||
const { account } = useAccountStore();
|
const { account } = useAccountStore();
|
||||||
|
|
||||||
|
@ -53,7 +58,9 @@ export default function LinkCard({ link, flipDropdown, editMode }: Props) {
|
||||||
let shortendURL;
|
let shortendURL;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
shortendURL = new URL(link.url || "").host.toLowerCase();
|
if (link.url) {
|
||||||
|
shortendURL = new URL(link.url).host.toLowerCase();
|
||||||
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.log(error);
|
console.log(error);
|
||||||
}
|
}
|
||||||
|
@ -109,7 +116,6 @@ export default function LinkCard({ link, flipDropdown, editMode }: Props) {
|
||||||
editMode &&
|
editMode &&
|
||||||
(permissions === true || permissions?.canCreate || permissions?.canDelete);
|
(permissions === true || permissions?.canCreate || permissions?.canDelete);
|
||||||
|
|
||||||
// window.open ('www.yourdomain.com', '_ blank');
|
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
ref={ref}
|
ref={ref}
|
||||||
|
@ -118,18 +124,17 @@ export default function LinkCard({ link, flipDropdown, editMode }: Props) {
|
||||||
selectable
|
selectable
|
||||||
? handleCheckboxClick(link)
|
? handleCheckboxClick(link)
|
||||||
: editMode
|
: editMode
|
||||||
? toast.error(
|
? toast.error(t("link_selection_error"))
|
||||||
"You don't have permission to edit or delete this item."
|
|
||||||
)
|
|
||||||
: undefined
|
: undefined
|
||||||
}
|
}
|
||||||
>
|
>
|
||||||
<div
|
<div
|
||||||
className="rounded-2xl cursor-pointer"
|
className="rounded-2xl cursor-pointer h-full flex flex-col justify-between"
|
||||||
onClick={() =>
|
onClick={() =>
|
||||||
!editMode && window.open(generateLinkHref(link, account), "_blank")
|
!editMode && window.open(generateLinkHref(link, account), "_blank")
|
||||||
}
|
}
|
||||||
>
|
>
|
||||||
|
<div>
|
||||||
<div className="relative rounded-t-2xl h-40 overflow-hidden">
|
<div className="relative rounded-t-2xl h-40 overflow-hidden">
|
||||||
{previewAvailable(link) ? (
|
{previewAvailable(link) ? (
|
||||||
<Image
|
<Image
|
||||||
|
@ -138,7 +143,9 @@ export default function LinkCard({ link, flipDropdown, editMode }: Props) {
|
||||||
height={720}
|
height={720}
|
||||||
alt=""
|
alt=""
|
||||||
className="rounded-t-2xl select-none object-cover z-10 h-40 w-full shadow opacity-80 scale-105"
|
className="rounded-t-2xl select-none object-cover z-10 h-40 w-full shadow opacity-80 scale-105"
|
||||||
style={{ filter: "blur(2px)" }}
|
style={
|
||||||
|
link.type !== "image" ? { filter: "blur(1px)" } : undefined
|
||||||
|
}
|
||||||
draggable="false"
|
draggable="false"
|
||||||
onError={(e) => {
|
onError={(e) => {
|
||||||
const target = e.target as HTMLElement;
|
const target = e.target as HTMLElement;
|
||||||
|
@ -150,36 +157,29 @@ export default function LinkCard({ link, flipDropdown, editMode }: Props) {
|
||||||
) : (
|
) : (
|
||||||
<div className="duration-100 h-40 bg-opacity-80 skeleton rounded-none"></div>
|
<div className="duration-100 h-40 bg-opacity-80 skeleton rounded-none"></div>
|
||||||
)}
|
)}
|
||||||
|
{link.type !== "image" && (
|
||||||
<div className="absolute top-0 left-0 right-0 bottom-0 rounded-t-2xl flex items-center justify-center shadow rounded-md">
|
<div className="absolute top-0 left-0 right-0 bottom-0 rounded-t-2xl flex items-center justify-center shadow rounded-md">
|
||||||
<LinkIcon link={link} />
|
<LinkIcon link={link} />
|
||||||
</div>
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
<hr className="divider my-0 border-t border-neutral-content h-[1px]" />
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<hr className="divider my-0 last:hidden border-t border-neutral-content h-[1px]" />
|
<div className="flex flex-col justify-between h-full">
|
||||||
|
<div className="p-3 flex flex-col gap-2">
|
||||||
<div className="p-3 mt-1">
|
<p className="truncate w-full pr-9 text-primary text-sm">
|
||||||
<p className="truncate w-full pr-8 text-primary">
|
{unescapeString(link.name)}
|
||||||
{unescapeString(link.name || link.description) || link.url}
|
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<Link
|
<LinkTypeBadge link={link} />
|
||||||
href={link.url || ""}
|
|
||||||
target="_blank"
|
|
||||||
title={link.url || ""}
|
|
||||||
onClick={(e) => {
|
|
||||||
e.stopPropagation();
|
|
||||||
}}
|
|
||||||
className="flex gap-1 item-center select-none text-neutral mt-1 hover:opacity-70 duration-100"
|
|
||||||
>
|
|
||||||
<i className="bi-link-45deg text-lg mt-[0.10rem] leading-none"></i>
|
|
||||||
<p className="text-sm truncate">{shortendURL}</p>
|
|
||||||
</Link>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div>
|
||||||
<hr className="divider mt-2 mb-1 last:hidden border-t border-neutral-content h-[1px]" />
|
<hr className="divider mt-2 mb-1 last:hidden border-t border-neutral-content h-[1px]" />
|
||||||
|
|
||||||
<div className="flex justify-between text-xs text-neutral px-3 pb-1">
|
<div className="flex justify-between text-xs text-neutral px-3 pb-1 gap-2">
|
||||||
<div className="cursor-pointer w-fit">
|
<div className="cursor-pointer truncate">
|
||||||
{collection && (
|
{collection && (
|
||||||
<LinkCollection link={link} collection={collection} />
|
<LinkCollection link={link} collection={collection} />
|
||||||
)}
|
)}
|
||||||
|
@ -187,32 +187,38 @@ export default function LinkCard({ link, flipDropdown, editMode }: Props) {
|
||||||
<LinkDate link={link} />
|
<LinkDate link={link} />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
{showInfo && (
|
{showInfo && (
|
||||||
<div className="p-3 absolute z-30 top-0 left-0 right-0 bottom-0 bg-base-200 rounded-2xl fade-in overflow-y-auto">
|
<div className="p-3 absolute z-30 top-0 left-0 right-0 bottom-0 bg-base-200 rounded-[0.9rem] fade-in overflow-y-auto">
|
||||||
<div
|
<div
|
||||||
onClick={() => setShowInfo(!showInfo)}
|
onClick={() => setShowInfo(!showInfo)}
|
||||||
className=" float-right btn btn-sm outline-none btn-circle btn-ghost z-10"
|
className=" float-right btn btn-sm outline-none btn-circle btn-ghost z-10"
|
||||||
>
|
>
|
||||||
<i className="bi-x text-neutral text-2xl"></i>
|
<i className="bi-x text-neutral text-2xl"></i>
|
||||||
</div>
|
</div>
|
||||||
<p className="text-neutral text-lg font-semibold">Description</p>
|
<p className="text-neutral text-lg font-semibold">
|
||||||
|
{t("description")}
|
||||||
|
</p>
|
||||||
|
|
||||||
<hr className="divider my-2 last:hidden border-t border-neutral-content h-[1px]" />
|
<hr className="divider my-2 border-t border-neutral-content h-[1px]" />
|
||||||
<p>
|
<p>
|
||||||
{link.description ? (
|
{link.description ? (
|
||||||
unescapeString(link.description)
|
unescapeString(link.description)
|
||||||
) : (
|
) : (
|
||||||
<span className="text-neutral text-sm">
|
<span className="text-neutral text-sm">
|
||||||
No description provided.
|
{t("no_description")}
|
||||||
</span>
|
</span>
|
||||||
)}
|
)}
|
||||||
</p>
|
</p>
|
||||||
{link.tags[0] && (
|
{link.tags && link.tags[0] && (
|
||||||
<>
|
<>
|
||||||
<p className="text-neutral text-lg mt-3 font-semibold">Tags</p>
|
<p className="text-neutral text-lg mt-3 font-semibold">
|
||||||
|
{t("tags")}
|
||||||
|
</p>
|
||||||
|
|
||||||
<hr className="divider my-2 last:hidden border-t border-neutral-content h-[1px]" />
|
<hr className="divider my-2 border-t border-neutral-content h-[1px]" />
|
||||||
|
|
||||||
<div className="flex gap-3 items-center flex-wrap mt-2 truncate relative">
|
<div className="flex gap-3 items-center flex-wrap mt-2 truncate relative">
|
||||||
<div className="flex gap-1 items-center flex-wrap">
|
<div className="flex gap-1 items-center flex-wrap">
|
||||||
|
|
|
@ -11,6 +11,7 @@ import useLinkStore from "@/store/links";
|
||||||
import { toast } from "react-hot-toast";
|
import { toast } from "react-hot-toast";
|
||||||
import useAccountStore from "@/store/account";
|
import useAccountStore from "@/store/account";
|
||||||
import { dropdownTriggerer } from "@/lib/client/utils";
|
import { dropdownTriggerer } from "@/lib/client/utils";
|
||||||
|
import { useTranslation } from "next-i18next";
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
link: LinkIncludingShortenedCollectionAndTags;
|
link: LinkIncludingShortenedCollectionAndTags;
|
||||||
|
@ -18,6 +19,7 @@ type Props = {
|
||||||
position?: string;
|
position?: string;
|
||||||
toggleShowInfo?: () => void;
|
toggleShowInfo?: () => void;
|
||||||
linkInfo?: boolean;
|
linkInfo?: boolean;
|
||||||
|
alignToTop?: boolean;
|
||||||
flipDropdown?: boolean;
|
flipDropdown?: boolean;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -26,8 +28,11 @@ export default function LinkActions({
|
||||||
toggleShowInfo,
|
toggleShowInfo,
|
||||||
position,
|
position,
|
||||||
linkInfo,
|
linkInfo,
|
||||||
|
alignToTop,
|
||||||
flipDropdown,
|
flipDropdown,
|
||||||
}: Props) {
|
}: Props) {
|
||||||
|
const { t } = useTranslation();
|
||||||
|
|
||||||
const permissions = usePermissions(link.collection.id as number);
|
const permissions = usePermissions(link.collection.id as number);
|
||||||
|
|
||||||
const [editLinkModal, setEditLinkModal] = useState(false);
|
const [editLinkModal, setEditLinkModal] = useState(false);
|
||||||
|
@ -41,7 +46,7 @@ export default function LinkActions({
|
||||||
const pinLink = async () => {
|
const pinLink = async () => {
|
||||||
const isAlreadyPinned = link?.pinnedBy && link.pinnedBy[0];
|
const isAlreadyPinned = link?.pinnedBy && link.pinnedBy[0];
|
||||||
|
|
||||||
const load = toast.loading("Applying...");
|
const load = toast.loading(t("applying"));
|
||||||
|
|
||||||
const response = await updateLink({
|
const response = await updateLink({
|
||||||
...link,
|
...link,
|
||||||
|
@ -51,25 +56,25 @@ export default function LinkActions({
|
||||||
toast.dismiss(load);
|
toast.dismiss(load);
|
||||||
|
|
||||||
response.ok &&
|
response.ok &&
|
||||||
toast.success(`Link ${isAlreadyPinned ? "Unpinned!" : "Pinned!"}`);
|
toast.success(isAlreadyPinned ? t("link_unpinned") : t("link_unpinned"));
|
||||||
};
|
};
|
||||||
|
|
||||||
const deleteLink = async () => {
|
const deleteLink = async () => {
|
||||||
const load = toast.loading("Deleting...");
|
const load = toast.loading(t("deleting"));
|
||||||
|
|
||||||
const response = await removeLink(link.id as number);
|
const response = await removeLink(link.id as number);
|
||||||
|
|
||||||
toast.dismiss(load);
|
toast.dismiss(load);
|
||||||
|
|
||||||
response.ok && toast.success(`Link Deleted.`);
|
response.ok && toast.success(t("deleted"));
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<div
|
<div
|
||||||
className={`dropdown dropdown-left dropdown-end absolute ${
|
className={`dropdown dropdown-left absolute ${
|
||||||
position || "top-3 right-3"
|
position || "top-3 right-3"
|
||||||
} z-20`}
|
} ${alignToTop ? "" : "dropdown-end"} z-20`}
|
||||||
>
|
>
|
||||||
<div
|
<div
|
||||||
tabIndex={0}
|
tabIndex={0}
|
||||||
|
@ -79,7 +84,11 @@ export default function LinkActions({
|
||||||
>
|
>
|
||||||
<i title="More" className="bi-three-dots text-xl" />
|
<i title="More" className="bi-three-dots text-xl" />
|
||||||
</div>
|
</div>
|
||||||
<ul className="dropdown-content z-[20] menu shadow bg-base-200 border border-neutral-content rounded-box w-44 mr-1 translate-y-10">
|
<ul
|
||||||
|
className={`dropdown-content z-[20] menu shadow bg-base-200 border border-neutral-content rounded-box w-44 mr-1 ${
|
||||||
|
alignToTop ? "" : "translate-y-10"
|
||||||
|
}`}
|
||||||
|
>
|
||||||
<li>
|
<li>
|
||||||
<div
|
<div
|
||||||
role="button"
|
role="button"
|
||||||
|
@ -90,8 +99,8 @@ export default function LinkActions({
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{link?.pinnedBy && link.pinnedBy[0]
|
{link?.pinnedBy && link.pinnedBy[0]
|
||||||
? "Unpin"
|
? t("unpin")
|
||||||
: "Pin to Dashboard"}
|
: t("pin_to_dashboard")}
|
||||||
</div>
|
</div>
|
||||||
</li>
|
</li>
|
||||||
{linkInfo !== undefined && toggleShowInfo ? (
|
{linkInfo !== undefined && toggleShowInfo ? (
|
||||||
|
@ -104,7 +113,7 @@ export default function LinkActions({
|
||||||
toggleShowInfo();
|
toggleShowInfo();
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{!linkInfo ? "Show" : "Hide"} Link Details
|
{!linkInfo ? t("show_link_details") : t("hide_link_details")}
|
||||||
</div>
|
</div>
|
||||||
</li>
|
</li>
|
||||||
) : undefined}
|
) : undefined}
|
||||||
|
@ -118,10 +127,11 @@ export default function LinkActions({
|
||||||
setEditLinkModal(true);
|
setEditLinkModal(true);
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
Edit Link
|
{t("edit_link")}
|
||||||
</div>
|
</div>
|
||||||
</li>
|
</li>
|
||||||
) : undefined}
|
) : undefined}
|
||||||
|
{link.type === "url" && (
|
||||||
<li>
|
<li>
|
||||||
<div
|
<div
|
||||||
role="button"
|
role="button"
|
||||||
|
@ -131,9 +141,10 @@ export default function LinkActions({
|
||||||
setPreservedFormatsModal(true);
|
setPreservedFormatsModal(true);
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
Preserved Formats
|
{t("preserved_formats")}
|
||||||
</div>
|
</div>
|
||||||
</li>
|
</li>
|
||||||
|
)}
|
||||||
{permissions === true || permissions?.canDelete ? (
|
{permissions === true || permissions?.canDelete ? (
|
||||||
<li>
|
<li>
|
||||||
<div
|
<div
|
||||||
|
@ -144,7 +155,7 @@ export default function LinkActions({
|
||||||
e.shiftKey ? deleteLink() : setDeleteLinkModal(true);
|
e.shiftKey ? deleteLink() : setDeleteLinkModal(true);
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
Delete
|
{t("delete")}
|
||||||
</div>
|
</div>
|
||||||
</li>
|
</li>
|
||||||
) : undefined}
|
) : undefined}
|
||||||
|
|
|
@ -6,17 +6,16 @@ export default function LinkDate({
|
||||||
}: {
|
}: {
|
||||||
link: LinkIncludingShortenedCollectionAndTags;
|
link: LinkIncludingShortenedCollectionAndTags;
|
||||||
}) {
|
}) {
|
||||||
const formattedDate = new Date(link.createdAt as string).toLocaleString(
|
const formattedDate = new Date(
|
||||||
"en-US",
|
(link.importDate || link.createdAt) as string
|
||||||
{
|
).toLocaleString("en-US", {
|
||||||
year: "numeric",
|
year: "numeric",
|
||||||
month: "short",
|
month: "short",
|
||||||
day: "numeric",
|
day: "numeric",
|
||||||
}
|
});
|
||||||
);
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="flex items-center gap-1 text-neutral">
|
<div className="flex items-center gap-1 text-neutral min-w-fit">
|
||||||
<i className="bi-calendar3 text-lg"></i>
|
<i className="bi-calendar3 text-lg"></i>
|
||||||
<p>{formattedDate}</p>
|
<p>{formattedDate}</p>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -1,55 +0,0 @@
|
||||||
import { LinkIncludingShortenedCollectionAndTags } from "@/types/global";
|
|
||||||
import Image from "next/image";
|
|
||||||
import isValidUrl from "@/lib/shared/isValidUrl";
|
|
||||||
import React from "react";
|
|
||||||
import Link from "next/link";
|
|
||||||
|
|
||||||
export default function LinkGroupedIconURL({
|
|
||||||
link,
|
|
||||||
}: {
|
|
||||||
link: LinkIncludingShortenedCollectionAndTags;
|
|
||||||
}) {
|
|
||||||
const url =
|
|
||||||
isValidUrl(link.url || "") && link.url ? new URL(link.url) : undefined;
|
|
||||||
|
|
||||||
const [showFavicon, setShowFavicon] = React.useState<boolean>(true);
|
|
||||||
|
|
||||||
let shortendURL;
|
|
||||||
|
|
||||||
try {
|
|
||||||
shortendURL = new URL(link.url || "").host.toLowerCase();
|
|
||||||
} catch (error) {
|
|
||||||
console.log(error);
|
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
|
||||||
<Link href={link.url || ""} target="_blank">
|
|
||||||
<div className="bg-white shadow-md rounded-md border-[2px] flex gap-1 item-center justify-center border-white select-none z-10 max-w-full">
|
|
||||||
{link.url && url && showFavicon ? (
|
|
||||||
<Image
|
|
||||||
src={`https://t2.gstatic.com/faviconV2?client=SOCIAL&type=FAVICON&fallback_opts=TYPE,SIZE,URL&url=${link.url}&size=32`}
|
|
||||||
width={64}
|
|
||||||
height={64}
|
|
||||||
alt=""
|
|
||||||
className="w-5 h-5 rounded"
|
|
||||||
draggable="false"
|
|
||||||
onError={() => {
|
|
||||||
setShowFavicon(false);
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
) : showFavicon === false ? (
|
|
||||||
<i className="bi-link-45deg text-xl leading-none text-black"></i>
|
|
||||||
) : link.type === "pdf" ? (
|
|
||||||
<i className={`bi-file-earmark-pdf`}></i>
|
|
||||||
) : link.type === "image" ? (
|
|
||||||
<i className={`bi-file-earmark-image`}></i>
|
|
||||||
) : link.type === "singlefile" ? (
|
|
||||||
<i className={`bi-filetype-html`}></i>
|
|
||||||
) : undefined}
|
|
||||||
<p className="truncate bg-white text-black mr-1">
|
|
||||||
<p className="text-sm">{shortendURL}</p>
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
</Link>
|
|
||||||
);
|
|
||||||
}
|
|
|
@ -5,46 +5,94 @@ import React from "react";
|
||||||
|
|
||||||
export default function LinkIcon({
|
export default function LinkIcon({
|
||||||
link,
|
link,
|
||||||
width,
|
className,
|
||||||
|
size,
|
||||||
}: {
|
}: {
|
||||||
link: LinkIncludingShortenedCollectionAndTags;
|
link: LinkIncludingShortenedCollectionAndTags;
|
||||||
width?: string;
|
className?: string;
|
||||||
|
size?: "small" | "medium";
|
||||||
}) {
|
}) {
|
||||||
|
let iconClasses: string =
|
||||||
|
"bg-white shadow rounded-md border-[2px] flex item-center justify-center border-white select-none z-10 " +
|
||||||
|
(className || "");
|
||||||
|
|
||||||
|
let dimension;
|
||||||
|
|
||||||
|
switch (size) {
|
||||||
|
case "small":
|
||||||
|
dimension = " w-8 h-8";
|
||||||
|
break;
|
||||||
|
case "medium":
|
||||||
|
dimension = " w-12 h-12";
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
size = "medium";
|
||||||
|
dimension = " w-12 h-12";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
const url =
|
const url =
|
||||||
isValidUrl(link.url || "") && link.url ? new URL(link.url) : undefined;
|
isValidUrl(link.url || "") && link.url ? new URL(link.url) : undefined;
|
||||||
|
|
||||||
const iconClasses: string =
|
|
||||||
"bg-white shadow rounded-md border-[2px] flex item-center justify-center border-white select-none z-10" +
|
|
||||||
" " +
|
|
||||||
(width || "w-12");
|
|
||||||
|
|
||||||
const [showFavicon, setShowFavicon] = React.useState<boolean>(true);
|
const [showFavicon, setShowFavicon] = React.useState<boolean>(true);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
{link.url && url && showFavicon ? (
|
{link.type === "url" && url ? (
|
||||||
|
showFavicon ? (
|
||||||
<Image
|
<Image
|
||||||
src={`https://t2.gstatic.com/faviconV2?client=SOCIAL&type=FAVICON&fallback_opts=TYPE,SIZE,URL&url=${link.url}&size=32`}
|
src={`https://t2.gstatic.com/faviconV2?client=SOCIAL&type=FAVICON&fallback_opts=TYPE,SIZE,URL&url=${link.url}&size=32`}
|
||||||
width={64}
|
width={64}
|
||||||
height={64}
|
height={64}
|
||||||
alt=""
|
alt=""
|
||||||
className={iconClasses}
|
className={iconClasses + dimension}
|
||||||
draggable="false"
|
draggable="false"
|
||||||
onError={() => {
|
onError={() => {
|
||||||
setShowFavicon(false);
|
setShowFavicon(false);
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
) : showFavicon === false ? (
|
) : (
|
||||||
<div className={iconClasses}>
|
<LinkPlaceholderIcon
|
||||||
<i className="bi-link-45deg text-4xl text-black"></i>
|
iconClasses={iconClasses + dimension}
|
||||||
</div>
|
size={size}
|
||||||
|
icon="bi-link-45deg"
|
||||||
|
/>
|
||||||
|
)
|
||||||
) : link.type === "pdf" ? (
|
) : link.type === "pdf" ? (
|
||||||
<i className={`bi-file-earmark-pdf ${iconClasses}`}></i>
|
<LinkPlaceholderIcon
|
||||||
|
iconClasses={iconClasses + dimension}
|
||||||
|
size={size}
|
||||||
|
icon="bi-file-earmark-pdf"
|
||||||
|
/>
|
||||||
) : link.type === "image" ? (
|
) : link.type === "image" ? (
|
||||||
<i className={`bi-file-earmark-image ${iconClasses}`}></i>
|
<LinkPlaceholderIcon
|
||||||
|
iconClasses={iconClasses + dimension}
|
||||||
|
size={size}
|
||||||
|
icon="bi-file-earmark-image"
|
||||||
|
/>
|
||||||
) : link.type === "singlefile" ? (
|
) : link.type === "singlefile" ? (
|
||||||
<i className={`bi-filetype-html ${iconClasses}`}></i>
|
<i className={`bi-filetype-html ${iconClasses}`}></i>
|
||||||
) : undefined}
|
) : undefined}
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const LinkPlaceholderIcon = ({
|
||||||
|
iconClasses,
|
||||||
|
size,
|
||||||
|
icon,
|
||||||
|
}: {
|
||||||
|
iconClasses: string;
|
||||||
|
size?: "small" | "medium";
|
||||||
|
icon: string;
|
||||||
|
}) => {
|
||||||
|
return (
|
||||||
|
<div
|
||||||
|
className={`${
|
||||||
|
size === "small" ? "text-2xl" : "text-4xl"
|
||||||
|
} text-black aspect-square ${iconClasses}`}
|
||||||
|
>
|
||||||
|
<i className={`${icon} m-auto`}></i>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
|
@ -0,0 +1,36 @@
|
||||||
|
import { LinkIncludingShortenedCollectionAndTags } from "@/types/global";
|
||||||
|
import Link from "next/link";
|
||||||
|
import React from "react";
|
||||||
|
|
||||||
|
export default function LinkTypeBadge({
|
||||||
|
link,
|
||||||
|
}: {
|
||||||
|
link: LinkIncludingShortenedCollectionAndTags;
|
||||||
|
}) {
|
||||||
|
let shortendURL;
|
||||||
|
|
||||||
|
if (link.type === "url" && link.url) {
|
||||||
|
try {
|
||||||
|
shortendURL = new URL(link.url).host.toLowerCase();
|
||||||
|
} catch (error) {
|
||||||
|
console.log(error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return link.url && shortendURL ? (
|
||||||
|
<Link
|
||||||
|
href={link.url || ""}
|
||||||
|
target="_blank"
|
||||||
|
title={link.url || ""}
|
||||||
|
onClick={(e) => {
|
||||||
|
e.stopPropagation();
|
||||||
|
}}
|
||||||
|
className="flex gap-1 item-center select-none text-neutral hover:opacity-70 duration-100 max-w-full w-fit"
|
||||||
|
>
|
||||||
|
<i className="bi-link-45deg text-lg leading-none"></i>
|
||||||
|
<p className="text-xs truncate">{shortendURL}</p>
|
||||||
|
</Link>
|
||||||
|
) : (
|
||||||
|
<div className="badge badge-primary badge-sm select-none">{link.type}</div>
|
||||||
|
);
|
||||||
|
}
|
|
@ -1,111 +0,0 @@
|
||||||
import {
|
|
||||||
CollectionIncludingMembersAndLinkCount,
|
|
||||||
LinkIncludingShortenedCollectionAndTags,
|
|
||||||
} from "@/types/global";
|
|
||||||
import { useEffect, useState } from "react";
|
|
||||||
import useLinkStore from "@/store/links";
|
|
||||||
import useCollectionStore from "@/store/collections";
|
|
||||||
import unescapeString from "@/lib/client/unescapeString";
|
|
||||||
import LinkActions from "@/components/LinkViews/LinkComponents/LinkActions";
|
|
||||||
import LinkDate from "@/components/LinkViews/LinkComponents/LinkDate";
|
|
||||||
import LinkCollection from "@/components/LinkViews/LinkComponents/LinkCollection";
|
|
||||||
import LinkIcon from "@/components/LinkViews/LinkComponents/LinkIcon";
|
|
||||||
import Link from "next/link";
|
|
||||||
|
|
||||||
type Props = {
|
|
||||||
link: LinkIncludingShortenedCollectionAndTags;
|
|
||||||
count: number;
|
|
||||||
className?: string;
|
|
||||||
};
|
|
||||||
|
|
||||||
export default function LinkGrid({ link }: Props) {
|
|
||||||
const { collections } = useCollectionStore();
|
|
||||||
|
|
||||||
const { links } = useLinkStore();
|
|
||||||
|
|
||||||
let shortendURL;
|
|
||||||
|
|
||||||
try {
|
|
||||||
shortendURL = new URL(link.url || "").host.toLowerCase();
|
|
||||||
} catch (error) {
|
|
||||||
console.log(error);
|
|
||||||
}
|
|
||||||
|
|
||||||
const [collection, setCollection] =
|
|
||||||
useState<CollectionIncludingMembersAndLinkCount>(
|
|
||||||
collections.find(
|
|
||||||
(e) => e.id === link.collection.id
|
|
||||||
) as CollectionIncludingMembersAndLinkCount
|
|
||||||
);
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
setCollection(
|
|
||||||
collections.find(
|
|
||||||
(e) => e.id === link.collection.id
|
|
||||||
) as CollectionIncludingMembersAndLinkCount
|
|
||||||
);
|
|
||||||
}, [collections, links]);
|
|
||||||
|
|
||||||
return (
|
|
||||||
<div className="border border-solid border-neutral-content bg-base-200 shadow-md hover:shadow-none duration-100 rounded-2xl relative p-3">
|
|
||||||
<div
|
|
||||||
onClick={() => link.url && window.open(link.url || "", "_blank")}
|
|
||||||
className="cursor-pointer"
|
|
||||||
>
|
|
||||||
<LinkIcon link={link} width="w-12 mb-3" />
|
|
||||||
<p className="truncate w-full">
|
|
||||||
{unescapeString(link.name || link.description) || link.url}
|
|
||||||
</p>
|
|
||||||
|
|
||||||
<div className="mt-1 flex flex-col text-xs text-neutral">
|
|
||||||
<div className="flex items-center gap-2">
|
|
||||||
<LinkCollection link={link} collection={collection} />
|
|
||||||
·
|
|
||||||
{link.url ? (
|
|
||||||
<div
|
|
||||||
onClick={(e) => {
|
|
||||||
e.preventDefault();
|
|
||||||
window.open(link.url || "", "_blank");
|
|
||||||
}}
|
|
||||||
className="flex items-center hover:opacity-60 cursor-pointer duration-100"
|
|
||||||
>
|
|
||||||
<p className="truncate">{shortendURL}</p>
|
|
||||||
</div>
|
|
||||||
) : (
|
|
||||||
<div className="badge badge-primary badge-sm my-1">
|
|
||||||
{link.type}
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
<LinkDate link={link} />
|
|
||||||
</div>
|
|
||||||
<p className="truncate">{unescapeString(link.description)}</p>
|
|
||||||
{link.tags[0] ? (
|
|
||||||
<div className="flex gap-3 items-center flex-wrap mt-2 truncate relative">
|
|
||||||
<div className="flex gap-1 items-center flex-wrap">
|
|
||||||
{link.tags.map((e, i) => (
|
|
||||||
<Link
|
|
||||||
href={"/tags/" + e.id}
|
|
||||||
key={i}
|
|
||||||
onClick={(e) => {
|
|
||||||
e.stopPropagation();
|
|
||||||
}}
|
|
||||||
className="btn btn-xs btn-ghost truncate max-w-[19rem]"
|
|
||||||
>
|
|
||||||
#{e.name}
|
|
||||||
</Link>
|
|
||||||
))}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
) : undefined}
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<LinkActions
|
|
||||||
toggleShowInfo={() => {}}
|
|
||||||
linkInfo={false}
|
|
||||||
link={link}
|
|
||||||
collection={collection}
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
}
|
|
|
@ -10,12 +10,13 @@ import LinkActions from "@/components/LinkViews/LinkComponents/LinkActions";
|
||||||
import LinkDate from "@/components/LinkViews/LinkComponents/LinkDate";
|
import LinkDate from "@/components/LinkViews/LinkComponents/LinkDate";
|
||||||
import LinkCollection from "@/components/LinkViews/LinkComponents/LinkCollection";
|
import LinkCollection from "@/components/LinkViews/LinkComponents/LinkCollection";
|
||||||
import LinkIcon from "@/components/LinkViews/LinkComponents/LinkIcon";
|
import LinkIcon from "@/components/LinkViews/LinkComponents/LinkIcon";
|
||||||
import Link from "next/link";
|
|
||||||
import { isPWA } from "@/lib/client/utils";
|
import { isPWA } from "@/lib/client/utils";
|
||||||
import { generateLinkHref } from "@/lib/client/generateLinkHref";
|
import { generateLinkHref } from "@/lib/client/generateLinkHref";
|
||||||
import useAccountStore from "@/store/account";
|
import useAccountStore from "@/store/account";
|
||||||
import usePermissions from "@/hooks/usePermissions";
|
import usePermissions from "@/hooks/usePermissions";
|
||||||
import toast from "react-hot-toast";
|
import toast from "react-hot-toast";
|
||||||
|
import LinkTypeBadge from "./LinkComponents/LinkTypeBadge";
|
||||||
|
import { useTranslation } from "next-i18next";
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
link: LinkIncludingShortenedCollectionAndTags;
|
link: LinkIncludingShortenedCollectionAndTags;
|
||||||
|
@ -30,6 +31,8 @@ export default function LinkCardCompact({
|
||||||
flipDropdown,
|
flipDropdown,
|
||||||
editMode,
|
editMode,
|
||||||
}: Props) {
|
}: Props) {
|
||||||
|
const { t } = useTranslation();
|
||||||
|
|
||||||
const { collections } = useCollectionStore();
|
const { collections } = useCollectionStore();
|
||||||
const { account } = useAccountStore();
|
const { account } = useAccountStore();
|
||||||
const { links, setSelectedLinks, selectedLinks } = useLinkStore();
|
const { links, setSelectedLinks, selectedLinks } = useLinkStore();
|
||||||
|
@ -56,14 +59,6 @@ export default function LinkCardCompact({
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
let shortendURL;
|
|
||||||
|
|
||||||
try {
|
|
||||||
shortendURL = new URL(link.url || "").host.toLowerCase();
|
|
||||||
} catch (error) {
|
|
||||||
console.log(error);
|
|
||||||
}
|
|
||||||
|
|
||||||
const [collection, setCollection] =
|
const [collection, setCollection] =
|
||||||
useState<CollectionIncludingMembersAndLinkCount>(
|
useState<CollectionIncludingMembersAndLinkCount>(
|
||||||
collections.find(
|
collections.find(
|
||||||
|
@ -98,14 +93,12 @@ export default function LinkCardCompact({
|
||||||
<div
|
<div
|
||||||
className={`${selectedStyle} border relative items-center flex ${
|
className={`${selectedStyle} border relative items-center flex ${
|
||||||
!showInfo && !isPWA() ? "hover:bg-base-300 p-3" : "py-3"
|
!showInfo && !isPWA() ? "hover:bg-base-300 p-3" : "py-3"
|
||||||
} duration-200 rounded-lg`}
|
} duration-200 rounded-lg w-full`}
|
||||||
onClick={() =>
|
onClick={() =>
|
||||||
selectable
|
selectable
|
||||||
? handleCheckboxClick(link)
|
? handleCheckboxClick(link)
|
||||||
: editMode
|
: editMode
|
||||||
? toast.error(
|
? toast.error(t("link_selection_error"))
|
||||||
"You don't have permission to edit or delete this item."
|
|
||||||
)
|
|
||||||
: undefined
|
: undefined
|
||||||
}
|
}
|
||||||
>
|
>
|
||||||
|
@ -124,43 +117,32 @@ export default function LinkCardCompact({
|
||||||
/>
|
/>
|
||||||
)} */}
|
)} */}
|
||||||
<div
|
<div
|
||||||
className="flex items-center cursor-pointer"
|
className="flex items-center cursor-pointer w-full"
|
||||||
onClick={() =>
|
onClick={() =>
|
||||||
!editMode && window.open(generateLinkHref(link, account), "_blank")
|
!editMode && window.open(generateLinkHref(link, account), "_blank")
|
||||||
}
|
}
|
||||||
>
|
>
|
||||||
<div className="shrink-0">
|
<div className="shrink-0">
|
||||||
<LinkIcon link={link} width="sm:w-12 w-8 mt-1 sm:mt-0" />
|
<LinkIcon link={link} className="w-12 h-12 text-4xl" />
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="w-[calc(100%-56px)] ml-2">
|
<div className="w-[calc(100%-56px)] ml-2">
|
||||||
<p className="line-clamp-1 mr-8 text-primary select-none">
|
<p className="line-clamp-1 mr-8 text-primary select-none">
|
||||||
{unescapeString(link.name || link.description) || link.url}
|
{link.name ? (
|
||||||
|
unescapeString(link.name)
|
||||||
|
) : (
|
||||||
|
<div className="mt-2">
|
||||||
|
<LinkTypeBadge link={link} />
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<div className="mt-1 flex flex-col sm:flex-row sm:items-center gap-2 text-xs text-neutral">
|
<div className="mt-1 flex flex-col sm:flex-row sm:items-center gap-2 text-xs text-neutral">
|
||||||
<div className="flex items-center gap-x-3 w-fit text-neutral flex-wrap">
|
<div className="flex items-center gap-x-3 text-neutral flex-wrap">
|
||||||
{collection ? (
|
{collection ? (
|
||||||
<LinkCollection link={link} collection={collection} />
|
<LinkCollection link={link} collection={collection} />
|
||||||
) : undefined}
|
) : undefined}
|
||||||
{link.url ? (
|
{link.name && <LinkTypeBadge link={link} />}
|
||||||
<Link
|
|
||||||
href={link.url || ""}
|
|
||||||
target="_blank"
|
|
||||||
title={link.url || ""}
|
|
||||||
onClick={(e) => {
|
|
||||||
e.stopPropagation();
|
|
||||||
}}
|
|
||||||
className="flex gap-1 item-center select-none text-neutral mt-1 hover:opacity-70 duration-100"
|
|
||||||
>
|
|
||||||
<i className="bi-link-45deg text-lg mt-[0.1rem] leading-none"></i>
|
|
||||||
<p className="text-sm truncate">{shortendURL}</p>
|
|
||||||
</Link>
|
|
||||||
) : (
|
|
||||||
<div className="badge badge-primary badge-sm my-1 select-none">
|
|
||||||
{link.type}
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
<LinkDate link={link} />
|
<LinkDate link={link} />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -0,0 +1,271 @@
|
||||||
|
import {
|
||||||
|
ArchivedFormat,
|
||||||
|
CollectionIncludingMembersAndLinkCount,
|
||||||
|
LinkIncludingShortenedCollectionAndTags,
|
||||||
|
} from "@/types/global";
|
||||||
|
import { useEffect, useRef, useState } from "react";
|
||||||
|
import useLinkStore from "@/store/links";
|
||||||
|
import useCollectionStore from "@/store/collections";
|
||||||
|
import unescapeString from "@/lib/client/unescapeString";
|
||||||
|
import LinkActions from "@/components/LinkViews/LinkComponents/LinkActions";
|
||||||
|
import LinkDate from "@/components/LinkViews/LinkComponents/LinkDate";
|
||||||
|
import LinkCollection from "@/components/LinkViews/LinkComponents/LinkCollection";
|
||||||
|
import Image from "next/image";
|
||||||
|
import { previewAvailable } from "@/lib/shared/getArchiveValidity";
|
||||||
|
import Link from "next/link";
|
||||||
|
import LinkIcon from "./LinkComponents/LinkIcon";
|
||||||
|
import useOnScreen from "@/hooks/useOnScreen";
|
||||||
|
import { generateLinkHref } from "@/lib/client/generateLinkHref";
|
||||||
|
import useAccountStore from "@/store/account";
|
||||||
|
import usePermissions from "@/hooks/usePermissions";
|
||||||
|
import toast from "react-hot-toast";
|
||||||
|
import LinkTypeBadge from "./LinkComponents/LinkTypeBadge";
|
||||||
|
import { useTranslation } from "next-i18next";
|
||||||
|
|
||||||
|
type Props = {
|
||||||
|
link: LinkIncludingShortenedCollectionAndTags;
|
||||||
|
count: number;
|
||||||
|
className?: string;
|
||||||
|
flipDropdown?: boolean;
|
||||||
|
editMode?: boolean;
|
||||||
|
};
|
||||||
|
|
||||||
|
export default function LinkMasonry({ link, flipDropdown, editMode }: Props) {
|
||||||
|
const { t } = useTranslation();
|
||||||
|
|
||||||
|
const { collections } = useCollectionStore();
|
||||||
|
const { account } = useAccountStore();
|
||||||
|
|
||||||
|
const { links, getLink, setSelectedLinks, selectedLinks } = useLinkStore();
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (!editMode) {
|
||||||
|
setSelectedLinks([]);
|
||||||
|
}
|
||||||
|
}, [editMode]);
|
||||||
|
|
||||||
|
const handleCheckboxClick = (
|
||||||
|
link: LinkIncludingShortenedCollectionAndTags
|
||||||
|
) => {
|
||||||
|
if (selectedLinks.includes(link)) {
|
||||||
|
setSelectedLinks(selectedLinks.filter((e) => e !== link));
|
||||||
|
} else {
|
||||||
|
setSelectedLinks([...selectedLinks, link]);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
let shortendURL;
|
||||||
|
|
||||||
|
try {
|
||||||
|
if (link.url) {
|
||||||
|
shortendURL = new URL(link.url).host.toLowerCase();
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.log(error);
|
||||||
|
}
|
||||||
|
|
||||||
|
const [collection, setCollection] =
|
||||||
|
useState<CollectionIncludingMembersAndLinkCount>(
|
||||||
|
collections.find(
|
||||||
|
(e) => e.id === link.collection.id
|
||||||
|
) as CollectionIncludingMembersAndLinkCount
|
||||||
|
);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
setCollection(
|
||||||
|
collections.find(
|
||||||
|
(e) => e.id === link.collection.id
|
||||||
|
) as CollectionIncludingMembersAndLinkCount
|
||||||
|
);
|
||||||
|
}, [collections, links]);
|
||||||
|
|
||||||
|
const ref = useRef<HTMLDivElement>(null);
|
||||||
|
const isVisible = useOnScreen(ref);
|
||||||
|
const permissions = usePermissions(collection?.id as number);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
let interval: any;
|
||||||
|
|
||||||
|
if (
|
||||||
|
isVisible &&
|
||||||
|
!link.preview?.startsWith("archives") &&
|
||||||
|
link.preview !== "unavailable"
|
||||||
|
) {
|
||||||
|
interval = setInterval(async () => {
|
||||||
|
getLink(link.id as number);
|
||||||
|
}, 5000);
|
||||||
|
}
|
||||||
|
|
||||||
|
return () => {
|
||||||
|
if (interval) {
|
||||||
|
clearInterval(interval);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}, [isVisible, link.preview]);
|
||||||
|
|
||||||
|
const [showInfo, setShowInfo] = useState(false);
|
||||||
|
|
||||||
|
const selectedStyle = selectedLinks.some(
|
||||||
|
(selectedLink) => selectedLink.id === link.id
|
||||||
|
)
|
||||||
|
? "border-primary bg-base-300"
|
||||||
|
: "border-neutral-content";
|
||||||
|
|
||||||
|
const selectable =
|
||||||
|
editMode &&
|
||||||
|
(permissions === true || permissions?.canCreate || permissions?.canDelete);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div
|
||||||
|
ref={ref}
|
||||||
|
className={`${selectedStyle} border border-solid border-neutral-content bg-base-200 shadow-md hover:shadow-none duration-100 rounded-2xl relative`}
|
||||||
|
onClick={() =>
|
||||||
|
selectable
|
||||||
|
? handleCheckboxClick(link)
|
||||||
|
: editMode
|
||||||
|
? toast.error(t("link_selection_error"))
|
||||||
|
: undefined
|
||||||
|
}
|
||||||
|
>
|
||||||
|
<div
|
||||||
|
className="rounded-2xl cursor-pointer"
|
||||||
|
onClick={() =>
|
||||||
|
!editMode && window.open(generateLinkHref(link, account), "_blank")
|
||||||
|
}
|
||||||
|
>
|
||||||
|
<div className="relative rounded-t-2xl overflow-hidden">
|
||||||
|
{previewAvailable(link) ? (
|
||||||
|
<Image
|
||||||
|
src={`/api/v1/archives/${link.id}?format=${ArchivedFormat.jpeg}&preview=true`}
|
||||||
|
width={1280}
|
||||||
|
height={720}
|
||||||
|
alt=""
|
||||||
|
className="rounded-t-2xl select-none object-cover z-10 h-40 w-full shadow opacity-80 scale-105"
|
||||||
|
style={
|
||||||
|
link.type !== "image" ? { filter: "blur(1px)" } : undefined
|
||||||
|
}
|
||||||
|
draggable="false"
|
||||||
|
onError={(e) => {
|
||||||
|
const target = e.target as HTMLElement;
|
||||||
|
target.style.display = "none";
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
) : link.preview === "unavailable" ? null : (
|
||||||
|
<div className="duration-100 h-40 bg-opacity-80 skeleton rounded-none"></div>
|
||||||
|
)}
|
||||||
|
{link.type !== "image" && (
|
||||||
|
<div className="absolute top-0 left-0 right-0 bottom-0 rounded-t-2xl flex items-center justify-center shadow rounded-md">
|
||||||
|
<LinkIcon link={link} />
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{link.preview !== "unavailable" && (
|
||||||
|
<hr className="divider my-0 last:hidden border-t border-neutral-content h-[1px]" />
|
||||||
|
)}
|
||||||
|
|
||||||
|
<div className="p-3 flex flex-col gap-2">
|
||||||
|
<p className="hyphens-auto w-full pr-9 text-primary text-sm">
|
||||||
|
{unescapeString(link.name)}
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<LinkTypeBadge link={link} />
|
||||||
|
|
||||||
|
{link.description && (
|
||||||
|
<p className="hyphens-auto text-sm">
|
||||||
|
{unescapeString(link.description)}
|
||||||
|
</p>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{link.tags[0] && (
|
||||||
|
<div className="flex gap-1 items-center flex-wrap">
|
||||||
|
{link.tags.map((e, i) => (
|
||||||
|
<Link
|
||||||
|
href={"/tags/" + e.id}
|
||||||
|
key={i}
|
||||||
|
onClick={(e) => {
|
||||||
|
e.stopPropagation();
|
||||||
|
}}
|
||||||
|
className="btn btn-xs btn-ghost truncate max-w-[19rem]"
|
||||||
|
>
|
||||||
|
#{e.name}
|
||||||
|
</Link>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<hr className="divider mt-2 mb-1 last:hidden border-t border-neutral-content h-[1px]" />
|
||||||
|
|
||||||
|
<div className="flex flex-wrap justify-between text-xs text-neutral px-3 pb-1 w-full gap-x-2">
|
||||||
|
{collection && <LinkCollection link={link} collection={collection} />}
|
||||||
|
<LinkDate link={link} />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{showInfo && (
|
||||||
|
<div className="p-3 absolute z-30 top-0 left-0 right-0 bottom-0 bg-base-200 rounded-2xl fade-in overflow-y-auto">
|
||||||
|
<div
|
||||||
|
onClick={() => setShowInfo(!showInfo)}
|
||||||
|
className=" float-right btn btn-sm outline-none btn-circle btn-ghost z-10"
|
||||||
|
>
|
||||||
|
<i className="bi-x text-neutral text-2xl"></i>
|
||||||
|
</div>
|
||||||
|
<p className="text-neutral text-lg font-semibold">
|
||||||
|
{t("description")}
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<hr className="divider my-2 last:hidden border-t border-neutral-content h-[1px]" />
|
||||||
|
<p>
|
||||||
|
{link.description ? (
|
||||||
|
unescapeString(link.description)
|
||||||
|
) : (
|
||||||
|
<span className="text-neutral text-sm">
|
||||||
|
{t("no_description")}
|
||||||
|
</span>
|
||||||
|
)}
|
||||||
|
</p>
|
||||||
|
{link.tags[0] && (
|
||||||
|
<>
|
||||||
|
<p className="text-neutral text-lg mt-3 font-semibold">
|
||||||
|
{t("tags")}
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<hr className="divider my-2 last:hidden border-t border-neutral-content h-[1px]" />
|
||||||
|
|
||||||
|
<div className="flex gap-3 items-center flex-wrap mt-2 truncate relative">
|
||||||
|
<div className="flex gap-1 items-center flex-wrap">
|
||||||
|
{link.tags.map((e, i) => (
|
||||||
|
<Link
|
||||||
|
href={"/tags/" + e.id}
|
||||||
|
key={i}
|
||||||
|
onClick={(e) => {
|
||||||
|
e.stopPropagation();
|
||||||
|
}}
|
||||||
|
className="btn btn-xs btn-ghost truncate max-w-[19rem]"
|
||||||
|
>
|
||||||
|
#{e.name}
|
||||||
|
</Link>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
|
<LinkActions
|
||||||
|
link={link}
|
||||||
|
collection={collection}
|
||||||
|
position={
|
||||||
|
link.preview !== "unavailable"
|
||||||
|
? "top-[10.75rem] right-3"
|
||||||
|
: "top-[.75rem] right-3"
|
||||||
|
}
|
||||||
|
toggleShowInfo={() => setShowInfo(!showInfo)}
|
||||||
|
linkInfo={showInfo}
|
||||||
|
flipDropdown={flipDropdown}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
|
@ -1,7 +0,0 @@
|
||||||
export default function Loading() {
|
|
||||||
return (
|
|
||||||
<div>
|
|
||||||
<p>Loading...</p>
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
}
|
|
|
@ -1,14 +1,16 @@
|
||||||
import { dropdownTriggerer, isIphone } from "@/lib/client/utils";
|
import { dropdownTriggerer, isIphone, isPWA } from "@/lib/client/utils";
|
||||||
import React from "react";
|
import React from "react";
|
||||||
import { useState } from "react";
|
import { useState } from "react";
|
||||||
import NewLinkModal from "./ModalContent/NewLinkModal";
|
import NewLinkModal from "./ModalContent/NewLinkModal";
|
||||||
import NewCollectionModal from "./ModalContent/NewCollectionModal";
|
import NewCollectionModal from "./ModalContent/NewCollectionModal";
|
||||||
import UploadFileModal from "./ModalContent/UploadFileModal";
|
import UploadFileModal from "./ModalContent/UploadFileModal";
|
||||||
import MobileNavigationButton from "./MobileNavigationButton";
|
import MobileNavigationButton from "./MobileNavigationButton";
|
||||||
|
import { useTranslation } from "next-i18next";
|
||||||
|
|
||||||
type Props = {};
|
type Props = {};
|
||||||
|
|
||||||
export default function MobileNavigation({}: Props) {
|
export default function MobileNavigation({}: Props) {
|
||||||
|
const { t } = useTranslation();
|
||||||
const [newLinkModal, setNewLinkModal] = useState(false);
|
const [newLinkModal, setNewLinkModal] = useState(false);
|
||||||
const [newCollectionModal, setNewCollectionModal] = useState(false);
|
const [newCollectionModal, setNewCollectionModal] = useState(false);
|
||||||
const [uploadFileModal, setUploadFileModal] = useState(false);
|
const [uploadFileModal, setUploadFileModal] = useState(false);
|
||||||
|
@ -20,7 +22,7 @@ export default function MobileNavigation({}: Props) {
|
||||||
>
|
>
|
||||||
<div
|
<div
|
||||||
className={`w-full flex bg-base-100 ${
|
className={`w-full flex bg-base-100 ${
|
||||||
isIphone() ? "pb-5" : ""
|
isIphone() && isPWA() ? "pb-5" : ""
|
||||||
} border-solid border-t-neutral-content border-t`}
|
} border-solid border-t-neutral-content border-t`}
|
||||||
>
|
>
|
||||||
<MobileNavigationButton href={`/dashboard`} icon={"bi-house"} />
|
<MobileNavigationButton href={`/dashboard`} icon={"bi-house"} />
|
||||||
|
@ -49,10 +51,10 @@ export default function MobileNavigation({}: Props) {
|
||||||
tabIndex={0}
|
tabIndex={0}
|
||||||
role="button"
|
role="button"
|
||||||
>
|
>
|
||||||
New Link
|
{t("new_link")}
|
||||||
</div>
|
</div>
|
||||||
</li>
|
</li>
|
||||||
{/* <li>
|
<li>
|
||||||
<div
|
<div
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
(document?.activeElement as HTMLElement)?.blur();
|
(document?.activeElement as HTMLElement)?.blur();
|
||||||
|
@ -61,9 +63,9 @@ export default function MobileNavigation({}: Props) {
|
||||||
tabIndex={0}
|
tabIndex={0}
|
||||||
role="button"
|
role="button"
|
||||||
>
|
>
|
||||||
Upload File
|
{t("upload_file")}
|
||||||
</div>
|
</div>
|
||||||
</li> */}
|
</li>
|
||||||
<li>
|
<li>
|
||||||
<div
|
<div
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
|
@ -73,7 +75,7 @@ export default function MobileNavigation({}: Props) {
|
||||||
tabIndex={0}
|
tabIndex={0}
|
||||||
role="button"
|
role="button"
|
||||||
>
|
>
|
||||||
New Collection
|
{t("new_collection")}
|
||||||
</div>
|
</div>
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
|
|
|
@ -6,9 +6,15 @@ type Props = {
|
||||||
toggleModal: Function;
|
toggleModal: Function;
|
||||||
children: ReactNode;
|
children: ReactNode;
|
||||||
className?: string;
|
className?: string;
|
||||||
|
dismissible?: boolean;
|
||||||
};
|
};
|
||||||
|
|
||||||
export default function Modal({ toggleModal, className, children }: Props) {
|
export default function Modal({
|
||||||
|
toggleModal,
|
||||||
|
className,
|
||||||
|
children,
|
||||||
|
dismissible = true,
|
||||||
|
}: Props) {
|
||||||
const [drawerIsOpen, setDrawerIsOpen] = React.useState(true);
|
const [drawerIsOpen, setDrawerIsOpen] = React.useState(true);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
@ -26,14 +32,23 @@ export default function Modal({ toggleModal, className, children }: Props) {
|
||||||
return (
|
return (
|
||||||
<Drawer.Root
|
<Drawer.Root
|
||||||
open={drawerIsOpen}
|
open={drawerIsOpen}
|
||||||
onClose={() => setTimeout(() => toggleModal(), 100)}
|
onClose={() => dismissible && setTimeout(() => toggleModal(), 100)}
|
||||||
|
dismissible={dismissible}
|
||||||
>
|
>
|
||||||
<Drawer.Portal>
|
<Drawer.Portal>
|
||||||
<Drawer.Overlay className="fixed inset-0 bg-black/40" />
|
<Drawer.Overlay className="fixed inset-0 bg-black/40" />
|
||||||
<ClickAwayHandler onClickOutside={() => setDrawerIsOpen(false)}>
|
<ClickAwayHandler
|
||||||
<Drawer.Content className="flex flex-col rounded-t-2xl h-[90%] mt-24 fixed bottom-0 left-0 right-0 z-30">
|
onClickOutside={() => dismissible && setDrawerIsOpen(false)}
|
||||||
<div className="p-4 pb-32 bg-base-100 rounded-t-2xl flex-1 border-neutral-content border-t overflow-y-auto">
|
>
|
||||||
<div className="mx-auto w-12 h-1.5 flex-shrink-0 rounded-full bg-neutral mb-5" />
|
<Drawer.Content className="flex flex-col rounded-t-2xl min-h-max mt-24 fixed bottom-0 left-0 right-0 z-30">
|
||||||
|
<div
|
||||||
|
className="p-4 bg-base-100 rounded-t-2xl flex-1 border-neutral-content border-t overflow-y-auto"
|
||||||
|
data-testid="mobile-modal-container"
|
||||||
|
>
|
||||||
|
<div
|
||||||
|
className="mx-auto w-12 h-1.5 flex-shrink-0 rounded-full bg-neutral mb-5"
|
||||||
|
data-testid="mobile-modal-slider"
|
||||||
|
/>
|
||||||
|
|
||||||
{children}
|
{children}
|
||||||
</div>
|
</div>
|
||||||
|
@ -44,20 +59,31 @@ export default function Modal({ toggleModal, className, children }: Props) {
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
return (
|
return (
|
||||||
<div className="overflow-y-auto pt-2 sm:py-2 fixed top-0 bottom-0 right-0 left-0 bg-black bg-opacity-10 backdrop-blur-sm flex justify-center items-center fade-in z-40">
|
<div
|
||||||
|
className="overflow-y-auto pt-2 sm:py-2 fixed top-0 bottom-0 right-0 left-0 bg-black bg-opacity-10 backdrop-blur-sm flex justify-center items-center fade-in z-40"
|
||||||
|
data-testid="modal-outer"
|
||||||
|
>
|
||||||
<ClickAwayHandler
|
<ClickAwayHandler
|
||||||
onClickOutside={toggleModal}
|
onClickOutside={() => dismissible && toggleModal()}
|
||||||
className={`w-full mt-auto sm:m-auto sm:w-11/12 sm:max-w-2xl ${
|
className={`w-full mt-auto sm:m-auto sm:w-11/12 sm:max-w-2xl ${
|
||||||
className || ""
|
className || ""
|
||||||
}`}
|
}`}
|
||||||
>
|
>
|
||||||
<div className="slide-up mt-auto sm:m-auto relative border-neutral-content rounded-t-2xl sm:rounded-2xl border-t sm:border shadow-2xl p-5 bg-base-100 overflow-y-auto sm:overflow-y-visible">
|
<div
|
||||||
|
className="slide-up mt-auto sm:m-auto relative border-neutral-content rounded-t-2xl sm:rounded-2xl border-t sm:border shadow-2xl p-5 bg-base-100 overflow-y-auto sm:overflow-y-visible"
|
||||||
|
data-testid="modal-container"
|
||||||
|
>
|
||||||
|
{dismissible && (
|
||||||
<div
|
<div
|
||||||
onClick={toggleModal as MouseEventHandler<HTMLDivElement>}
|
onClick={toggleModal as MouseEventHandler<HTMLDivElement>}
|
||||||
className="absolute top-4 right-3 btn btn-sm outline-none btn-circle btn-ghost z-10"
|
className="absolute top-4 right-3 btn btn-sm outline-none btn-circle btn-ghost z-10"
|
||||||
>
|
>
|
||||||
<i className="bi-x text-neutral text-2xl"></i>
|
<i
|
||||||
|
className="bi-x text-neutral text-2xl"
|
||||||
|
data-testid="close-modal-button"
|
||||||
|
></i>
|
||||||
</div>
|
</div>
|
||||||
|
)}
|
||||||
{children}
|
{children}
|
||||||
</div>
|
</div>
|
||||||
</ClickAwayHandler>
|
</ClickAwayHandler>
|
||||||
|
|
|
@ -2,20 +2,19 @@ import React from "react";
|
||||||
import useLinkStore from "@/store/links";
|
import useLinkStore from "@/store/links";
|
||||||
import toast from "react-hot-toast";
|
import toast from "react-hot-toast";
|
||||||
import Modal from "../Modal";
|
import Modal from "../Modal";
|
||||||
|
import Button from "../ui/Button";
|
||||||
|
import { useTranslation } from "next-i18next";
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
onClose: Function;
|
onClose: Function;
|
||||||
};
|
};
|
||||||
|
|
||||||
export default function BulkDeleteLinksModal({ onClose }: Props) {
|
export default function BulkDeleteLinksModal({ onClose }: Props) {
|
||||||
|
const { t } = useTranslation();
|
||||||
const { selectedLinks, setSelectedLinks, deleteLinksById } = useLinkStore();
|
const { selectedLinks, setSelectedLinks, deleteLinksById } = useLinkStore();
|
||||||
|
|
||||||
const deleteLink = async () => {
|
const deleteLink = async () => {
|
||||||
const load = toast.loading(
|
const load = toast.loading(t("deleting"));
|
||||||
`Deleting ${selectedLinks.length} Link${
|
|
||||||
selectedLinks.length > 1 ? "s" : ""
|
|
||||||
}...`
|
|
||||||
);
|
|
||||||
|
|
||||||
const response = await deleteLinksById(
|
const response = await deleteLinksById(
|
||||||
selectedLinks.map((link) => link.id as number)
|
selectedLinks.map((link) => link.id as number)
|
||||||
|
@ -24,12 +23,7 @@ export default function BulkDeleteLinksModal({ onClose }: Props) {
|
||||||
toast.dismiss(load);
|
toast.dismiss(load);
|
||||||
|
|
||||||
if (response.ok) {
|
if (response.ok) {
|
||||||
toast.success(
|
toast.success(t("deleted"));
|
||||||
`Deleted ${selectedLinks.length} Link${
|
|
||||||
selectedLinks.length > 1 ? "s" : ""
|
|
||||||
}`
|
|
||||||
);
|
|
||||||
|
|
||||||
setSelectedLinks([]);
|
setSelectedLinks([]);
|
||||||
onClose();
|
onClose();
|
||||||
} else toast.error(response.data as string);
|
} else toast.error(response.data as string);
|
||||||
|
@ -38,37 +32,33 @@ export default function BulkDeleteLinksModal({ onClose }: Props) {
|
||||||
return (
|
return (
|
||||||
<Modal toggleModal={onClose}>
|
<Modal toggleModal={onClose}>
|
||||||
<p className="text-xl font-thin text-red-500">
|
<p className="text-xl font-thin text-red-500">
|
||||||
Delete {selectedLinks.length} Link{selectedLinks.length > 1 ? "s" : ""}
|
{selectedLinks.length === 1
|
||||||
|
? t("delete_link")
|
||||||
|
: t("delete_links", { count: selectedLinks.length })}
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<div className="divider mb-3 mt-1"></div>
|
<div className="divider mb-3 mt-1"></div>
|
||||||
|
|
||||||
<div className="flex flex-col gap-3">
|
<div className="flex flex-col gap-3">
|
||||||
{selectedLinks.length > 1 ? (
|
<p>
|
||||||
<p>Are you sure you want to delete {selectedLinks.length} links?</p>
|
{selectedLinks.length === 1
|
||||||
) : (
|
? t("link_deletion_confirmation_message")
|
||||||
<p>Are you sure you want to delete this link?</p>
|
: t("links_deletion_confirmation_message", {
|
||||||
)}
|
count: selectedLinks.length,
|
||||||
|
})}
|
||||||
|
</p>
|
||||||
|
|
||||||
<div role="alert" className="alert alert-warning">
|
<div role="alert" className="alert alert-warning">
|
||||||
<i className="bi-exclamation-triangle text-xl" />
|
<i className="bi-exclamation-triangle text-xl" />
|
||||||
<span>
|
<span>{t("warning_irreversible")}</span>
|
||||||
<b>Warning:</b> This action is irreversible!
|
|
||||||
</span>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<p>
|
<p>{t("shift_key_tip")}</p>
|
||||||
Hold the <kbd className="kbd kbd-sm">Shift</kbd> key while clicking
|
|
||||||
'Delete' to bypass this confirmation in the future.
|
|
||||||
</p>
|
|
||||||
|
|
||||||
<button
|
<Button className="ml-auto" intent="destructive" onClick={deleteLink}>
|
||||||
className={`ml-auto btn w-fit text-white flex items-center gap-2 duration-100 bg-red-500 hover:bg-red-400 hover:dark:bg-red-600 cursor-pointer`}
|
|
||||||
onClick={deleteLink}
|
|
||||||
>
|
|
||||||
<i className="bi-trash text-xl" />
|
<i className="bi-trash text-xl" />
|
||||||
Delete
|
{t("delete")}
|
||||||
</button>
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
</Modal>
|
</Modal>
|
||||||
);
|
);
|
||||||
|
|
|
@ -5,12 +5,14 @@ import useLinkStore from "@/store/links";
|
||||||
import { LinkIncludingShortenedCollectionAndTags } from "@/types/global";
|
import { LinkIncludingShortenedCollectionAndTags } from "@/types/global";
|
||||||
import toast from "react-hot-toast";
|
import toast from "react-hot-toast";
|
||||||
import Modal from "../Modal";
|
import Modal from "../Modal";
|
||||||
|
import { useTranslation } from "next-i18next";
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
onClose: Function;
|
onClose: Function;
|
||||||
};
|
};
|
||||||
|
|
||||||
export default function BulkEditLinksModal({ onClose }: Props) {
|
export default function BulkEditLinksModal({ onClose }: Props) {
|
||||||
|
const { t } = useTranslation();
|
||||||
const { updateLinks, selectedLinks, setSelectedLinks } = useLinkStore();
|
const { updateLinks, selectedLinks, setSelectedLinks } = useLinkStore();
|
||||||
const [submitLoader, setSubmitLoader] = useState(false);
|
const [submitLoader, setSubmitLoader] = useState(false);
|
||||||
const [removePreviousTags, setRemovePreviousTags] = useState(false);
|
const [removePreviousTags, setRemovePreviousTags] = useState(false);
|
||||||
|
@ -20,7 +22,6 @@ export default function BulkEditLinksModal({ onClose }: Props) {
|
||||||
|
|
||||||
const setCollection = (e: any) => {
|
const setCollection = (e: any) => {
|
||||||
const collectionId = e?.value || null;
|
const collectionId = e?.value || null;
|
||||||
console.log(updatedValues);
|
|
||||||
setUpdatedValues((prevValues) => ({ ...prevValues, collectionId }));
|
setUpdatedValues((prevValues) => ({ ...prevValues, collectionId }));
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -33,7 +34,7 @@ export default function BulkEditLinksModal({ onClose }: Props) {
|
||||||
if (!submitLoader) {
|
if (!submitLoader) {
|
||||||
setSubmitLoader(true);
|
setSubmitLoader(true);
|
||||||
|
|
||||||
const load = toast.loading("Updating...");
|
const load = toast.loading(t("updating"));
|
||||||
|
|
||||||
const response = await updateLinks(
|
const response = await updateLinks(
|
||||||
selectedLinks,
|
selectedLinks,
|
||||||
|
@ -44,7 +45,7 @@ export default function BulkEditLinksModal({ onClose }: Props) {
|
||||||
toast.dismiss(load);
|
toast.dismiss(load);
|
||||||
|
|
||||||
if (response.ok) {
|
if (response.ok) {
|
||||||
toast.success(`Updated!`);
|
toast.success(t("updated"));
|
||||||
setSelectedLinks([]);
|
setSelectedLinks([]);
|
||||||
onClose();
|
onClose();
|
||||||
} else toast.error(response.data as string);
|
} else toast.error(response.data as string);
|
||||||
|
@ -57,13 +58,15 @@ export default function BulkEditLinksModal({ onClose }: Props) {
|
||||||
return (
|
return (
|
||||||
<Modal toggleModal={onClose}>
|
<Modal toggleModal={onClose}>
|
||||||
<p className="text-xl font-thin">
|
<p className="text-xl font-thin">
|
||||||
Edit {selectedLinks.length} Link{selectedLinks.length > 1 ? "s" : ""}
|
{selectedLinks.length === 1
|
||||||
|
? t("edit_link")
|
||||||
|
: t("edit_links", { count: selectedLinks.length })}
|
||||||
</p>
|
</p>
|
||||||
<div className="divider mb-3 mt-1"></div>
|
<div className="divider mb-3 mt-1"></div>
|
||||||
<div className="mt-5">
|
<div className="mt-5">
|
||||||
<div className="grid sm:grid-cols-2 gap-3">
|
<div className="grid sm:grid-cols-2 gap-3">
|
||||||
<div>
|
<div>
|
||||||
<p className="mb-2">Move to Collection</p>
|
<p className="mb-2">{t("move_to_collection")}</p>
|
||||||
<CollectionSelection
|
<CollectionSelection
|
||||||
showDefaultValue={false}
|
showDefaultValue={false}
|
||||||
onChange={setCollection}
|
onChange={setCollection}
|
||||||
|
@ -72,7 +75,7 @@ export default function BulkEditLinksModal({ onClose }: Props) {
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div>
|
<div>
|
||||||
<p className="mb-2">Add Tags</p>
|
<p className="mb-2">{t("add_tags")}</p>
|
||||||
<TagSelection onChange={setTags} />
|
<TagSelection onChange={setTags} />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -84,7 +87,7 @@ export default function BulkEditLinksModal({ onClose }: Props) {
|
||||||
checked={removePreviousTags}
|
checked={removePreviousTags}
|
||||||
onChange={(e) => setRemovePreviousTags(e.target.checked)}
|
onChange={(e) => setRemovePreviousTags(e.target.checked)}
|
||||||
/>
|
/>
|
||||||
Remove previous tags
|
{t("remove_previous_tags")}
|
||||||
</label>
|
</label>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -94,7 +97,7 @@ export default function BulkEditLinksModal({ onClose }: Props) {
|
||||||
className="btn btn-accent dark:border-violet-400 text-white"
|
className="btn btn-accent dark:border-violet-400 text-white"
|
||||||
onClick={submit}
|
onClick={submit}
|
||||||
>
|
>
|
||||||
Save Changes
|
{t("save_changes")}
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
</Modal>
|
</Modal>
|
||||||
|
|
|
@ -6,6 +6,8 @@ import { CollectionIncludingMembersAndLinkCount } from "@/types/global";
|
||||||
import { useRouter } from "next/router";
|
import { useRouter } from "next/router";
|
||||||
import usePermissions from "@/hooks/usePermissions";
|
import usePermissions from "@/hooks/usePermissions";
|
||||||
import Modal from "../Modal";
|
import Modal from "../Modal";
|
||||||
|
import Button from "../ui/Button";
|
||||||
|
import { useTranslation } from "next-i18next";
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
onClose: Function;
|
onClose: Function;
|
||||||
|
@ -16,42 +18,40 @@ export default function DeleteCollectionModal({
|
||||||
onClose,
|
onClose,
|
||||||
activeCollection,
|
activeCollection,
|
||||||
}: Props) {
|
}: Props) {
|
||||||
|
const { t } = useTranslation();
|
||||||
const [collection, setCollection] =
|
const [collection, setCollection] =
|
||||||
useState<CollectionIncludingMembersAndLinkCount>(activeCollection);
|
useState<CollectionIncludingMembersAndLinkCount>(activeCollection);
|
||||||
|
const [submitLoader, setSubmitLoader] = useState(false);
|
||||||
|
const { removeCollection } = useCollectionStore();
|
||||||
|
const router = useRouter();
|
||||||
|
const [inputField, setInputField] = useState("");
|
||||||
|
const permissions = usePermissions(collection.id as number);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
setCollection(activeCollection);
|
setCollection(activeCollection);
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
const [submitLoader, setSubmitLoader] = useState(false);
|
|
||||||
const { removeCollection } = useCollectionStore();
|
|
||||||
const router = useRouter();
|
|
||||||
const [inputField, setInputField] = useState("");
|
|
||||||
|
|
||||||
const permissions = usePermissions(collection.id as number);
|
|
||||||
|
|
||||||
const submit = async () => {
|
const submit = async () => {
|
||||||
if (permissions === true) if (collection.name !== inputField) return null;
|
if (permissions === true && collection.name !== inputField) return;
|
||||||
|
|
||||||
if (!submitLoader) {
|
if (!submitLoader) {
|
||||||
setSubmitLoader(true);
|
setSubmitLoader(true);
|
||||||
if (!collection) return null;
|
if (!collection) return null;
|
||||||
|
|
||||||
setSubmitLoader(true);
|
setSubmitLoader(true);
|
||||||
|
|
||||||
const load = toast.loading("Deleting...");
|
const load = toast.loading(t("deleting_collection"));
|
||||||
|
|
||||||
let response;
|
let response = await removeCollection(collection.id as number);
|
||||||
|
|
||||||
response = await removeCollection(collection.id as any);
|
|
||||||
|
|
||||||
toast.dismiss(load);
|
toast.dismiss(load);
|
||||||
|
|
||||||
if (response.ok) {
|
if (response.ok) {
|
||||||
toast.success(`Deleted.`);
|
toast.success(t("deleted"));
|
||||||
onClose();
|
onClose();
|
||||||
router.push("/collections");
|
router.push("/collections");
|
||||||
} else toast.error(response.data as string);
|
} else {
|
||||||
|
toast.error(response.data as string);
|
||||||
|
}
|
||||||
|
|
||||||
setSubmitLoader(false);
|
setSubmitLoader(false);
|
||||||
}
|
}
|
||||||
|
@ -60,7 +60,7 @@ export default function DeleteCollectionModal({
|
||||||
return (
|
return (
|
||||||
<Modal toggleModal={onClose}>
|
<Modal toggleModal={onClose}>
|
||||||
<p className="text-xl font-thin text-red-500">
|
<p className="text-xl font-thin text-red-500">
|
||||||
{permissions === true ? "Delete" : "Leave"} Collection
|
{permissions === true ? t("delete_collection") : t("leave_collection")}
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<div className="divider mb-3 mt-1"></div>
|
<div className="divider mb-3 mt-1"></div>
|
||||||
|
@ -68,48 +68,37 @@ export default function DeleteCollectionModal({
|
||||||
<div className="flex flex-col gap-3">
|
<div className="flex flex-col gap-3">
|
||||||
{permissions === true ? (
|
{permissions === true ? (
|
||||||
<>
|
<>
|
||||||
<div className="flex flex-col gap-3">
|
<p>{t("confirm_deletion_prompt", { name: collection.name })}</p>
|
||||||
<p>
|
|
||||||
To confirm, type "
|
|
||||||
<span className="font-bold">{collection.name}</span>
|
|
||||||
" in the box below:
|
|
||||||
</p>
|
|
||||||
|
|
||||||
<TextInput
|
<TextInput
|
||||||
value={inputField}
|
value={inputField}
|
||||||
onChange={(e) => setInputField(e.target.value)}
|
onChange={(e) => setInputField(e.target.value)}
|
||||||
placeholder={`Type "${collection.name}" Here.`}
|
placeholder={t("type_name_placeholder", {
|
||||||
|
name: collection.name,
|
||||||
|
})}
|
||||||
className="w-3/4 mx-auto"
|
className="w-3/4 mx-auto"
|
||||||
/>
|
/>
|
||||||
</div>
|
|
||||||
|
|
||||||
<div role="alert" className="alert alert-warning">
|
<div role="alert" className="alert alert-warning">
|
||||||
<i className="bi-exclamation-triangle text-xl"></i>
|
<i className="bi-exclamation-triangle text-xl"></i>
|
||||||
<span>
|
<span>
|
||||||
<b>Warning:</b> Deleting this collection will permanently erase
|
<b>{t("warning")}: </b>
|
||||||
all its contents, and it will become inaccessible to everyone,
|
{t("deletion_warning")}
|
||||||
including members with previous access.
|
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
</>
|
</>
|
||||||
) : (
|
) : (
|
||||||
<p>Click the button below to leave the current collection.</p>
|
<p>{t("leave_prompt")}</p>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
<button
|
<Button
|
||||||
disabled={permissions === true && inputField !== collection.name}
|
disabled={permissions === true && inputField !== collection.name}
|
||||||
className={`ml-auto btn w-fit text-white flex items-center gap-2 duration-100 ${
|
|
||||||
permissions === true
|
|
||||||
? inputField === collection.name
|
|
||||||
? "bg-red-500 hover:bg-red-400 hover:dark:bg-red-600 cursor-pointer"
|
|
||||||
: "cursor-not-allowed bg-red-300 dark:bg-red-900"
|
|
||||||
: "bg-red-500 hover:bg-red-400 hover:dark:bg-red-600 cursor-pointer"
|
|
||||||
}`}
|
|
||||||
onClick={submit}
|
onClick={submit}
|
||||||
|
intent="destructive"
|
||||||
|
className="ml-auto"
|
||||||
>
|
>
|
||||||
<i className="bi-trash text-xl"></i>
|
<i className="bi-trash text-xl"></i>
|
||||||
{permissions === true ? "Delete" : "Leave"} Collection
|
{permissions === true ? t("delete") : t("leave")}
|
||||||
</button>
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
</Modal>
|
</Modal>
|
||||||
);
|
);
|
||||||
|
|
|
@ -4,6 +4,8 @@ import { LinkIncludingShortenedCollectionAndTags } from "@/types/global";
|
||||||
import toast from "react-hot-toast";
|
import toast from "react-hot-toast";
|
||||||
import Modal from "../Modal";
|
import Modal from "../Modal";
|
||||||
import { useRouter } from "next/router";
|
import { useRouter } from "next/router";
|
||||||
|
import Button from "../ui/Button";
|
||||||
|
import { useTranslation } from "next-i18next";
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
onClose: Function;
|
onClose: Function;
|
||||||
|
@ -11,11 +13,10 @@ type Props = {
|
||||||
};
|
};
|
||||||
|
|
||||||
export default function DeleteLinkModal({ onClose, activeLink }: Props) {
|
export default function DeleteLinkModal({ onClose, activeLink }: Props) {
|
||||||
|
const { t } = useTranslation();
|
||||||
const [link, setLink] =
|
const [link, setLink] =
|
||||||
useState<LinkIncludingShortenedCollectionAndTags>(activeLink);
|
useState<LinkIncludingShortenedCollectionAndTags>(activeLink);
|
||||||
|
|
||||||
const { removeLink } = useLinkStore();
|
const { removeLink } = useLinkStore();
|
||||||
|
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
@ -23,13 +24,13 @@ export default function DeleteLinkModal({ onClose, activeLink }: Props) {
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
const deleteLink = async () => {
|
const deleteLink = async () => {
|
||||||
const load = toast.loading("Deleting...");
|
const load = toast.loading(t("deleting"));
|
||||||
|
|
||||||
const response = await removeLink(link.id as number);
|
const response = await removeLink(link.id as number);
|
||||||
|
|
||||||
toast.dismiss(load);
|
toast.dismiss(load);
|
||||||
|
|
||||||
response.ok && toast.success(`Link Deleted.`);
|
response.ok && toast.success(t("deleted"));
|
||||||
|
|
||||||
if (router.pathname.startsWith("/links/[id]")) {
|
if (router.pathname.startsWith("/links/[id]")) {
|
||||||
router.push("/dashboard");
|
router.push("/dashboard");
|
||||||
|
@ -40,32 +41,26 @@ export default function DeleteLinkModal({ onClose, activeLink }: Props) {
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Modal toggleModal={onClose}>
|
<Modal toggleModal={onClose}>
|
||||||
<p className="text-xl font-thin text-red-500">Delete Link</p>
|
<p className="text-xl font-thin text-red-500">{t("delete_link")}</p>
|
||||||
|
|
||||||
<div className="divider mb-3 mt-1"></div>
|
<div className="divider mb-3 mt-1"></div>
|
||||||
|
|
||||||
<div className="flex flex-col gap-3">
|
<div className="flex flex-col gap-3">
|
||||||
<p>Are you sure you want to delete this Link?</p>
|
<p>{t("link_deletion_confirmation_message")}</p>
|
||||||
|
|
||||||
<div role="alert" className="alert alert-warning">
|
<div role="alert" className="alert alert-warning">
|
||||||
<i className="bi-exclamation-triangle text-xl" />
|
<i className="bi-exclamation-triangle text-xl" />
|
||||||
<span>
|
<span>
|
||||||
<b>Warning:</b> This action is irreversible!
|
<b>{t("warning")}:</b> {t("irreversible_warning")}
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<p>
|
<p>{t("shift_key_tip")}</p>
|
||||||
Hold the <kbd className="kbd kbd-sm">Shift</kbd> key while clicking
|
|
||||||
'Delete' to bypass this confirmation in the future.
|
|
||||||
</p>
|
|
||||||
|
|
||||||
<button
|
<Button className="ml-auto" intent="destructive" onClick={deleteLink}>
|
||||||
className={`ml-auto btn w-fit text-white flex items-center gap-2 duration-100 bg-red-500 hover:bg-red-400 hover:dark:bg-red-600 cursor-pointer`}
|
|
||||||
onClick={deleteLink}
|
|
||||||
>
|
|
||||||
<i className="bi-trash text-xl" />
|
<i className="bi-trash text-xl" />
|
||||||
Delete
|
{t("delete")}
|
||||||
</button>
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
</Modal>
|
</Modal>
|
||||||
);
|
);
|
||||||
|
|
|
@ -0,0 +1,51 @@
|
||||||
|
import toast from "react-hot-toast";
|
||||||
|
import Modal from "../Modal";
|
||||||
|
import useUserStore from "@/store/admin/users";
|
||||||
|
import Button from "../ui/Button";
|
||||||
|
import { useTranslation } from "next-i18next";
|
||||||
|
|
||||||
|
type Props = {
|
||||||
|
onClose: Function;
|
||||||
|
userId: number;
|
||||||
|
};
|
||||||
|
|
||||||
|
export default function DeleteUserModal({ onClose, userId }: Props) {
|
||||||
|
const { t } = useTranslation();
|
||||||
|
const { removeUser } = useUserStore();
|
||||||
|
|
||||||
|
const deleteUser = async () => {
|
||||||
|
const load = toast.loading(t("deleting_user"));
|
||||||
|
|
||||||
|
const response = await removeUser(userId);
|
||||||
|
|
||||||
|
toast.dismiss(load);
|
||||||
|
|
||||||
|
response.ok && toast.success(t("user_deleted"));
|
||||||
|
|
||||||
|
onClose();
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Modal toggleModal={onClose}>
|
||||||
|
<p className="text-xl font-thin text-red-500">{t("delete_user")}</p>
|
||||||
|
|
||||||
|
<div className="divider mb-3 mt-1"></div>
|
||||||
|
|
||||||
|
<div className="flex flex-col gap-3">
|
||||||
|
<p>{t("confirm_user_deletion")}</p>
|
||||||
|
|
||||||
|
<div role="alert" className="alert alert-warning">
|
||||||
|
<i className="bi-exclamation-triangle text-xl" />
|
||||||
|
<span>
|
||||||
|
<b>{t("warning")}:</b> {t("irreversible_action_warning")}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<Button className="ml-auto" intent="destructive" onClick={deleteUser}>
|
||||||
|
<i className="bi-trash text-xl" />
|
||||||
|
{t("delete_confirmation")}
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
</Modal>
|
||||||
|
);
|
||||||
|
}
|
|
@ -5,6 +5,7 @@ import toast from "react-hot-toast";
|
||||||
import { HexColorPicker } from "react-colorful";
|
import { HexColorPicker } from "react-colorful";
|
||||||
import { CollectionIncludingMembersAndLinkCount } from "@/types/global";
|
import { CollectionIncludingMembersAndLinkCount } from "@/types/global";
|
||||||
import Modal from "../Modal";
|
import Modal from "../Modal";
|
||||||
|
import { useTranslation } from "next-i18next";
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
onClose: Function;
|
onClose: Function;
|
||||||
|
@ -15,6 +16,7 @@ export default function EditCollectionModal({
|
||||||
onClose,
|
onClose,
|
||||||
activeCollection,
|
activeCollection,
|
||||||
}: Props) {
|
}: Props) {
|
||||||
|
const { t } = useTranslation();
|
||||||
const [collection, setCollection] =
|
const [collection, setCollection] =
|
||||||
useState<CollectionIncludingMembersAndLinkCount>(activeCollection);
|
useState<CollectionIncludingMembersAndLinkCount>(activeCollection);
|
||||||
|
|
||||||
|
@ -28,16 +30,14 @@ export default function EditCollectionModal({
|
||||||
|
|
||||||
setSubmitLoader(true);
|
setSubmitLoader(true);
|
||||||
|
|
||||||
const load = toast.loading("Updating...");
|
const load = toast.loading(t("updating_collection"));
|
||||||
|
|
||||||
let response;
|
let response = await updateCollection(collection as any);
|
||||||
|
|
||||||
response = await updateCollection(collection as any);
|
|
||||||
|
|
||||||
toast.dismiss(load);
|
toast.dismiss(load);
|
||||||
|
|
||||||
if (response.ok) {
|
if (response.ok) {
|
||||||
toast.success(`Updated!`);
|
toast.success(t("updated"));
|
||||||
onClose();
|
onClose();
|
||||||
} else toast.error(response.data as string);
|
} else toast.error(response.data as string);
|
||||||
|
|
||||||
|
@ -47,29 +47,35 @@ export default function EditCollectionModal({
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Modal toggleModal={onClose}>
|
<Modal toggleModal={onClose}>
|
||||||
<p className="text-xl font-thin">Edit Collection Info</p>
|
<p className="text-xl font-thin">{t("edit_collection_info")}</p>
|
||||||
|
|
||||||
<div className="divider mb-3 mt-1"></div>
|
<div className="divider mb-3 mt-1"></div>
|
||||||
|
|
||||||
<div className="flex flex-col gap-3">
|
<div className="flex flex-col gap-3">
|
||||||
<div className="flex flex-col sm:flex-row gap-3">
|
<div className="flex flex-col sm:flex-row gap-3">
|
||||||
<div className="w-full">
|
<div className="w-full">
|
||||||
<p className="mb-2">Name</p>
|
<p className="mb-2">{t("name")}</p>
|
||||||
<div className="flex flex-col gap-3">
|
<div className="flex flex-col gap-3">
|
||||||
<TextInput
|
<TextInput
|
||||||
className="bg-base-200"
|
className="bg-base-200"
|
||||||
value={collection.name}
|
value={collection.name}
|
||||||
placeholder="e.g. Example Collection"
|
placeholder={t("collection_name_placeholder")}
|
||||||
onChange={(e) =>
|
onChange={(e) =>
|
||||||
setCollection({ ...collection, name: e.target.value })
|
setCollection({ ...collection, name: e.target.value })
|
||||||
}
|
}
|
||||||
/>
|
/>
|
||||||
<div>
|
<div>
|
||||||
<p className="w-full mb-2">Color</p>
|
<p className="w-full mb-2">{t("color")}</p>
|
||||||
<div className="color-picker flex justify-between">
|
<div className="color-picker flex justify-between items-center">
|
||||||
|
<HexColorPicker
|
||||||
|
color={collection.color}
|
||||||
|
onChange={(color) =>
|
||||||
|
setCollection({ ...collection, color })
|
||||||
|
}
|
||||||
|
/>
|
||||||
<div className="flex flex-col gap-2 items-center w-32">
|
<div className="flex flex-col gap-2 items-center w-32">
|
||||||
<i
|
<i
|
||||||
className="bi-folder-fill text-5xl drop-shadow"
|
className="bi-folder-fill text-5xl"
|
||||||
style={{ color: collection.color }}
|
style={{ color: collection.color }}
|
||||||
></i>
|
></i>
|
||||||
<div
|
<div
|
||||||
|
@ -78,29 +84,22 @@ export default function EditCollectionModal({
|
||||||
setCollection({ ...collection, color: "#0ea5e9" })
|
setCollection({ ...collection, color: "#0ea5e9" })
|
||||||
}
|
}
|
||||||
>
|
>
|
||||||
Reset
|
{t("reset")}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<HexColorPicker
|
|
||||||
color={collection.color}
|
|
||||||
onChange={(e) => setCollection({ ...collection, color: e })}
|
|
||||||
/>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="w-full">
|
<div className="w-full">
|
||||||
<p className="mb-2">Description</p>
|
<p className="mb-2">{t("description")}</p>
|
||||||
<textarea
|
<textarea
|
||||||
className="w-full h-[13rem] resize-none border rounded-md duration-100 bg-base-200 p-2 outline-none border-neutral-content focus:border-primary"
|
className="w-full h-[13rem] resize-none border rounded-md duration-100 bg-base-200 p-2 outline-none border-neutral-content focus:border-primary"
|
||||||
placeholder="The purpose of this Collection..."
|
placeholder={t("collection_description_placeholder")}
|
||||||
value={collection.description}
|
value={collection.description}
|
||||||
onChange={(e) =>
|
onChange={(e) =>
|
||||||
setCollection({
|
setCollection({ ...collection, description: e.target.value })
|
||||||
...collection,
|
|
||||||
description: e.target.value,
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
@ -110,7 +109,7 @@ export default function EditCollectionModal({
|
||||||
className="btn btn-accent dark:border-violet-400 text-white w-fit ml-auto"
|
className="btn btn-accent dark:border-violet-400 text-white w-fit ml-auto"
|
||||||
onClick={submit}
|
onClick={submit}
|
||||||
>
|
>
|
||||||
Save Changes
|
{t("save_changes")}
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
</Modal>
|
</Modal>
|
||||||
|
|
|
@ -10,6 +10,7 @@ import ProfilePhoto from "../ProfilePhoto";
|
||||||
import addMemberToCollection from "@/lib/client/addMemberToCollection";
|
import addMemberToCollection from "@/lib/client/addMemberToCollection";
|
||||||
import Modal from "../Modal";
|
import Modal from "../Modal";
|
||||||
import { dropdownTriggerer } from "@/lib/client/utils";
|
import { dropdownTriggerer } from "@/lib/client/utils";
|
||||||
|
import { useTranslation } from "next-i18next";
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
onClose: Function;
|
onClose: Function;
|
||||||
|
@ -20,6 +21,8 @@ export default function EditCollectionSharingModal({
|
||||||
onClose,
|
onClose,
|
||||||
activeCollection,
|
activeCollection,
|
||||||
}: Props) {
|
}: Props) {
|
||||||
|
const { t } = useTranslation();
|
||||||
|
|
||||||
const [collection, setCollection] =
|
const [collection, setCollection] =
|
||||||
useState<CollectionIncludingMembersAndLinkCount>(activeCollection);
|
useState<CollectionIncludingMembersAndLinkCount>(activeCollection);
|
||||||
|
|
||||||
|
@ -33,7 +36,7 @@ export default function EditCollectionSharingModal({
|
||||||
|
|
||||||
setSubmitLoader(true);
|
setSubmitLoader(true);
|
||||||
|
|
||||||
const load = toast.loading("Updating...");
|
const load = toast.loading(t("updating"));
|
||||||
|
|
||||||
let response;
|
let response;
|
||||||
|
|
||||||
|
@ -42,7 +45,7 @@ export default function EditCollectionSharingModal({
|
||||||
toast.dismiss(load);
|
toast.dismiss(load);
|
||||||
|
|
||||||
if (response.ok) {
|
if (response.ok) {
|
||||||
toast.success(`Updated!`);
|
toast.success(t("updated"));
|
||||||
onClose();
|
onClose();
|
||||||
} else toast.error(response.data as string);
|
} else toast.error(response.data as string);
|
||||||
|
|
||||||
|
@ -94,7 +97,7 @@ export default function EditCollectionSharingModal({
|
||||||
return (
|
return (
|
||||||
<Modal toggleModal={onClose}>
|
<Modal toggleModal={onClose}>
|
||||||
<p className="text-xl font-thin">
|
<p className="text-xl font-thin">
|
||||||
{permissions === true ? "Share and Collaborate" : "Team"}
|
{permissions === true ? t("share_and_collaborate") : t("team")}
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<div className="divider mb-3 mt-1"></div>
|
<div className="divider mb-3 mt-1"></div>
|
||||||
|
@ -102,7 +105,7 @@ export default function EditCollectionSharingModal({
|
||||||
<div className="flex flex-col gap-3">
|
<div className="flex flex-col gap-3">
|
||||||
{permissions === true && (
|
{permissions === true && (
|
||||||
<div>
|
<div>
|
||||||
<p>Make Public</p>
|
<p>{t("make_collection_public")}</p>
|
||||||
|
|
||||||
<label className="label cursor-pointer justify-start gap-2">
|
<label className="label cursor-pointer justify-start gap-2">
|
||||||
<input
|
<input
|
||||||
|
@ -116,25 +119,26 @@ export default function EditCollectionSharingModal({
|
||||||
}
|
}
|
||||||
className="checkbox checkbox-primary"
|
className="checkbox checkbox-primary"
|
||||||
/>
|
/>
|
||||||
<span className="label-text">Make this a public collection</span>
|
<span className="label-text">
|
||||||
|
{t("make_collection_public_checkbox")}
|
||||||
|
</span>
|
||||||
</label>
|
</label>
|
||||||
|
|
||||||
<p className="text-neutral text-sm">
|
<p className="text-neutral text-sm">
|
||||||
This will let <b>Anyone</b> to view this collection and it's
|
{t("make_collection_public_desc")}
|
||||||
users.
|
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
{collection.isPublic ? (
|
{collection.isPublic ? (
|
||||||
<div className={permissions === true ? "pl-5" : ""}>
|
<div className={permissions === true ? "pl-5" : ""}>
|
||||||
<p className="mb-2">Sharable Link (Click to copy)</p>
|
<p className="mb-2">{t("sharable_link_guide")}</p>
|
||||||
<div
|
<div
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
try {
|
try {
|
||||||
navigator.clipboard
|
navigator.clipboard
|
||||||
.writeText(publicCollectionURL)
|
.writeText(publicCollectionURL)
|
||||||
.then(() => toast.success("Copied!"));
|
.then(() => toast.success(t("copied")));
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.log(err);
|
console.log(err);
|
||||||
}
|
}
|
||||||
|
@ -150,13 +154,13 @@ export default function EditCollectionSharingModal({
|
||||||
|
|
||||||
{permissions === true && (
|
{permissions === true && (
|
||||||
<>
|
<>
|
||||||
<p>Members</p>
|
<p>{t("members")}</p>
|
||||||
|
|
||||||
<div className="flex items-center gap-2">
|
<div className="flex items-center gap-2">
|
||||||
<TextInput
|
<TextInput
|
||||||
value={memberUsername || ""}
|
value={memberUsername || ""}
|
||||||
className="bg-base-200"
|
className="bg-base-200"
|
||||||
placeholder="Username (without the '@')"
|
placeholder={t("members_username_placeholder")}
|
||||||
onChange={(e) => setMemberUsername(e.target.value)}
|
onChange={(e) => setMemberUsername(e.target.value)}
|
||||||
onKeyDown={(e) =>
|
onKeyDown={(e) =>
|
||||||
e.key === "Enter" &&
|
e.key === "Enter" &&
|
||||||
|
@ -164,7 +168,8 @@ export default function EditCollectionSharingModal({
|
||||||
account.username as string,
|
account.username as string,
|
||||||
memberUsername || "",
|
memberUsername || "",
|
||||||
collection,
|
collection,
|
||||||
setMemberState
|
setMemberState,
|
||||||
|
t
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
/>
|
/>
|
||||||
|
@ -175,7 +180,8 @@ export default function EditCollectionSharingModal({
|
||||||
account.username as string,
|
account.username as string,
|
||||||
memberUsername || "",
|
memberUsername || "",
|
||||||
collection,
|
collection,
|
||||||
setMemberState
|
setMemberState,
|
||||||
|
t
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
className="btn btn-accent dark:border-violet-400 text-white btn-square btn-sm h-10 w-10"
|
className="btn btn-accent dark:border-violet-400 text-white btn-square btn-sm h-10 w-10"
|
||||||
|
@ -215,7 +221,7 @@ export default function EditCollectionSharingModal({
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
<p className="text-sm font-bold">Owner</p>
|
<p className="text-sm font-bold">{t("owner")}</p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -227,11 +233,11 @@ export default function EditCollectionSharingModal({
|
||||||
.map((e, i) => {
|
.map((e, i) => {
|
||||||
const roleLabel =
|
const roleLabel =
|
||||||
e.canCreate && e.canUpdate && e.canDelete
|
e.canCreate && e.canUpdate && e.canDelete
|
||||||
? "Admin"
|
? t("admin")
|
||||||
: e.canCreate && !e.canUpdate && !e.canDelete
|
: e.canCreate && !e.canUpdate && !e.canDelete
|
||||||
? "Contributor"
|
? t("contributor")
|
||||||
: !e.canCreate && !e.canUpdate && !e.canDelete
|
: !e.canCreate && !e.canUpdate && !e.canDelete
|
||||||
? "Viewer"
|
? t("viewer")
|
||||||
: undefined;
|
: undefined;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
@ -308,8 +314,10 @@ export default function EditCollectionSharingModal({
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
<div>
|
<div>
|
||||||
<p className="font-bold">Viewer</p>
|
<p className="font-bold">
|
||||||
<p>Read-only access</p>
|
{t("viewer")}
|
||||||
|
</p>
|
||||||
|
<p>{t("viewer_desc")}</p>
|
||||||
</div>
|
</div>
|
||||||
</label>
|
</label>
|
||||||
</li>
|
</li>
|
||||||
|
@ -351,8 +359,10 @@ export default function EditCollectionSharingModal({
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
<div>
|
<div>
|
||||||
<p className="font-bold">Contributor</p>
|
<p className="font-bold">
|
||||||
<p>Can view and create Links</p>
|
{t("contributor")}
|
||||||
|
</p>
|
||||||
|
<p>{t("contributor_desc")}</p>
|
||||||
</div>
|
</div>
|
||||||
</label>
|
</label>
|
||||||
</li>
|
</li>
|
||||||
|
@ -394,8 +404,10 @@ export default function EditCollectionSharingModal({
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
<div>
|
<div>
|
||||||
<p className="font-bold">Admin</p>
|
<p className="font-bold">
|
||||||
<p>Full access to all Links</p>
|
{t("admin")}
|
||||||
|
</p>
|
||||||
|
<p>{t("admin_desc")}</p>
|
||||||
</div>
|
</div>
|
||||||
</label>
|
</label>
|
||||||
</li>
|
</li>
|
||||||
|
@ -412,7 +424,7 @@ export default function EditCollectionSharingModal({
|
||||||
className={
|
className={
|
||||||
"bi-x text-xl btn btn-sm btn-square btn-ghost text-neutral hover:text-red-500 dark:hover:text-red-500 duration-100 cursor-pointer"
|
"bi-x text-xl btn btn-sm btn-square btn-ghost text-neutral hover:text-red-500 dark:hover:text-red-500 duration-100 cursor-pointer"
|
||||||
}
|
}
|
||||||
title="Remove Member"
|
title={t("remove_member")}
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
const updatedMembers =
|
const updatedMembers =
|
||||||
collection.members.filter((member) => {
|
collection.members.filter((member) => {
|
||||||
|
@ -443,7 +455,7 @@ export default function EditCollectionSharingModal({
|
||||||
className="btn btn-accent dark:border-violet-400 text-white w-fit ml-auto mt-3"
|
className="btn btn-accent dark:border-violet-400 text-white w-fit ml-auto mt-3"
|
||||||
onClick={submit}
|
onClick={submit}
|
||||||
>
|
>
|
||||||
Save Changes
|
{t("save_changes")}
|
||||||
</button>
|
</button>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -8,6 +8,7 @@ import { LinkIncludingShortenedCollectionAndTags } from "@/types/global";
|
||||||
import toast from "react-hot-toast";
|
import toast from "react-hot-toast";
|
||||||
import Link from "next/link";
|
import Link from "next/link";
|
||||||
import Modal from "../Modal";
|
import Modal from "../Modal";
|
||||||
|
import { useTranslation } from "next-i18next";
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
onClose: Function;
|
onClose: Function;
|
||||||
|
@ -15,13 +16,13 @@ type Props = {
|
||||||
};
|
};
|
||||||
|
|
||||||
export default function EditLinkModal({ onClose, activeLink }: Props) {
|
export default function EditLinkModal({ onClose, activeLink }: Props) {
|
||||||
|
const { t } = useTranslation();
|
||||||
const [link, setLink] =
|
const [link, setLink] =
|
||||||
useState<LinkIncludingShortenedCollectionAndTags>(activeLink);
|
useState<LinkIncludingShortenedCollectionAndTags>(activeLink);
|
||||||
|
|
||||||
let shortendURL;
|
let shortenedURL;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
shortendURL = new URL(link.url || "").host.toLowerCase();
|
shortenedURL = new URL(link.url || "").host.toLowerCase();
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.log(error);
|
console.log(error);
|
||||||
}
|
}
|
||||||
|
@ -31,7 +32,6 @@ export default function EditLinkModal({ onClose, activeLink }: Props) {
|
||||||
|
|
||||||
const setCollection = (e: any) => {
|
const setCollection = (e: any) => {
|
||||||
if (e?.__isNew__) e.value = null;
|
if (e?.__isNew__) e.value = null;
|
||||||
|
|
||||||
setLink({
|
setLink({
|
||||||
...link,
|
...link,
|
||||||
collection: { id: e?.value, name: e?.label, ownerId: e?.ownerId },
|
collection: { id: e?.value, name: e?.label, ownerId: e?.ownerId },
|
||||||
|
@ -39,10 +39,7 @@ export default function EditLinkModal({ onClose, activeLink }: Props) {
|
||||||
};
|
};
|
||||||
|
|
||||||
const setTags = (e: any) => {
|
const setTags = (e: any) => {
|
||||||
const tagNames = e.map((e: any) => {
|
const tagNames = e.map((e: any) => ({ name: e.label }));
|
||||||
return { name: e.label };
|
|
||||||
});
|
|
||||||
|
|
||||||
setLink({ ...link, tags: tagNames });
|
setLink({ ...link, tags: tagNames });
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -53,29 +50,25 @@ export default function EditLinkModal({ onClose, activeLink }: Props) {
|
||||||
const submit = async () => {
|
const submit = async () => {
|
||||||
if (!submitLoader) {
|
if (!submitLoader) {
|
||||||
setSubmitLoader(true);
|
setSubmitLoader(true);
|
||||||
|
const load = toast.loading(t("updating"));
|
||||||
let response;
|
let response = await updateLink(link);
|
||||||
|
|
||||||
const load = toast.loading("Updating...");
|
|
||||||
|
|
||||||
response = await updateLink(link);
|
|
||||||
|
|
||||||
toast.dismiss(load);
|
toast.dismiss(load);
|
||||||
|
|
||||||
if (response.ok) {
|
if (response.ok) {
|
||||||
toast.success(`Updated!`);
|
toast.success(t("updated"));
|
||||||
onClose();
|
onClose();
|
||||||
} else toast.error(response.data as string);
|
} else {
|
||||||
|
toast.error(response.data as string);
|
||||||
|
}
|
||||||
|
|
||||||
setSubmitLoader(false);
|
setSubmitLoader(false);
|
||||||
|
|
||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Modal toggleModal={onClose}>
|
<Modal toggleModal={onClose}>
|
||||||
<p className="text-xl font-thin">Edit Link</p>
|
<p className="text-xl font-thin">{t("edit_link")}</p>
|
||||||
|
|
||||||
<div className="divider mb-3 mt-1"></div>
|
<div className="divider mb-3 mt-1"></div>
|
||||||
|
|
||||||
|
@ -87,42 +80,31 @@ export default function EditLinkModal({ onClose, activeLink }: Props) {
|
||||||
target="_blank"
|
target="_blank"
|
||||||
>
|
>
|
||||||
<i className="bi-link-45deg text-xl" />
|
<i className="bi-link-45deg text-xl" />
|
||||||
<p>{shortendURL}</p>
|
<p>{shortenedURL}</p>
|
||||||
</Link>
|
</Link>
|
||||||
) : undefined}
|
) : undefined}
|
||||||
|
|
||||||
<div className="w-full">
|
<div className="w-full">
|
||||||
<p className="mb-2">Name</p>
|
<p className="mb-2">{t("name")}</p>
|
||||||
<TextInput
|
<TextInput
|
||||||
value={link.name}
|
value={link.name}
|
||||||
onChange={(e) => setLink({ ...link, name: e.target.value })}
|
onChange={(e) => setLink({ ...link, name: e.target.value })}
|
||||||
placeholder="e.g. Example Link"
|
placeholder={t("placeholder_example_link")}
|
||||||
className="bg-base-200"
|
className="bg-base-200"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="mt-5">
|
<div className="mt-5">
|
||||||
{/* <hr className="mb-3 border border-neutral-content" /> */}
|
|
||||||
<div className="grid sm:grid-cols-2 gap-3">
|
<div className="grid sm:grid-cols-2 gap-3">
|
||||||
<div>
|
<div>
|
||||||
<p className="mb-2">Collection</p>
|
<p className="mb-2">{t("collection")}</p>
|
||||||
{link.collection.name ? (
|
{link.collection.name ? (
|
||||||
<CollectionSelection
|
<CollectionSelection
|
||||||
onChange={setCollection}
|
onChange={setCollection}
|
||||||
// defaultValue={{
|
|
||||||
// label: link.collection.name,
|
|
||||||
// value: link.collection.id,
|
|
||||||
// }}
|
|
||||||
defaultValue={
|
defaultValue={
|
||||||
link.collection.id
|
link.collection.id
|
||||||
? {
|
? { value: link.collection.id, label: link.collection.name }
|
||||||
value: link.collection.id,
|
: { value: null as unknown as number, label: "Unorganized" }
|
||||||
label: link.collection.name,
|
|
||||||
}
|
|
||||||
: {
|
|
||||||
value: null as unknown as number,
|
|
||||||
label: "Unorganized",
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
creatable={false}
|
creatable={false}
|
||||||
/>
|
/>
|
||||||
|
@ -130,23 +112,24 @@ export default function EditLinkModal({ onClose, activeLink }: Props) {
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div>
|
<div>
|
||||||
<p className="mb-2">Tags</p>
|
<p className="mb-2">{t("tags")}</p>
|
||||||
<TagSelection
|
<TagSelection
|
||||||
onChange={setTags}
|
onChange={setTags}
|
||||||
defaultValue={link.tags.map((e) => {
|
defaultValue={link.tags.map((e) => ({
|
||||||
return { label: e.name, value: e.id };
|
label: e.name,
|
||||||
})}
|
value: e.id,
|
||||||
|
}))}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="sm:col-span-2">
|
<div className="sm:col-span-2">
|
||||||
<p className="mb-2">Description</p>
|
<p className="mb-2">{t("description")}</p>
|
||||||
<textarea
|
<textarea
|
||||||
value={unescapeString(link.description) as string}
|
value={unescapeString(link.description) as string}
|
||||||
onChange={(e) =>
|
onChange={(e) =>
|
||||||
setLink({ ...link, description: e.target.value })
|
setLink({ ...link, description: e.target.value })
|
||||||
}
|
}
|
||||||
placeholder="Will be auto generated if nothing is provided."
|
placeholder={t("link_description_placeholder")}
|
||||||
className="resize-none w-full rounded-md p-2 border-neutral-content bg-base-200 focus:border-sky-300 dark:focus:border-sky-600 border-solid border outline-none duration-100"
|
className="resize-none w-full rounded-md p-2 border-neutral-content bg-base-200 focus:border-sky-300 dark:focus:border-sky-600 border-solid border outline-none duration-100"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
@ -158,7 +141,7 @@ export default function EditLinkModal({ onClose, activeLink }: Props) {
|
||||||
className="btn btn-accent dark:border-violet-400 text-white"
|
className="btn btn-accent dark:border-violet-400 text-white"
|
||||||
onClick={submit}
|
onClick={submit}
|
||||||
>
|
>
|
||||||
Save Changes
|
{t("save_changes")}
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
</Modal>
|
</Modal>
|
||||||
|
|
|
@ -0,0 +1,74 @@
|
||||||
|
import React, { useState } from "react";
|
||||||
|
import TextInput from "@/components/TextInput";
|
||||||
|
import Modal from "../Modal";
|
||||||
|
import { useTranslation } from "next-i18next";
|
||||||
|
|
||||||
|
type Props = {
|
||||||
|
onClose: Function;
|
||||||
|
onSubmit: Function;
|
||||||
|
oldEmail: string;
|
||||||
|
newEmail: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
export default function EmailChangeVerificationModal({
|
||||||
|
onClose,
|
||||||
|
onSubmit,
|
||||||
|
oldEmail,
|
||||||
|
newEmail,
|
||||||
|
}: Props) {
|
||||||
|
const { t } = useTranslation();
|
||||||
|
const [password, setPassword] = useState("");
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Modal toggleModal={onClose}>
|
||||||
|
<p className="text-xl font-thin">{t("confirm_password")}</p>
|
||||||
|
|
||||||
|
<div className="divider mb-3 mt-1"></div>
|
||||||
|
|
||||||
|
<div className="flex flex-col gap-5">
|
||||||
|
<p>
|
||||||
|
{t("password_change_warning")}
|
||||||
|
{process.env.NEXT_PUBLIC_STRIPE === "true" && t("stripe_update_note")}
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
{t("sso_will_be_removed_warning", {
|
||||||
|
service:
|
||||||
|
process.env.NEXT_PUBLIC_GOOGLE_ENABLED === "true" ? "Google" : "",
|
||||||
|
})}
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<p>{t("old_email")}</p>
|
||||||
|
<p className="text-neutral">{oldEmail}</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<p>{t("new_email")}</p>
|
||||||
|
<p className="text-neutral">{newEmail}</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="w-full">
|
||||||
|
<p className="mb-2">{t("password")}</p>
|
||||||
|
<TextInput
|
||||||
|
value={password}
|
||||||
|
onChange={(e) => setPassword(e.target.value)}
|
||||||
|
placeholder="••••••••••••••"
|
||||||
|
className="bg-base-200"
|
||||||
|
type="password"
|
||||||
|
autoFocus
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="flex justify-end items-center">
|
||||||
|
<button
|
||||||
|
className="btn btn-accent dark:border-violet-400 text-white"
|
||||||
|
onClick={() => onSubmit(password)}
|
||||||
|
>
|
||||||
|
{t("confirm")}
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</Modal>
|
||||||
|
);
|
||||||
|
}
|
|
@ -8,6 +8,7 @@ import Modal from "../Modal";
|
||||||
import { CollectionIncludingMembersAndLinkCount } from "@/types/global";
|
import { CollectionIncludingMembersAndLinkCount } from "@/types/global";
|
||||||
import useAccountStore from "@/store/account";
|
import useAccountStore from "@/store/account";
|
||||||
import { useSession } from "next-auth/react";
|
import { useSession } from "next-auth/react";
|
||||||
|
import { useTranslation } from "next-i18next";
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
onClose: Function;
|
onClose: Function;
|
||||||
|
@ -15,6 +16,7 @@ type Props = {
|
||||||
};
|
};
|
||||||
|
|
||||||
export default function NewCollectionModal({ onClose, parent }: Props) {
|
export default function NewCollectionModal({ onClose, parent }: Props) {
|
||||||
|
const { t } = useTranslation();
|
||||||
const initial = {
|
const initial = {
|
||||||
parentId: parent?.id,
|
parentId: parent?.id,
|
||||||
name: "",
|
name: "",
|
||||||
|
@ -39,15 +41,14 @@ export default function NewCollectionModal({ onClose, parent }: Props) {
|
||||||
|
|
||||||
setSubmitLoader(true);
|
setSubmitLoader(true);
|
||||||
|
|
||||||
const load = toast.loading("Creating...");
|
const load = toast.loading(t("creating"));
|
||||||
|
|
||||||
let response = await addCollection(collection as any);
|
let response = await addCollection(collection as any);
|
||||||
toast.dismiss(load);
|
toast.dismiss(load);
|
||||||
|
|
||||||
if (response.ok) {
|
if (response.ok) {
|
||||||
toast.success("Created!");
|
toast.success(t("created"));
|
||||||
if (response.data) {
|
if (response.data) {
|
||||||
// If the collection was created successfully, we need to get the new collection order
|
|
||||||
setAccount(data?.user.id as number);
|
setAccount(data?.user.id as number);
|
||||||
onClose();
|
onClose();
|
||||||
}
|
}
|
||||||
|
@ -60,11 +61,13 @@ export default function NewCollectionModal({ onClose, parent }: Props) {
|
||||||
<Modal toggleModal={onClose}>
|
<Modal toggleModal={onClose}>
|
||||||
{parent?.id ? (
|
{parent?.id ? (
|
||||||
<>
|
<>
|
||||||
<p className="text-xl font-thin">New Sub-Collection</p>
|
<p className="text-xl font-thin">{t("new_sub_collection")}</p>
|
||||||
<p className="capitalize text-sm">For {parent.name}</p>
|
<p className="capitalize text-sm">
|
||||||
|
{t("for_collection", { name: parent.name })}
|
||||||
|
</p>
|
||||||
</>
|
</>
|
||||||
) : (
|
) : (
|
||||||
<p className="text-xl font-thin">Create a New Collection</p>
|
<p className="text-xl font-thin">{t("create_new_collection")}</p>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
<div className="divider mb-3 mt-1"></div>
|
<div className="divider mb-3 mt-1"></div>
|
||||||
|
@ -72,19 +75,25 @@ export default function NewCollectionModal({ onClose, parent }: Props) {
|
||||||
<div className="flex flex-col gap-3">
|
<div className="flex flex-col gap-3">
|
||||||
<div className="flex flex-col sm:flex-row gap-3">
|
<div className="flex flex-col sm:flex-row gap-3">
|
||||||
<div className="w-full">
|
<div className="w-full">
|
||||||
<p className="mb-2">Name</p>
|
<p className="mb-2">{t("name")}</p>
|
||||||
<div className="flex flex-col gap-3">
|
<div className="flex flex-col gap-2">
|
||||||
<TextInput
|
<TextInput
|
||||||
className="bg-base-200"
|
className="bg-base-200"
|
||||||
value={collection.name}
|
value={collection.name}
|
||||||
placeholder="e.g. Example Collection"
|
placeholder={t("collection_name_placeholder")}
|
||||||
onChange={(e) =>
|
onChange={(e) =>
|
||||||
setCollection({ ...collection, name: e.target.value })
|
setCollection({ ...collection, name: e.target.value })
|
||||||
}
|
}
|
||||||
/>
|
/>
|
||||||
<div>
|
<div>
|
||||||
<p className="w-full mb-2">Color</p>
|
<p className="w-full mb-2">{t("color")}</p>
|
||||||
<div className="color-picker flex justify-between">
|
<div className="color-picker flex justify-between items-center">
|
||||||
|
<HexColorPicker
|
||||||
|
color={collection.color}
|
||||||
|
onChange={(color) =>
|
||||||
|
setCollection({ ...collection, color })
|
||||||
|
}
|
||||||
|
/>
|
||||||
<div className="flex flex-col gap-2 items-center w-32">
|
<div className="flex flex-col gap-2 items-center w-32">
|
||||||
<i
|
<i
|
||||||
className={"bi-folder-fill text-5xl"}
|
className={"bi-folder-fill text-5xl"}
|
||||||
|
@ -96,29 +105,22 @@ export default function NewCollectionModal({ onClose, parent }: Props) {
|
||||||
setCollection({ ...collection, color: "#0ea5e9" })
|
setCollection({ ...collection, color: "#0ea5e9" })
|
||||||
}
|
}
|
||||||
>
|
>
|
||||||
Reset
|
{t("reset")}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<HexColorPicker
|
|
||||||
color={collection.color}
|
|
||||||
onChange={(e) => setCollection({ ...collection, color: e })}
|
|
||||||
/>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="w-full">
|
<div className="w-full">
|
||||||
<p className="mb-2">Description</p>
|
<p className="mb-2">{t("description")}</p>
|
||||||
<textarea
|
<textarea
|
||||||
className="w-full h-[13rem] resize-none border rounded-md duration-100 bg-base-200 p-2 outline-none border-neutral-content focus:border-primary"
|
className="w-full h-[13rem] resize-none border rounded-md duration-100 bg-base-200 p-2 outline-none border-neutral-content focus:border-primary"
|
||||||
placeholder="The purpose of this Collection..."
|
placeholder={t("collection_description_placeholder")}
|
||||||
value={collection.description}
|
value={collection.description}
|
||||||
onChange={(e) =>
|
onChange={(e) =>
|
||||||
setCollection({
|
setCollection({ ...collection, description: e.target.value })
|
||||||
...collection,
|
|
||||||
description: e.target.value,
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
@ -128,7 +130,7 @@ export default function NewCollectionModal({ onClose, parent }: Props) {
|
||||||
className="btn btn-accent dark:border-violet-400 text-white w-fit ml-auto"
|
className="btn btn-accent dark:border-violet-400 text-white w-fit ml-auto"
|
||||||
onClick={submit}
|
onClick={submit}
|
||||||
>
|
>
|
||||||
Create Collection
|
{t("create_collection_button")}
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
</Modal>
|
</Modal>
|
||||||
|
|
|
@ -11,14 +11,15 @@ import { useSession } from "next-auth/react";
|
||||||
import { useRouter } from "next/router";
|
import { useRouter } from "next/router";
|
||||||
import toast from "react-hot-toast";
|
import toast from "react-hot-toast";
|
||||||
import Modal from "../Modal";
|
import Modal from "../Modal";
|
||||||
|
import { useTranslation } from "next-i18next";
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
onClose: Function;
|
onClose: Function;
|
||||||
};
|
};
|
||||||
|
|
||||||
export default function NewLinkModal({ onClose }: Props) {
|
export default function NewLinkModal({ onClose }: Props) {
|
||||||
|
const { t } = useTranslation();
|
||||||
const { data } = useSession();
|
const { data } = useSession();
|
||||||
|
|
||||||
const initial = {
|
const initial = {
|
||||||
name: "",
|
name: "",
|
||||||
url: "",
|
url: "",
|
||||||
|
@ -39,18 +40,14 @@ export default function NewLinkModal({ onClose }: Props) {
|
||||||
|
|
||||||
const [link, setLink] =
|
const [link, setLink] =
|
||||||
useState<LinkIncludingShortenedCollectionAndTags>(initial);
|
useState<LinkIncludingShortenedCollectionAndTags>(initial);
|
||||||
|
|
||||||
const { addLink } = useLinkStore();
|
const { addLink } = useLinkStore();
|
||||||
const [submitLoader, setSubmitLoader] = useState(false);
|
const [submitLoader, setSubmitLoader] = useState(false);
|
||||||
|
|
||||||
const [optionsExpanded, setOptionsExpanded] = useState(false);
|
const [optionsExpanded, setOptionsExpanded] = useState(false);
|
||||||
|
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
const { collections } = useCollectionStore();
|
const { collections } = useCollectionStore();
|
||||||
|
|
||||||
const setCollection = (e: any) => {
|
const setCollection = (e: any) => {
|
||||||
if (e?.__isNew__) e.value = null;
|
if (e?.__isNew__) e.value = null;
|
||||||
|
|
||||||
setLink({
|
setLink({
|
||||||
...link,
|
...link,
|
||||||
collection: { id: e?.value, name: e?.label, ownerId: e?.ownerId },
|
collection: { id: e?.value, name: e?.label, ownerId: e?.ownerId },
|
||||||
|
@ -58,10 +55,7 @@ export default function NewLinkModal({ onClose }: Props) {
|
||||||
};
|
};
|
||||||
|
|
||||||
const setTags = (e: any) => {
|
const setTags = (e: any) => {
|
||||||
const tagNames = e.map((e: any) => {
|
const tagNames = e.map((e: any) => ({ name: e.label }));
|
||||||
return { name: e.label };
|
|
||||||
});
|
|
||||||
|
|
||||||
setLink({ ...link, tags: tagNames });
|
setLink({ ...link, tags: tagNames });
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -70,7 +64,6 @@ export default function NewLinkModal({ onClose }: Props) {
|
||||||
const currentCollection = collections.find(
|
const currentCollection = collections.find(
|
||||||
(e) => e.id == Number(router.query.id)
|
(e) => e.id == Number(router.query.id)
|
||||||
);
|
);
|
||||||
|
|
||||||
if (
|
if (
|
||||||
currentCollection &&
|
currentCollection &&
|
||||||
currentCollection.ownerId &&
|
currentCollection.ownerId &&
|
||||||
|
@ -87,53 +80,42 @@ export default function NewLinkModal({ onClose }: Props) {
|
||||||
} else
|
} else
|
||||||
setLink({
|
setLink({
|
||||||
...initial,
|
...initial,
|
||||||
collection: {
|
collection: { name: "Unorganized", ownerId: data?.user.id as number },
|
||||||
name: "Unorganized",
|
|
||||||
ownerId: data?.user.id as number,
|
|
||||||
},
|
|
||||||
});
|
});
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
const submit = async () => {
|
const submit = async () => {
|
||||||
if (!submitLoader) {
|
if (!submitLoader) {
|
||||||
setSubmitLoader(true);
|
setSubmitLoader(true);
|
||||||
|
const load = toast.loading(t("creating_link"));
|
||||||
let response;
|
const response = await addLink(link);
|
||||||
|
|
||||||
const load = toast.loading("Creating...");
|
|
||||||
|
|
||||||
response = await addLink(link);
|
|
||||||
|
|
||||||
toast.dismiss(load);
|
toast.dismiss(load);
|
||||||
|
|
||||||
if (response.ok) {
|
if (response.ok) {
|
||||||
toast.success(`Created!`);
|
toast.success(t("link_created"));
|
||||||
onClose();
|
onClose();
|
||||||
} else toast.error(response.data as string);
|
} else {
|
||||||
|
toast.error(response.data as string);
|
||||||
|
}
|
||||||
setSubmitLoader(false);
|
setSubmitLoader(false);
|
||||||
|
|
||||||
return response;
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Modal toggleModal={onClose}>
|
<Modal toggleModal={onClose}>
|
||||||
<p className="text-xl font-thin">Create a New Link</p>
|
<p className="text-xl font-thin">{t("create_new_link")}</p>
|
||||||
|
|
||||||
<div className="divider mb-3 mt-1"></div>
|
<div className="divider mb-3 mt-1"></div>
|
||||||
|
|
||||||
<div className="grid grid-flow-row-dense sm:grid-cols-5 gap-3">
|
<div className="grid grid-flow-row-dense sm:grid-cols-5 gap-3">
|
||||||
<div className="sm:col-span-3 col-span-5">
|
<div className="sm:col-span-3 col-span-5">
|
||||||
<p className="mb-2">Link</p>
|
<p className="mb-2">{t("link")}</p>
|
||||||
<TextInput
|
<TextInput
|
||||||
value={link.url || ""}
|
value={link.url || ""}
|
||||||
onChange={(e) => setLink({ ...link, url: e.target.value })}
|
onChange={(e) => setLink({ ...link, url: e.target.value })}
|
||||||
placeholder="e.g. http://example.com/"
|
placeholder={t("link_url_placeholder")}
|
||||||
className="bg-base-200"
|
className="bg-base-200"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
<div className="sm:col-span-2 col-span-5">
|
<div className="sm:col-span-2 col-span-5">
|
||||||
<p className="mb-2">Collection</p>
|
<p className="mb-2">{t("collection")}</p>
|
||||||
{link.collection.name ? (
|
{link.collection.name ? (
|
||||||
<CollectionSelection
|
<CollectionSelection
|
||||||
onChange={setCollection}
|
onChange={setCollection}
|
||||||
|
@ -145,40 +127,37 @@ export default function NewLinkModal({ onClose }: Props) {
|
||||||
) : null}
|
) : null}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className={"mt-2"}>
|
<div className={"mt-2"}>
|
||||||
{optionsExpanded ? (
|
{optionsExpanded ? (
|
||||||
<div className="mt-5">
|
<div className="mt-5">
|
||||||
{/* <hr className="mb-3 border border-neutral-content" /> */}
|
|
||||||
<div className="grid sm:grid-cols-2 gap-3">
|
<div className="grid sm:grid-cols-2 gap-3">
|
||||||
<div>
|
<div>
|
||||||
<p className="mb-2">Name</p>
|
<p className="mb-2">{t("name")}</p>
|
||||||
<TextInput
|
<TextInput
|
||||||
value={link.name}
|
value={link.name}
|
||||||
onChange={(e) => setLink({ ...link, name: e.target.value })}
|
onChange={(e) => setLink({ ...link, name: e.target.value })}
|
||||||
placeholder="e.g. Example Link"
|
placeholder={t("link_name_placeholder")}
|
||||||
className="bg-base-200"
|
className="bg-base-200"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div>
|
<div>
|
||||||
<p className="mb-2">Tags</p>
|
<p className="mb-2">{t("tags")}</p>
|
||||||
<TagSelection
|
<TagSelection
|
||||||
onChange={setTags}
|
onChange={setTags}
|
||||||
defaultValue={link.tags.map((e) => {
|
defaultValue={link.tags.map((e) => ({
|
||||||
return { label: e.name, value: e.id };
|
label: e.name,
|
||||||
})}
|
value: e.id,
|
||||||
|
}))}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="sm:col-span-2">
|
<div className="sm:col-span-2">
|
||||||
<p className="mb-2">Description</p>
|
<p className="mb-2">{t("description")}</p>
|
||||||
<textarea
|
<textarea
|
||||||
value={unescapeString(link.description) as string}
|
value={unescapeString(link.description) as string}
|
||||||
onChange={(e) =>
|
onChange={(e) =>
|
||||||
setLink({ ...link, description: e.target.value })
|
setLink({ ...link, description: e.target.value })
|
||||||
}
|
}
|
||||||
placeholder="Will be auto generated if nothing is provided."
|
placeholder={t("link_description_placeholder")}
|
||||||
className="resize-none w-full rounded-md p-2 border-neutral-content bg-base-200 focus:border-primary border-solid border outline-none duration-100"
|
className="resize-none w-full rounded-md p-2 border-neutral-content bg-base-200 focus:border-primary border-solid border outline-none duration-100"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
@ -186,27 +165,19 @@ export default function NewLinkModal({ onClose }: Props) {
|
||||||
</div>
|
</div>
|
||||||
) : undefined}
|
) : undefined}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="flex justify-between items-center mt-5">
|
<div className="flex justify-between items-center mt-5">
|
||||||
<div
|
<div
|
||||||
onClick={() => setOptionsExpanded(!optionsExpanded)}
|
onClick={() => setOptionsExpanded(!optionsExpanded)}
|
||||||
className={`rounded-md cursor-pointer btn btn-sm btn-ghost duration-100 flex items-center px-2 w-fit text-sm`}
|
className={`rounded-md cursor-pointer btn btn-sm btn-ghost duration-100 flex items-center px-2 w-fit text-sm`}
|
||||||
>
|
>
|
||||||
<p className="font-normal">
|
<p>{optionsExpanded ? t("hide_options") : t("more_options")}</p>
|
||||||
{optionsExpanded ? "Hide" : "More"} Options
|
<i className={`bi-chevron-${optionsExpanded ? "up" : "down"}`}></i>
|
||||||
</p>
|
|
||||||
<i
|
|
||||||
className={`${
|
|
||||||
optionsExpanded ? "bi-chevron-up" : "bi-chevron-down"
|
|
||||||
}`}
|
|
||||||
></i>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<button
|
<button
|
||||||
className="btn btn-accent dark:border-violet-400 text-white"
|
className="btn btn-accent dark:border-violet-400 text-white"
|
||||||
onClick={submit}
|
onClick={submit}
|
||||||
>
|
>
|
||||||
Create Link
|
{t("create_link")}
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
</Modal>
|
</Modal>
|
||||||
|
|
|
@ -5,14 +5,16 @@ import toast from "react-hot-toast";
|
||||||
import Modal from "../Modal";
|
import Modal from "../Modal";
|
||||||
import useTokenStore from "@/store/tokens";
|
import useTokenStore from "@/store/tokens";
|
||||||
import { dropdownTriggerer } from "@/lib/client/utils";
|
import { dropdownTriggerer } from "@/lib/client/utils";
|
||||||
|
import Button from "../ui/Button";
|
||||||
|
import { useTranslation } from "next-i18next";
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
onClose: Function;
|
onClose: Function;
|
||||||
};
|
};
|
||||||
|
|
||||||
export default function NewTokenModal({ onClose }: Props) {
|
export default function NewTokenModal({ onClose }: Props) {
|
||||||
|
const { t } = useTranslation();
|
||||||
const [newToken, setNewToken] = useState("");
|
const [newToken, setNewToken] = useState("");
|
||||||
|
|
||||||
const { addToken } = useTokenStore();
|
const { addToken } = useTokenStore();
|
||||||
|
|
||||||
const initial = {
|
const initial = {
|
||||||
|
@ -21,21 +23,19 @@ export default function NewTokenModal({ onClose }: Props) {
|
||||||
};
|
};
|
||||||
|
|
||||||
const [token, setToken] = useState(initial as any);
|
const [token, setToken] = useState(initial as any);
|
||||||
|
|
||||||
const [submitLoader, setSubmitLoader] = useState(false);
|
const [submitLoader, setSubmitLoader] = useState(false);
|
||||||
|
|
||||||
const submit = async () => {
|
const submit = async () => {
|
||||||
if (!submitLoader) {
|
if (!submitLoader) {
|
||||||
setSubmitLoader(true);
|
setSubmitLoader(true);
|
||||||
|
const load = toast.loading(t("creating_token"));
|
||||||
const load = toast.loading("Creating...");
|
|
||||||
|
|
||||||
const { ok, data } = await addToken(token);
|
const { ok, data } = await addToken(token);
|
||||||
|
|
||||||
toast.dismiss(load);
|
toast.dismiss(load);
|
||||||
|
|
||||||
if (ok) {
|
if (ok) {
|
||||||
toast.success(`Created!`);
|
toast.success(t("token_created"));
|
||||||
setNewToken((data as any).secretKey);
|
setNewToken((data as any).secretKey);
|
||||||
} else toast.error(data as string);
|
} else toast.error(data as string);
|
||||||
|
|
||||||
|
@ -43,15 +43,27 @@ export default function NewTokenModal({ onClose }: Props) {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const getLabel = (expiry: TokenExpiry) => {
|
||||||
|
switch (expiry) {
|
||||||
|
case TokenExpiry.sevenDays:
|
||||||
|
return t("7_days");
|
||||||
|
case TokenExpiry.oneMonth:
|
||||||
|
return t("30_days");
|
||||||
|
case TokenExpiry.twoMonths:
|
||||||
|
return t("60_days");
|
||||||
|
case TokenExpiry.threeMonths:
|
||||||
|
return t("90_days");
|
||||||
|
case TokenExpiry.never:
|
||||||
|
return t("no_expiration");
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Modal toggleModal={onClose}>
|
<Modal toggleModal={onClose}>
|
||||||
{newToken ? (
|
{newToken ? (
|
||||||
<div className="flex flex-col justify-center space-y-4">
|
<div className="flex flex-col justify-center space-y-4">
|
||||||
<p className="text-xl font-thin">Access Token Created</p>
|
<p className="text-xl font-thin">{t("access_token_created")}</p>
|
||||||
<p>
|
<p>{t("token_creation_notice")}</p>
|
||||||
Your new token has been created. Please copy it and store it
|
|
||||||
somewhere safe. You will not be able to see it again.
|
|
||||||
</p>
|
|
||||||
<TextInput
|
<TextInput
|
||||||
spellCheck={false}
|
spellCheck={false}
|
||||||
value={newToken}
|
value={newToken}
|
||||||
|
@ -61,47 +73,44 @@ export default function NewTokenModal({ onClose }: Props) {
|
||||||
<button
|
<button
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
navigator.clipboard.writeText(newToken);
|
navigator.clipboard.writeText(newToken);
|
||||||
toast.success("Copied to clipboard!");
|
toast.success(t("copied_to_clipboard"));
|
||||||
}}
|
}}
|
||||||
className="btn btn-primary w-fit mx-auto"
|
className="btn btn-primary w-fit mx-auto"
|
||||||
>
|
>
|
||||||
Copy to Clipboard
|
{t("copy_to_clipboard")}
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
) : (
|
) : (
|
||||||
<>
|
<>
|
||||||
<p className="text-xl font-thin">Create an Access Token</p>
|
<p className="text-xl font-thin">{t("create_access_token")}</p>
|
||||||
|
|
||||||
<div className="divider mb-3 mt-1"></div>
|
<div className="divider mb-3 mt-1"></div>
|
||||||
|
|
||||||
<div className="flex sm:flex-row flex-col gap-2 items-center">
|
<div className="flex sm:flex-row flex-col gap-2 items-center">
|
||||||
<div className="w-full">
|
<div className="w-full">
|
||||||
<p className="mb-2">Name</p>
|
<p className="mb-2">{t("name")}</p>
|
||||||
|
|
||||||
<TextInput
|
<TextInput
|
||||||
value={token.name}
|
value={token.name}
|
||||||
onChange={(e) => setToken({ ...token, name: e.target.value })}
|
onChange={(e) => setToken({ ...token, name: e.target.value })}
|
||||||
placeholder="e.g. For the iOS shortcut"
|
placeholder={t("token_name_placeholder")}
|
||||||
className="bg-base-200"
|
className="bg-base-200"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="w-full sm:w-fit">
|
<div className="w-full sm:w-fit">
|
||||||
<p className="mb-2">Expires in</p>
|
<p className="mb-2">{t("expires_in")}</p>
|
||||||
|
|
||||||
<div className="dropdown dropdown-bottom dropdown-end w-full">
|
<div className="dropdown dropdown-bottom dropdown-end w-full">
|
||||||
<div
|
<Button
|
||||||
tabIndex={0}
|
tabIndex={0}
|
||||||
role="button"
|
role="button"
|
||||||
|
intent="secondary"
|
||||||
onMouseDown={dropdownTriggerer}
|
onMouseDown={dropdownTriggerer}
|
||||||
className="btn btn-outline w-full sm:w-36 flex items-center btn-sm h-10"
|
className="whitespace-nowrap w-32"
|
||||||
>
|
>
|
||||||
{token.expires === TokenExpiry.sevenDays && "7 Days"}
|
{getLabel(token.expires)}
|
||||||
{token.expires === TokenExpiry.oneMonth && "30 Days"}
|
</Button>
|
||||||
{token.expires === TokenExpiry.twoMonths && "60 Days"}
|
|
||||||
{token.expires === TokenExpiry.threeMonths && "90 Days"}
|
|
||||||
{token.expires === TokenExpiry.never && "No Expiration"}
|
|
||||||
</div>
|
|
||||||
<ul className="dropdown-content z-[30] menu shadow bg-base-200 border border-neutral-content rounded-xl w-full sm:w-52 mt-1">
|
<ul className="dropdown-content z-[30] menu shadow bg-base-200 border border-neutral-content rounded-xl w-full sm:w-52 mt-1">
|
||||||
<li>
|
<li>
|
||||||
<label
|
<label
|
||||||
|
@ -122,7 +131,7 @@ export default function NewTokenModal({ onClose }: Props) {
|
||||||
});
|
});
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
<span className="label-text">7 Days</span>
|
<span className="label-text">{t("7_days")}</span>
|
||||||
</label>
|
</label>
|
||||||
</li>
|
</li>
|
||||||
<li>
|
<li>
|
||||||
|
@ -141,7 +150,7 @@ export default function NewTokenModal({ onClose }: Props) {
|
||||||
setToken({ ...token, expires: TokenExpiry.oneMonth });
|
setToken({ ...token, expires: TokenExpiry.oneMonth });
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
<span className="label-text">30 Days</span>
|
<span className="label-text">{t("30_days")}</span>
|
||||||
</label>
|
</label>
|
||||||
</li>
|
</li>
|
||||||
<li>
|
<li>
|
||||||
|
@ -163,7 +172,7 @@ export default function NewTokenModal({ onClose }: Props) {
|
||||||
});
|
});
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
<span className="label-text">60 Days</span>
|
<span className="label-text">{t("60_days")}</span>
|
||||||
</label>
|
</label>
|
||||||
</li>
|
</li>
|
||||||
<li>
|
<li>
|
||||||
|
@ -185,7 +194,7 @@ export default function NewTokenModal({ onClose }: Props) {
|
||||||
});
|
});
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
<span className="label-text">90 Days</span>
|
<span className="label-text">{t("90_days")}</span>
|
||||||
</label>
|
</label>
|
||||||
</li>
|
</li>
|
||||||
<li>
|
<li>
|
||||||
|
@ -204,7 +213,7 @@ export default function NewTokenModal({ onClose }: Props) {
|
||||||
setToken({ ...token, expires: TokenExpiry.never });
|
setToken({ ...token, expires: TokenExpiry.never });
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
<span className="label-text">No Expiration</span>
|
<span className="label-text">{t("no_expiration")}</span>
|
||||||
</label>
|
</label>
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
|
@ -217,7 +226,7 @@ export default function NewTokenModal({ onClose }: Props) {
|
||||||
className="btn btn-accent dark:border-violet-400 text-white"
|
className="btn btn-accent dark:border-violet-400 text-white"
|
||||||
onClick={submit}
|
onClick={submit}
|
||||||
>
|
>
|
||||||
Create Access Token
|
{t("create_token")}
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
</>
|
</>
|
||||||
|
|
|
@ -0,0 +1,148 @@
|
||||||
|
import toast from "react-hot-toast";
|
||||||
|
import Modal from "../Modal";
|
||||||
|
import useUserStore from "@/store/admin/users";
|
||||||
|
import TextInput from "../TextInput";
|
||||||
|
import { FormEvent, useState } from "react";
|
||||||
|
import { useTranslation, Trans } from "next-i18next";
|
||||||
|
|
||||||
|
type Props = {
|
||||||
|
onClose: Function;
|
||||||
|
};
|
||||||
|
|
||||||
|
type FormData = {
|
||||||
|
name: string;
|
||||||
|
username?: string;
|
||||||
|
email?: string;
|
||||||
|
password: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
const emailEnabled = process.env.NEXT_PUBLIC_EMAIL_PROVIDER === "true";
|
||||||
|
|
||||||
|
export default function NewUserModal({ onClose }: Props) {
|
||||||
|
const { t } = useTranslation();
|
||||||
|
const { addUser } = useUserStore();
|
||||||
|
const [form, setForm] = useState<FormData>({
|
||||||
|
name: "",
|
||||||
|
username: "",
|
||||||
|
email: emailEnabled ? "" : undefined,
|
||||||
|
password: "",
|
||||||
|
});
|
||||||
|
const [submitLoader, setSubmitLoader] = useState(false);
|
||||||
|
|
||||||
|
async function submit(event: FormEvent<HTMLFormElement>) {
|
||||||
|
event.preventDefault();
|
||||||
|
|
||||||
|
if (!submitLoader) {
|
||||||
|
const checkFields = () => {
|
||||||
|
if (emailEnabled) {
|
||||||
|
return form.name !== "" && form.email !== "" && form.password !== "";
|
||||||
|
} else {
|
||||||
|
return (
|
||||||
|
form.name !== "" && form.username !== "" && form.password !== ""
|
||||||
|
);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
if (checkFields()) {
|
||||||
|
if (form.password.length < 8)
|
||||||
|
return toast.error(t("password_length_error"));
|
||||||
|
|
||||||
|
setSubmitLoader(true);
|
||||||
|
|
||||||
|
const load = toast.loading(t("creating_account"));
|
||||||
|
|
||||||
|
const response = await addUser(form);
|
||||||
|
|
||||||
|
toast.dismiss(load);
|
||||||
|
setSubmitLoader(false);
|
||||||
|
|
||||||
|
if (response.ok) {
|
||||||
|
toast.success(t("user_created"));
|
||||||
|
onClose();
|
||||||
|
} else {
|
||||||
|
toast.error(response.data as string);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
toast.error(t("fill_all_fields_error"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Modal toggleModal={onClose}>
|
||||||
|
<p className="text-xl font-thin">{t("create_new_user")}</p>
|
||||||
|
|
||||||
|
<div className="divider mb-3 mt-1"></div>
|
||||||
|
|
||||||
|
<form onSubmit={submit}>
|
||||||
|
<div className="grid sm:grid-cols-2 gap-3">
|
||||||
|
<div>
|
||||||
|
<p className="mb-2">{t("display_name")}</p>
|
||||||
|
<TextInput
|
||||||
|
placeholder={t("placeholder_johnny")}
|
||||||
|
className="bg-base-200"
|
||||||
|
onChange={(e) => setForm({ ...form, name: e.target.value })}
|
||||||
|
value={form.name}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{emailEnabled ? (
|
||||||
|
<div>
|
||||||
|
<p className="mb-2">{t("email")}</p>
|
||||||
|
<TextInput
|
||||||
|
placeholder={t("placeholder_email")}
|
||||||
|
className="bg-base-200"
|
||||||
|
onChange={(e) => setForm({ ...form, email: e.target.value })}
|
||||||
|
value={form.email}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
) : undefined}
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<p className="mb-2">
|
||||||
|
{t("username")}{" "}
|
||||||
|
{emailEnabled && (
|
||||||
|
<span className="text-xs text-neutral">{t("optional")}</span>
|
||||||
|
)}
|
||||||
|
</p>
|
||||||
|
<TextInput
|
||||||
|
placeholder={t("placeholder_john")}
|
||||||
|
className="bg-base-200"
|
||||||
|
onChange={(e) => setForm({ ...form, username: e.target.value })}
|
||||||
|
value={form.username}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<p className="mb-2">{t("password")}</p>
|
||||||
|
<TextInput
|
||||||
|
placeholder="••••••••••••••"
|
||||||
|
className="bg-base-200"
|
||||||
|
onChange={(e) => setForm({ ...form, password: e.target.value })}
|
||||||
|
value={form.password}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div role="note" className="alert alert-note mt-5">
|
||||||
|
<i className="bi-exclamation-triangle text-xl" />
|
||||||
|
<span>
|
||||||
|
<Trans
|
||||||
|
i18nKey="password_change_note"
|
||||||
|
components={[<b key={0} />]}
|
||||||
|
/>
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="flex justify-between items-center mt-5">
|
||||||
|
<button
|
||||||
|
className="btn btn-accent dark:border-violet-400 text-white ml-auto"
|
||||||
|
type="submit"
|
||||||
|
>
|
||||||
|
{t("create_user")}
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</Modal>
|
||||||
|
);
|
||||||
|
}
|
|
@ -1,8 +1,8 @@
|
||||||
import React, { useEffect, useState } from "react";
|
import React, { useEffect, useState } from "react";
|
||||||
import useLinkStore from "@/store/links";
|
import useLinkStore from "@/store/links";
|
||||||
import {
|
import {
|
||||||
ArchivedFormat,
|
|
||||||
LinkIncludingShortenedCollectionAndTags,
|
LinkIncludingShortenedCollectionAndTags,
|
||||||
|
ArchivedFormat,
|
||||||
} from "@/types/global";
|
} from "@/types/global";
|
||||||
import toast from "react-hot-toast";
|
import toast from "react-hot-toast";
|
||||||
import Link from "next/link";
|
import Link from "next/link";
|
||||||
|
@ -18,6 +18,7 @@ import {
|
||||||
import PreservedFormatRow from "@/components/PreserverdFormatRow";
|
import PreservedFormatRow from "@/components/PreserverdFormatRow";
|
||||||
import useAccountStore from "@/store/account";
|
import useAccountStore from "@/store/account";
|
||||||
import getPublicUserData from "@/lib/client/getPublicUserData";
|
import getPublicUserData from "@/lib/client/getPublicUserData";
|
||||||
|
import { useTranslation } from "next-i18next";
|
||||||
import { BeatLoader } from "react-spinners";
|
import { BeatLoader } from "react-spinners";
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
|
@ -26,14 +27,12 @@ type Props = {
|
||||||
};
|
};
|
||||||
|
|
||||||
export default function PreservedFormatsModal({ onClose, activeLink }: Props) {
|
export default function PreservedFormatsModal({ onClose, activeLink }: Props) {
|
||||||
|
const { t } = useTranslation();
|
||||||
const session = useSession();
|
const session = useSession();
|
||||||
const { getLink } = useLinkStore();
|
const { getLink } = useLinkStore();
|
||||||
|
|
||||||
const { account } = useAccountStore();
|
const { account } = useAccountStore();
|
||||||
|
|
||||||
const [link, setLink] =
|
const [link, setLink] =
|
||||||
useState<LinkIncludingShortenedCollectionAndTags>(activeLink);
|
useState<LinkIncludingShortenedCollectionAndTags>(activeLink);
|
||||||
|
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
|
|
||||||
let isPublic = router.pathname.startsWith("/public") ? true : undefined;
|
let isPublic = router.pathname.startsWith("/public") ? true : undefined;
|
||||||
|
@ -125,17 +124,16 @@ export default function PreservedFormatsModal({ onClose, activeLink }: Props) {
|
||||||
clearInterval(interval);
|
clearInterval(interval);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}, [link?.image, link?.pdf, link?.readable, link?.singlefile]);
|
}, [link, getLink, link?.singlefile]);
|
||||||
|
|
||||||
const updateArchive = async () => {
|
const updateArchive = async () => {
|
||||||
const load = toast.loading("Sending request...");
|
const load = toast.loading(t("sending_request"));
|
||||||
|
|
||||||
const response = await fetch(`/api/v1/links/${link?.id}/archive`, {
|
const response = await fetch(`/api/v1/links/${link?.id}/archive`, {
|
||||||
method: "PUT",
|
method: "PUT",
|
||||||
});
|
});
|
||||||
|
|
||||||
const data = await response.json();
|
const data = await response.json();
|
||||||
|
|
||||||
toast.dismiss(load);
|
toast.dismiss(load);
|
||||||
|
|
||||||
if (response.ok) {
|
if (response.ok) {
|
||||||
|
@ -143,23 +141,19 @@ export default function PreservedFormatsModal({ onClose, activeLink }: Props) {
|
||||||
setLink(
|
setLink(
|
||||||
(newLink as any).response as LinkIncludingShortenedCollectionAndTags
|
(newLink as any).response as LinkIncludingShortenedCollectionAndTags
|
||||||
);
|
);
|
||||||
toast.success(`Link is being archived...`);
|
toast.success(t("link_being_archived"));
|
||||||
} else toast.error(data.response);
|
} else toast.error(data.response);
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Modal toggleModal={onClose}>
|
<Modal toggleModal={onClose}>
|
||||||
<p className="text-xl font-thin">Preserved Formats</p>
|
<p className="text-xl font-thin">{t("preserved_formats")}</p>
|
||||||
|
|
||||||
<div className="divider mb-2 mt-1"></div>
|
<div className="divider mb-2 mt-1"></div>
|
||||||
|
|
||||||
{screenshotAvailable(link) ||
|
{screenshotAvailable(link) ||
|
||||||
pdfAvailable(link) ||
|
pdfAvailable(link) ||
|
||||||
readabilityAvailable(link) ||
|
readabilityAvailable(link) ||
|
||||||
singlefileAvailable(link) ? (
|
singlefileAvailable(link) ? (
|
||||||
<p className="mb-3">
|
<p className="mb-3">{t("available_formats")}</p>
|
||||||
The following formats are available for this link:
|
|
||||||
</p>
|
|
||||||
) : (
|
) : (
|
||||||
""
|
""
|
||||||
)}
|
)}
|
||||||
|
@ -167,7 +161,7 @@ export default function PreservedFormatsModal({ onClose, activeLink }: Props) {
|
||||||
<div className={`flex flex-col gap-3`}>
|
<div className={`flex flex-col gap-3`}>
|
||||||
{screenshotAvailable(link) ? (
|
{screenshotAvailable(link) ? (
|
||||||
<PreservedFormatRow
|
<PreservedFormatRow
|
||||||
name={"Screenshot"}
|
name={t("screenshot")}
|
||||||
icon={"bi-file-earmark-image"}
|
icon={"bi-file-earmark-image"}
|
||||||
format={
|
format={
|
||||||
link?.image?.endsWith("png")
|
link?.image?.endsWith("png")
|
||||||
|
@ -181,7 +175,7 @@ export default function PreservedFormatsModal({ onClose, activeLink }: Props) {
|
||||||
|
|
||||||
{pdfAvailable(link) ? (
|
{pdfAvailable(link) ? (
|
||||||
<PreservedFormatRow
|
<PreservedFormatRow
|
||||||
name={"PDF"}
|
name={t("pdf")}
|
||||||
icon={"bi-file-earmark-pdf"}
|
icon={"bi-file-earmark-pdf"}
|
||||||
format={ArchivedFormat.pdf}
|
format={ArchivedFormat.pdf}
|
||||||
activeLink={link}
|
activeLink={link}
|
||||||
|
@ -189,19 +183,9 @@ export default function PreservedFormatsModal({ onClose, activeLink }: Props) {
|
||||||
/>
|
/>
|
||||||
) : undefined}
|
) : undefined}
|
||||||
|
|
||||||
{singlefileAvailable(link) ? (
|
|
||||||
<PreservedFormatRow
|
|
||||||
name={"SingleFile (Full Copy)"}
|
|
||||||
icon={"bi-filetype-html"}
|
|
||||||
format={ArchivedFormat.singlefile}
|
|
||||||
activeLink={link}
|
|
||||||
downloadable={true}
|
|
||||||
/>
|
|
||||||
) : undefined}
|
|
||||||
|
|
||||||
{readabilityAvailable(link) ? (
|
{readabilityAvailable(link) ? (
|
||||||
<PreservedFormatRow
|
<PreservedFormatRow
|
||||||
name={"Readable"}
|
name={t("readable")}
|
||||||
icon={"bi-file-earmark-text"}
|
icon={"bi-file-earmark-text"}
|
||||||
format={ArchivedFormat.readability}
|
format={ArchivedFormat.readability}
|
||||||
activeLink={link}
|
activeLink={link}
|
||||||
|
@ -216,12 +200,8 @@ export default function PreservedFormatsModal({ onClose, activeLink }: Props) {
|
||||||
size={30}
|
size={30}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<p className="text-center text-2xl">
|
<p className="text-center text-2xl">{t("preservation_in_queue")}</p>
|
||||||
Link preservation is in the queue
|
<p className="text-center text-lg">{t("check_back_later")}</p>
|
||||||
</p>
|
|
||||||
<p className="text-center text-lg">
|
|
||||||
Please check back later to see the result
|
|
||||||
</p>
|
|
||||||
</div>
|
</div>
|
||||||
) : !isReady() && atLeastOneFormatAvailable() ? (
|
) : !isReady() && atLeastOneFormatAvailable() ? (
|
||||||
<div className={`w-full h-full flex flex-col justify-center p-5`}>
|
<div className={`w-full h-full flex flex-col justify-center p-5`}>
|
||||||
|
@ -234,9 +214,7 @@ export default function PreservedFormatsModal({ onClose, activeLink }: Props) {
|
||||||
<p className="text-center">
|
<p className="text-center">
|
||||||
There are more preserved formats in the queue
|
There are more preserved formats in the queue
|
||||||
</p>
|
</p>
|
||||||
<p className="text-center text-sm">
|
<p className="text-center text-sm">{t("check_back_later")}</p>
|
||||||
Please check back later to see the result
|
|
||||||
</p>
|
|
||||||
</div>
|
</div>
|
||||||
) : undefined}
|
) : undefined}
|
||||||
|
|
||||||
|
@ -251,23 +229,21 @@ export default function PreservedFormatsModal({ onClose, activeLink }: Props) {
|
||||||
""
|
""
|
||||||
)}`}
|
)}`}
|
||||||
target="_blank"
|
target="_blank"
|
||||||
className={`text-neutral duration-100 hover:opacity-60 flex gap-2 w-1/2 justify-center items-center text-sm`}
|
className="text-neutral duration-100 hover:opacity-60 flex gap-2 w-1/2 justify-center items-center text-sm"
|
||||||
>
|
>
|
||||||
<p className="whitespace-nowrap">
|
<p className="whitespace-nowrap">{t("view_latest_snapshot")}</p>
|
||||||
View latest snapshot on archive.org
|
|
||||||
</p>
|
|
||||||
<i className="bi-box-arrow-up-right" />
|
<i className="bi-box-arrow-up-right" />
|
||||||
</Link>
|
</Link>
|
||||||
{link?.collection.ownerId === session.data?.user.id ? (
|
{link?.collection.ownerId === session.data?.user.id && (
|
||||||
<div className={`btn btn-outline`} onClick={() => updateArchive()}>
|
<div className="btn btn-outline" onClick={updateArchive}>
|
||||||
<div>
|
<div>
|
||||||
<p>Refresh Preserved Formats</p>
|
<p>{t("refresh_preserved_formats")}</p>
|
||||||
<p className="text-xs">
|
<p className="text-xs">
|
||||||
This deletes the current preservations
|
{t("this_deletes_current_preservations")}
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
) : undefined}
|
)}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</Modal>
|
</Modal>
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
import React, { useEffect, useState } from "react";
|
import React, { useEffect, useState } from "react";
|
||||||
import useLinkStore from "@/store/links";
|
import useTokenStore from "@/store/tokens";
|
||||||
import toast from "react-hot-toast";
|
import toast from "react-hot-toast";
|
||||||
import Modal from "../Modal";
|
import Modal from "../Modal";
|
||||||
import { useRouter } from "next/router";
|
import Button from "../ui/Button";
|
||||||
|
import { useTranslation } from "next-i18next";
|
||||||
import { AccessToken } from "@prisma/client";
|
import { AccessToken } from "@prisma/client";
|
||||||
import useTokenStore from "@/store/tokens";
|
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
onClose: Function;
|
onClose: Function;
|
||||||
|
@ -12,50 +12,42 @@ type Props = {
|
||||||
};
|
};
|
||||||
|
|
||||||
export default function DeleteTokenModal({ onClose, activeToken }: Props) {
|
export default function DeleteTokenModal({ onClose, activeToken }: Props) {
|
||||||
|
const { t } = useTranslation();
|
||||||
const [token, setToken] = useState<AccessToken>(activeToken);
|
const [token, setToken] = useState<AccessToken>(activeToken);
|
||||||
|
|
||||||
const { revokeToken } = useTokenStore();
|
const { revokeToken } = useTokenStore();
|
||||||
const [submitLoader, setSubmitLoader] = useState(false);
|
|
||||||
|
|
||||||
const router = useRouter();
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
setToken(activeToken);
|
setToken(activeToken);
|
||||||
}, []);
|
}, [activeToken]);
|
||||||
|
|
||||||
const deleteLink = async () => {
|
const deleteLink = async () => {
|
||||||
console.log(token);
|
const load = toast.loading(t("deleting"));
|
||||||
const load = toast.loading("Deleting...");
|
|
||||||
|
|
||||||
const response = await revokeToken(token.id as number);
|
const response = await revokeToken(token.id as number);
|
||||||
|
|
||||||
toast.dismiss(load);
|
toast.dismiss(load);
|
||||||
|
|
||||||
response.ok && toast.success(`Token Revoked.`);
|
if (response.ok) {
|
||||||
|
toast.success(t("token_revoked"));
|
||||||
|
}
|
||||||
|
|
||||||
onClose();
|
onClose();
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Modal toggleModal={onClose}>
|
<Modal toggleModal={onClose}>
|
||||||
<p className="text-xl font-thin text-red-500">Revoke Token</p>
|
<p className="text-xl font-thin text-red-500">{t("revoke_token")}</p>
|
||||||
|
|
||||||
<div className="divider mb-3 mt-1"></div>
|
<div className="divider mb-3 mt-1"></div>
|
||||||
|
|
||||||
<div className="flex flex-col gap-3">
|
<div className="flex flex-col gap-3">
|
||||||
<p>
|
<p>{t("revoke_confirmation")}</p>
|
||||||
Are you sure you want to revoke this Access Token? Any apps or
|
|
||||||
services using this token will no longer be able to access Linkwarden
|
|
||||||
using it.
|
|
||||||
</p>
|
|
||||||
|
|
||||||
<button
|
<Button className="ml-auto" intent="destructive" onClick={deleteLink}>
|
||||||
className={`ml-auto btn w-fit text-white flex items-center gap-2 duration-100 bg-red-500 hover:bg-red-400 hover:dark:bg-red-600 cursor-pointer`}
|
|
||||||
onClick={deleteLink}
|
|
||||||
>
|
|
||||||
<i className="bi-trash text-xl" />
|
<i className="bi-trash text-xl" />
|
||||||
Revoke
|
{t("revoke")}
|
||||||
</button>
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
</Modal>
|
</Modal>
|
||||||
);
|
);
|
||||||
|
|
|
@ -5,20 +5,19 @@ import TextInput from "@/components/TextInput";
|
||||||
import unescapeString from "@/lib/client/unescapeString";
|
import unescapeString from "@/lib/client/unescapeString";
|
||||||
import useCollectionStore from "@/store/collections";
|
import useCollectionStore from "@/store/collections";
|
||||||
import useLinkStore from "@/store/links";
|
import useLinkStore from "@/store/links";
|
||||||
import {
|
import { LinkIncludingShortenedCollectionAndTags } from "@/types/global";
|
||||||
ArchivedFormat,
|
|
||||||
LinkIncludingShortenedCollectionAndTags,
|
|
||||||
} from "@/types/global";
|
|
||||||
import { useSession } from "next-auth/react";
|
import { useSession } from "next-auth/react";
|
||||||
import { useRouter } from "next/router";
|
import { useRouter } from "next/router";
|
||||||
import toast from "react-hot-toast";
|
import toast from "react-hot-toast";
|
||||||
import Modal from "../Modal";
|
import Modal from "../Modal";
|
||||||
|
import { useTranslation } from "next-i18next";
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
onClose: Function;
|
onClose: Function;
|
||||||
};
|
};
|
||||||
|
|
||||||
export default function UploadFileModal({ onClose }: Props) {
|
export default function UploadFileModal({ onClose }: Props) {
|
||||||
|
const { t } = useTranslation();
|
||||||
const { data } = useSession();
|
const { data } = useSession();
|
||||||
|
|
||||||
const initial = {
|
const initial = {
|
||||||
|
@ -41,14 +40,11 @@ export default function UploadFileModal({ onClose }: Props) {
|
||||||
|
|
||||||
const [link, setLink] =
|
const [link, setLink] =
|
||||||
useState<LinkIncludingShortenedCollectionAndTags>(initial);
|
useState<LinkIncludingShortenedCollectionAndTags>(initial);
|
||||||
|
|
||||||
const [file, setFile] = useState<File>();
|
const [file, setFile] = useState<File>();
|
||||||
|
|
||||||
const { addLink } = useLinkStore();
|
const { uploadFile } = useLinkStore();
|
||||||
const [submitLoader, setSubmitLoader] = useState(false);
|
const [submitLoader, setSubmitLoader] = useState(false);
|
||||||
|
|
||||||
const [optionsExpanded, setOptionsExpanded] = useState(false);
|
const [optionsExpanded, setOptionsExpanded] = useState(false);
|
||||||
|
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
const { collections } = useCollectionStore();
|
const { collections } = useCollectionStore();
|
||||||
|
|
||||||
|
@ -75,7 +71,6 @@ export default function UploadFileModal({ onClose }: Props) {
|
||||||
const currentCollection = collections.find(
|
const currentCollection = collections.find(
|
||||||
(e) => e.id == Number(router.query.id)
|
(e) => e.id == Number(router.query.id)
|
||||||
);
|
);
|
||||||
|
|
||||||
if (
|
if (
|
||||||
currentCollection &&
|
currentCollection &&
|
||||||
currentCollection.ownerId &&
|
currentCollection.ownerId &&
|
||||||
|
@ -92,12 +87,9 @@ export default function UploadFileModal({ onClose }: Props) {
|
||||||
} else
|
} else
|
||||||
setLink({
|
setLink({
|
||||||
...initial,
|
...initial,
|
||||||
collection: {
|
collection: { name: "Unorganized", ownerId: data?.user.id as number },
|
||||||
name: "Unorganized",
|
|
||||||
ownerId: data?.user.id as number,
|
|
||||||
},
|
|
||||||
});
|
});
|
||||||
}, []);
|
}, [router, collections]);
|
||||||
|
|
||||||
const submit = async () => {
|
const submit = async () => {
|
||||||
if (!submitLoader && file) {
|
if (!submitLoader && file) {
|
||||||
|
@ -123,49 +115,32 @@ export default function UploadFileModal({ onClose }: Props) {
|
||||||
|
|
||||||
let response;
|
let response;
|
||||||
|
|
||||||
const load = toast.loading("Creating...");
|
const load = toast.loading(t("creating"));
|
||||||
|
|
||||||
response = await addLink({
|
const response = await uploadFile(link, file);
|
||||||
...link,
|
|
||||||
type: linkType,
|
|
||||||
name: link.name ? link.name : file.name.replace(/\.[^/.]+$/, ""),
|
|
||||||
});
|
|
||||||
|
|
||||||
toast.dismiss(load);
|
toast.dismiss(load);
|
||||||
|
|
||||||
if (response.ok) {
|
if (response.ok) {
|
||||||
const formBody = new FormData();
|
toast.success(t("created"));
|
||||||
file && formBody.append("file", file);
|
|
||||||
|
|
||||||
await fetch(
|
|
||||||
`/api/v1/archives/${
|
|
||||||
(response.data as LinkIncludingShortenedCollectionAndTags).id
|
|
||||||
}?format=${fileType}`,
|
|
||||||
{
|
|
||||||
body: formBody,
|
|
||||||
method: "POST",
|
|
||||||
}
|
|
||||||
);
|
|
||||||
toast.success(`Created!`);
|
|
||||||
onClose();
|
onClose();
|
||||||
} else toast.error(response.data as string);
|
} else {
|
||||||
|
toast.error(response.data as string);
|
||||||
|
}
|
||||||
|
|
||||||
setSubmitLoader(false);
|
setSubmitLoader(false);
|
||||||
|
|
||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Modal toggleModal={onClose}>
|
<Modal toggleModal={onClose}>
|
||||||
<div className="flex gap-2 items-start">
|
<div className="flex gap-2 items-start">
|
||||||
<p className="text-xl font-thin">Upload File</p>
|
<p className="text-xl font-thin">{t("upload_file")}</p>
|
||||||
</div>
|
</div>
|
||||||
<div className="divider mb-3 mt-1"></div>
|
<div className="divider mb-3 mt-1"></div>
|
||||||
<div className="grid grid-flow-row-dense sm:grid-cols-5 gap-3">
|
<div className="grid grid-flow-row-dense sm:grid-cols-5 gap-3">
|
||||||
<div className="sm:col-span-3 col-span-5">
|
<div className="sm:col-span-3 col-span-5">
|
||||||
<p className="mb-2">File</p>
|
<p className="mb-2">{t("file")}</p>
|
||||||
<label className="btn h-10 btn-sm w-full border border-neutral-content hover:border-neutral-content flex justify-between">
|
<label className="btn h-10 btn-sm w-full border border-neutral-content hover:border-neutral-content flex justify-between">
|
||||||
<input
|
<input
|
||||||
type="file"
|
type="file"
|
||||||
|
@ -175,12 +150,13 @@ export default function UploadFileModal({ onClose }: Props) {
|
||||||
/>
|
/>
|
||||||
</label>
|
</label>
|
||||||
<p className="text-xs font-semibold mt-2">
|
<p className="text-xs font-semibold mt-2">
|
||||||
PDF, PNG, JPG, HTML (Up to {process.env.NEXT_PUBLIC_MAX_FILE_SIZE || 30}
|
{t("file_types", {
|
||||||
MB)
|
size: process.env.NEXT_PUBLIC_MAX_FILE_SIZE || 30,
|
||||||
|
})}
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
<div className="sm:col-span-2 col-span-5">
|
<div className="sm:col-span-2 col-span-5">
|
||||||
<p className="mb-2">Collection</p>
|
<p className="mb-2">{t("collection")}</p>
|
||||||
{link.collection.name ? (
|
{link.collection.name ? (
|
||||||
<CollectionSelection
|
<CollectionSelection
|
||||||
onChange={setCollection}
|
onChange={setCollection}
|
||||||
|
@ -194,36 +170,34 @@ export default function UploadFileModal({ onClose }: Props) {
|
||||||
</div>
|
</div>
|
||||||
{optionsExpanded ? (
|
{optionsExpanded ? (
|
||||||
<div className="mt-5">
|
<div className="mt-5">
|
||||||
{/* <hr className="mb-3 border border-neutral-content" /> */}
|
|
||||||
<div className="grid sm:grid-cols-2 gap-3">
|
<div className="grid sm:grid-cols-2 gap-3">
|
||||||
<div>
|
<div>
|
||||||
<p className="mb-2">Name</p>
|
<p className="mb-2">{t("name")}</p>
|
||||||
<TextInput
|
<TextInput
|
||||||
value={link.name}
|
value={link.name}
|
||||||
onChange={(e) => setLink({ ...link, name: e.target.value })}
|
onChange={(e) => setLink({ ...link, name: e.target.value })}
|
||||||
placeholder="e.g. Example Link"
|
placeholder={t("example_link")}
|
||||||
className="bg-base-200"
|
className="bg-base-200"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div>
|
<div>
|
||||||
<p className="mb-2">Tags</p>
|
<p className="mb-2">{t("tags")}</p>
|
||||||
<TagSelection
|
<TagSelection
|
||||||
onChange={setTags}
|
onChange={setTags}
|
||||||
defaultValue={link.tags.map((e) => {
|
defaultValue={link.tags.map((e) => ({
|
||||||
return { label: e.name, value: e.id };
|
label: e.name,
|
||||||
})}
|
value: e.id,
|
||||||
|
}))}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="sm:col-span-2">
|
<div className="sm:col-span-2">
|
||||||
<p className="mb-2">Description</p>
|
<p className="mb-2">{t("description")}</p>
|
||||||
<textarea
|
<textarea
|
||||||
value={unescapeString(link.description) as string}
|
value={unescapeString(link.description) as string}
|
||||||
onChange={(e) =>
|
onChange={(e) =>
|
||||||
setLink({ ...link, description: e.target.value })
|
setLink({ ...link, description: e.target.value })
|
||||||
}
|
}
|
||||||
placeholder="Will be auto generated if nothing is provided."
|
placeholder={t("description_placeholder")}
|
||||||
className="resize-none w-full rounded-md p-2 border-neutral-content bg-base-200 focus:border-sky-300 dark:focus:border-sky-600 border-solid border outline-none duration-100"
|
className="resize-none w-full rounded-md p-2 border-neutral-content bg-base-200 focus:border-sky-300 dark:focus:border-sky-600 border-solid border outline-none duration-100"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
@ -235,14 +209,15 @@ export default function UploadFileModal({ onClose }: Props) {
|
||||||
onClick={() => setOptionsExpanded(!optionsExpanded)}
|
onClick={() => setOptionsExpanded(!optionsExpanded)}
|
||||||
className={`rounded-md cursor-pointer btn btn-sm btn-ghost duration-100 flex items-center px-2 w-fit text-sm`}
|
className={`rounded-md cursor-pointer btn btn-sm btn-ghost duration-100 flex items-center px-2 w-fit text-sm`}
|
||||||
>
|
>
|
||||||
<p>{optionsExpanded ? "Hide" : "More"} Options</p>
|
<p>
|
||||||
|
{optionsExpanded ? t("hide") : t("more")} {t("options")}
|
||||||
|
</p>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<button
|
<button
|
||||||
className="btn btn-accent dark:border-violet-400 text-white"
|
className="btn btn-accent dark:border-violet-400 text-white"
|
||||||
onClick={submit}
|
onClick={submit}
|
||||||
>
|
>
|
||||||
Create Link
|
{t("upload_file")}
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
</Modal>
|
</Modal>
|
||||||
|
|
|
@ -1,40 +1,26 @@
|
||||||
import { signOut } from "next-auth/react";
|
|
||||||
import { useEffect, useState } from "react";
|
import { useEffect, useState } from "react";
|
||||||
import ClickAwayHandler from "@/components/ClickAwayHandler";
|
import ClickAwayHandler from "@/components/ClickAwayHandler";
|
||||||
import Sidebar from "@/components/Sidebar";
|
import Sidebar from "@/components/Sidebar";
|
||||||
import { useRouter } from "next/router";
|
import { useRouter } from "next/router";
|
||||||
import SearchBar from "@/components/SearchBar";
|
import SearchBar from "@/components/SearchBar";
|
||||||
import useAccountStore from "@/store/account";
|
|
||||||
import ProfilePhoto from "@/components/ProfilePhoto";
|
|
||||||
import useWindowDimensions from "@/hooks/useWindowDimensions";
|
import useWindowDimensions from "@/hooks/useWindowDimensions";
|
||||||
import ToggleDarkMode from "./ToggleDarkMode";
|
import ToggleDarkMode from "./ToggleDarkMode";
|
||||||
import useLocalSettingsStore from "@/store/localSettings";
|
|
||||||
import NewLinkModal from "./ModalContent/NewLinkModal";
|
import NewLinkModal from "./ModalContent/NewLinkModal";
|
||||||
import NewCollectionModal from "./ModalContent/NewCollectionModal";
|
import NewCollectionModal from "./ModalContent/NewCollectionModal";
|
||||||
import Link from "next/link";
|
|
||||||
import UploadFileModal from "./ModalContent/UploadFileModal";
|
import UploadFileModal from "./ModalContent/UploadFileModal";
|
||||||
import { dropdownTriggerer } from "@/lib/client/utils";
|
import { dropdownTriggerer } from "@/lib/client/utils";
|
||||||
import MobileNavigation from "./MobileNavigation";
|
import MobileNavigation from "./MobileNavigation";
|
||||||
|
import ProfileDropdown from "./ProfileDropdown";
|
||||||
|
import { useTranslation } from "next-i18next";
|
||||||
|
|
||||||
export default function Navbar() {
|
export default function Navbar() {
|
||||||
const { settings, updateSettings } = useLocalSettingsStore();
|
const { t } = useTranslation();
|
||||||
|
|
||||||
const { account } = useAccountStore();
|
|
||||||
|
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
|
|
||||||
const [sidebar, setSidebar] = useState(false);
|
const [sidebar, setSidebar] = useState(false);
|
||||||
|
|
||||||
const { width } = useWindowDimensions();
|
const { width } = useWindowDimensions();
|
||||||
|
|
||||||
const handleToggle = () => {
|
|
||||||
if (settings.theme === "dark") {
|
|
||||||
updateSettings({ theme: "light" });
|
|
||||||
} else {
|
|
||||||
updateSettings({ theme: "dark" });
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
setSidebar(false);
|
setSidebar(false);
|
||||||
document.body.style.overflow = "auto";
|
document.body.style.overflow = "auto";
|
||||||
|
@ -65,7 +51,7 @@ export default function Navbar() {
|
||||||
<ToggleDarkMode className="hidden sm:inline-grid" />
|
<ToggleDarkMode className="hidden sm:inline-grid" />
|
||||||
|
|
||||||
<div className="dropdown dropdown-end sm:inline-block hidden">
|
<div className="dropdown dropdown-end sm:inline-block hidden">
|
||||||
<div className="tooltip tooltip-bottom" data-tip="Create New...">
|
<div className="tooltip tooltip-bottom" data-tip={t("create_new")}>
|
||||||
<div
|
<div
|
||||||
tabIndex={0}
|
tabIndex={0}
|
||||||
role="button"
|
role="button"
|
||||||
|
@ -90,10 +76,10 @@ export default function Navbar() {
|
||||||
tabIndex={0}
|
tabIndex={0}
|
||||||
role="button"
|
role="button"
|
||||||
>
|
>
|
||||||
New Link
|
{t("new_link")}
|
||||||
</div>
|
</div>
|
||||||
</li>
|
</li>
|
||||||
{/* <li>
|
<li>
|
||||||
<div
|
<div
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
(document?.activeElement as HTMLElement)?.blur();
|
(document?.activeElement as HTMLElement)?.blur();
|
||||||
|
@ -102,9 +88,9 @@ export default function Navbar() {
|
||||||
tabIndex={0}
|
tabIndex={0}
|
||||||
role="button"
|
role="button"
|
||||||
>
|
>
|
||||||
Upload File
|
{t("upload_file")}
|
||||||
</div>
|
</div>
|
||||||
</li> */}
|
</li>
|
||||||
<li>
|
<li>
|
||||||
<div
|
<div
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
|
@ -114,61 +100,13 @@ export default function Navbar() {
|
||||||
tabIndex={0}
|
tabIndex={0}
|
||||||
role="button"
|
role="button"
|
||||||
>
|
>
|
||||||
New Collection
|
{t("new_collection")}
|
||||||
</div>
|
</div>
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="dropdown dropdown-end">
|
<ProfileDropdown />
|
||||||
<div
|
|
||||||
tabIndex={0}
|
|
||||||
role="button"
|
|
||||||
onMouseDown={dropdownTriggerer}
|
|
||||||
className="btn btn-circle btn-ghost"
|
|
||||||
>
|
|
||||||
<ProfilePhoto
|
|
||||||
src={account.image ? account.image : undefined}
|
|
||||||
priority={true}
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
<ul className="dropdown-content z-[1] menu shadow bg-base-200 border border-neutral-content rounded-box w-40 mt-1">
|
|
||||||
<li>
|
|
||||||
<Link
|
|
||||||
href="/settings/account"
|
|
||||||
onClick={() => (document?.activeElement as HTMLElement)?.blur()}
|
|
||||||
tabIndex={0}
|
|
||||||
role="button"
|
|
||||||
>
|
|
||||||
Settings
|
|
||||||
</Link>
|
|
||||||
</li>
|
|
||||||
<li className="block sm:hidden">
|
|
||||||
<div
|
|
||||||
onClick={() => {
|
|
||||||
(document?.activeElement as HTMLElement)?.blur();
|
|
||||||
handleToggle();
|
|
||||||
}}
|
|
||||||
tabIndex={0}
|
|
||||||
role="button"
|
|
||||||
>
|
|
||||||
Switch to {settings.theme === "light" ? "Dark" : "Light"}
|
|
||||||
</div>
|
|
||||||
</li>
|
|
||||||
<li>
|
|
||||||
<div
|
|
||||||
onClick={() => {
|
|
||||||
(document?.activeElement as HTMLElement)?.blur();
|
|
||||||
signOut();
|
|
||||||
}}
|
|
||||||
tabIndex={0}
|
|
||||||
role="button"
|
|
||||||
>
|
|
||||||
Logout
|
|
||||||
</div>
|
|
||||||
</li>
|
|
||||||
</ul>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<MobileNavigation />
|
<MobileNavigation />
|
||||||
|
|
|
@ -1,11 +1,13 @@
|
||||||
import React, { useState } from "react";
|
import React, { useState } from "react";
|
||||||
import NewLinkModal from "./ModalContent/NewLinkModal";
|
import NewLinkModal from "./ModalContent/NewLinkModal";
|
||||||
|
import { useTranslation } from "next-i18next";
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
text?: string;
|
text?: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
export default function NoLinksFound({ text }: Props) {
|
export default function NoLinksFound({ text }: Props) {
|
||||||
|
const { t } = useTranslation();
|
||||||
const [newLinkModal, setNewLinkModal] = useState(false);
|
const [newLinkModal, setNewLinkModal] = useState(false);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
@ -23,9 +25,7 @@ export default function NoLinksFound({ text }: Props) {
|
||||||
<p className="text-center text-xl sm:text-2xl">
|
<p className="text-center text-xl sm:text-2xl">
|
||||||
{text || "You haven't created any Links Here"}
|
{text || "You haven't created any Links Here"}
|
||||||
</p>
|
</p>
|
||||||
<p className="text-center text-sm sm:text-base">
|
<p className="text-center text-sm sm:text-base">{t("start_journey")}</p>
|
||||||
Start your journey by creating a new Link!
|
|
||||||
</p>
|
|
||||||
<div className="text-center w-full mt-4">
|
<div className="text-center w-full mt-4">
|
||||||
<div
|
<div
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
|
@ -35,7 +35,7 @@ export default function NoLinksFound({ text }: Props) {
|
||||||
>
|
>
|
||||||
<i className="bi-plus-lg text-3xl left-2 group-hover:ml-[4rem] absolute duration-100"></i>
|
<i className="bi-plus-lg text-3xl left-2 group-hover:ml-[4rem] absolute duration-100"></i>
|
||||||
<span className="group-hover:opacity-0 text-right w-full duration-100">
|
<span className="group-hover:opacity-0 text-right w-full duration-100">
|
||||||
Create New Link
|
{t("create_new_link")}
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -1,6 +1,10 @@
|
||||||
import React, { useEffect, useState } from "react";
|
import React, { useEffect, useState } from "react";
|
||||||
import useLinkStore from "@/store/links";
|
import useLinkStore from "@/store/links";
|
||||||
import { ArchivedFormat, LinkIncludingShortenedCollectionAndTags } from "@/types/global";
|
import {
|
||||||
|
ArchivedFormat,
|
||||||
|
LinkIncludingShortenedCollectionAndTags,
|
||||||
|
} from "@/types/global";
|
||||||
|
import toast from "react-hot-toast";
|
||||||
import Link from "next/link";
|
import Link from "next/link";
|
||||||
import { useRouter } from "next/router";
|
import { useRouter } from "next/router";
|
||||||
import { useSession } from "next-auth/react";
|
import { useSession } from "next-auth/react";
|
||||||
|
@ -67,7 +71,12 @@ export default function PreservedFormatRow({
|
||||||
// Create a temporary link and click it to trigger the download
|
// Create a temporary link and click it to trigger the download
|
||||||
const anchorElement = document.createElement("a");
|
const anchorElement = document.createElement("a");
|
||||||
anchorElement.href = path;
|
anchorElement.href = path;
|
||||||
anchorElement.download = format === ArchivedFormat.singlefile ? (link.name ?? 'index') : format === ArchivedFormat.pdf ? "PDF" : "Screenshot";
|
anchorElement.download =
|
||||||
|
format === ArchivedFormat.singlefile
|
||||||
|
? link.name ?? "index"
|
||||||
|
: format === ArchivedFormat.pdf
|
||||||
|
? "PDF"
|
||||||
|
: "Screenshot";
|
||||||
anchorElement.click();
|
anchorElement.click();
|
||||||
} else {
|
} else {
|
||||||
console.error("Failed to download file");
|
console.error("Failed to download file");
|
||||||
|
|
|
@ -0,0 +1,72 @@
|
||||||
|
import useLocalSettingsStore from "@/store/localSettings";
|
||||||
|
import { dropdownTriggerer } from "@/lib/client/utils";
|
||||||
|
import ProfilePhoto from "./ProfilePhoto";
|
||||||
|
import useAccountStore from "@/store/account";
|
||||||
|
import Link from "next/link";
|
||||||
|
import { signOut } from "next-auth/react";
|
||||||
|
import { useTranslation } from "next-i18next";
|
||||||
|
|
||||||
|
export default function ProfileDropdown() {
|
||||||
|
const { t } = useTranslation();
|
||||||
|
const { settings, updateSettings } = useLocalSettingsStore();
|
||||||
|
const { account } = useAccountStore();
|
||||||
|
|
||||||
|
const handleToggle = () => {
|
||||||
|
const newTheme = settings.theme === "dark" ? "light" : "dark";
|
||||||
|
updateSettings({ theme: newTheme });
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="dropdown dropdown-end">
|
||||||
|
<div
|
||||||
|
tabIndex={0}
|
||||||
|
role="button"
|
||||||
|
onMouseDown={dropdownTriggerer}
|
||||||
|
className="btn btn-circle btn-ghost"
|
||||||
|
>
|
||||||
|
<ProfilePhoto
|
||||||
|
src={account.image ? account.image : undefined}
|
||||||
|
priority={true}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<ul className="dropdown-content z-[1] menu shadow bg-base-200 border border-neutral-content rounded-box w-40 mt-1">
|
||||||
|
<li>
|
||||||
|
<Link
|
||||||
|
href="/settings/account"
|
||||||
|
onClick={() => (document?.activeElement as HTMLElement)?.blur()}
|
||||||
|
tabIndex={0}
|
||||||
|
role="button"
|
||||||
|
>
|
||||||
|
{t("settings")}
|
||||||
|
</Link>
|
||||||
|
</li>
|
||||||
|
<li className="block sm:hidden">
|
||||||
|
<div
|
||||||
|
onClick={() => {
|
||||||
|
(document?.activeElement as HTMLElement)?.blur();
|
||||||
|
handleToggle();
|
||||||
|
}}
|
||||||
|
tabIndex={0}
|
||||||
|
role="button"
|
||||||
|
>
|
||||||
|
{t("switch_to", {
|
||||||
|
theme: settings.theme === "light" ? t("dark") : t("light"),
|
||||||
|
})}
|
||||||
|
</div>
|
||||||
|
</li>
|
||||||
|
<li>
|
||||||
|
<div
|
||||||
|
onClick={() => {
|
||||||
|
(document?.activeElement as HTMLElement)?.blur();
|
||||||
|
signOut();
|
||||||
|
}}
|
||||||
|
tabIndex={0}
|
||||||
|
role="button"
|
||||||
|
>
|
||||||
|
{t("logout")}
|
||||||
|
</div>
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
|
@ -19,7 +19,7 @@ export default function ProfilePhoto({
|
||||||
const [image, setImage] = useState("");
|
const [image, setImage] = useState("");
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (src && !src?.includes("base64"))
|
if (src && !src?.includes("base64") && !src.startsWith("http"))
|
||||||
setImage(`/api/v1/${src.replace("uploads/", "").replace(".jpg", "")}`);
|
setImage(`/api/v1/${src.replace("uploads/", "").replace(".jpg", "")}`);
|
||||||
else if (!src) setImage("");
|
else if (!src) setImage("");
|
||||||
else {
|
else {
|
||||||
|
|
|
@ -16,14 +16,6 @@ export default function RadioButton({ label, state, onClick }: Props) {
|
||||||
checked={state}
|
checked={state}
|
||||||
onChange={onClick}
|
onChange={onClick}
|
||||||
/>
|
/>
|
||||||
{/*<FontAwesomeIcon*/}
|
|
||||||
{/* icon={faCircleCheck}*/}
|
|
||||||
{/* className="w-5 h-5 text-primary peer-checked:block hidden"*/}
|
|
||||||
{/*/>*/}
|
|
||||||
{/*<FontAwesomeIcon*/}
|
|
||||||
{/* icon={faCircle}*/}
|
|
||||||
{/* className="w-5 h-5 text-primary peer-checked:hidden block"*/}
|
|
||||||
{/*/>*/}
|
|
||||||
<span className="rounded select-none">{label}</span>
|
<span className="rounded select-none">{label}</span>
|
||||||
</label>
|
</label>
|
||||||
);
|
);
|
||||||
|
|
|
@ -4,6 +4,7 @@ import isValidUrl from "@/lib/shared/isValidUrl";
|
||||||
import useLinkStore from "@/store/links";
|
import useLinkStore from "@/store/links";
|
||||||
import {
|
import {
|
||||||
ArchivedFormat,
|
ArchivedFormat,
|
||||||
|
CollectionIncludingMembersAndLinkCount,
|
||||||
LinkIncludingShortenedCollectionAndTags,
|
LinkIncludingShortenedCollectionAndTags,
|
||||||
} from "@/types/global";
|
} from "@/types/global";
|
||||||
import ColorThief, { RGBColor } from "colorthief";
|
import ColorThief, { RGBColor } from "colorthief";
|
||||||
|
@ -11,7 +12,10 @@ import DOMPurify from "dompurify";
|
||||||
import Image from "next/image";
|
import Image from "next/image";
|
||||||
import Link from "next/link";
|
import Link from "next/link";
|
||||||
import { useRouter } from "next/router";
|
import { useRouter } from "next/router";
|
||||||
import React, { useEffect, useState } from "react";
|
import React, { useEffect, useMemo, useState } from "react";
|
||||||
|
import LinkActions from "./LinkViews/LinkComponents/LinkActions";
|
||||||
|
import useCollectionStore from "@/store/collections";
|
||||||
|
import { useTranslation } from "next-i18next";
|
||||||
|
|
||||||
type LinkContent = {
|
type LinkContent = {
|
||||||
title: string;
|
title: string;
|
||||||
|
@ -30,15 +34,25 @@ type Props = {
|
||||||
};
|
};
|
||||||
|
|
||||||
export default function ReadableView({ link }: Props) {
|
export default function ReadableView({ link }: Props) {
|
||||||
|
const { t } = useTranslation();
|
||||||
const [linkContent, setLinkContent] = useState<LinkContent>();
|
const [linkContent, setLinkContent] = useState<LinkContent>();
|
||||||
const [imageError, setImageError] = useState<boolean>(false);
|
const [imageError, setImageError] = useState<boolean>(false);
|
||||||
const [colorPalette, setColorPalette] = useState<RGBColor[]>();
|
const [colorPalette, setColorPalette] = useState<RGBColor[]>();
|
||||||
|
|
||||||
|
const [date, setDate] = useState<Date | string>();
|
||||||
|
|
||||||
const colorThief = new ColorThief();
|
const colorThief = new ColorThief();
|
||||||
|
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
|
|
||||||
const { links, getLink } = useLinkStore();
|
const { getLink } = useLinkStore();
|
||||||
|
const { collections } = useCollectionStore();
|
||||||
|
|
||||||
|
const collection = useMemo(() => {
|
||||||
|
return collections.find(
|
||||||
|
(e) => e.id === link.collection.id
|
||||||
|
) as CollectionIncludingMembersAndLinkCount;
|
||||||
|
}, [collections, link]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const fetchLinkContent = async () => {
|
const fetchLinkContent = async () => {
|
||||||
|
@ -54,6 +68,8 @@ export default function ReadableView({ link }: Props) {
|
||||||
};
|
};
|
||||||
|
|
||||||
fetchLinkContent();
|
fetchLinkContent();
|
||||||
|
|
||||||
|
setDate(link.importDate || link.createdAt);
|
||||||
}, [link]);
|
}, [link]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
@ -126,10 +142,10 @@ export default function ReadableView({ link }: Props) {
|
||||||
}, [colorPalette]);
|
}, [colorPalette]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={`flex flex-col max-w-screen-md h-full mx-auto py-5`}>
|
<div className={`flex flex-col max-w-screen-md h-full mx-auto p-5`}>
|
||||||
<div
|
<div
|
||||||
id="link-banner"
|
id="link-banner"
|
||||||
className="link-banner bg-opacity-10 border-neutral-content p-3 border mb-3"
|
className="link-banner relative bg-opacity-10 border-neutral-content p-3 border mb-3"
|
||||||
>
|
>
|
||||||
<div id="link-banner-inner" className="link-banner-inner"></div>
|
<div id="link-banner-inner" className="link-banner-inner"></div>
|
||||||
|
|
||||||
|
@ -162,7 +178,7 @@ export default function ReadableView({ link }: Props) {
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
<div className="flex flex-col">
|
<div className="flex flex-col">
|
||||||
<p className="text-xl">
|
<p className="text-xl pr-10">
|
||||||
{unescapeString(
|
{unescapeString(
|
||||||
link?.name || link?.description || link?.url || ""
|
link?.name || link?.description || link?.url || ""
|
||||||
)}
|
)}
|
||||||
|
@ -200,7 +216,7 @@ export default function ReadableView({ link }: Props) {
|
||||||
{link?.collection.name}
|
{link?.collection.name}
|
||||||
</p>
|
</p>
|
||||||
</Link>
|
</Link>
|
||||||
{link?.tags.map((e, i) => (
|
{link?.tags?.map((e, i) => (
|
||||||
<Link key={i} href={`/tags/${e.id}`} className="z-10">
|
<Link key={i} href={`/tags/${e.id}`} className="z-10">
|
||||||
<p
|
<p
|
||||||
title={e.name}
|
title={e.name}
|
||||||
|
@ -213,8 +229,8 @@ export default function ReadableView({ link }: Props) {
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<p className="min-w-fit text-sm text-neutral">
|
<p className="min-w-fit text-sm text-neutral">
|
||||||
{link?.createdAt
|
{date
|
||||||
? new Date(link?.createdAt).toLocaleString("en-US", {
|
? new Date(date).toLocaleString("en-US", {
|
||||||
year: "numeric",
|
year: "numeric",
|
||||||
month: "long",
|
month: "long",
|
||||||
day: "numeric",
|
day: "numeric",
|
||||||
|
@ -224,6 +240,13 @@ export default function ReadableView({ link }: Props) {
|
||||||
|
|
||||||
{link?.name ? <p>{unescapeString(link?.description)}</p> : undefined}
|
{link?.name ? <p>{unescapeString(link?.description)}</p> : undefined}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<LinkActions
|
||||||
|
link={link}
|
||||||
|
collection={collection}
|
||||||
|
position="top-3 right-3"
|
||||||
|
alignToTop
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="flex flex-col gap-5 h-full">
|
<div className="flex flex-col gap-5 h-full">
|
||||||
|
@ -252,11 +275,9 @@ export default function ReadableView({ link }: Props) {
|
||||||
<path d="m14.12 6.576 1.715.858c.22.11.22.424 0 .534l-7.568 3.784a.598.598 0 0 1-.534 0L.165 7.968a.299.299 0 0 1 0-.534l1.716-.858 5.317 2.659c.505.252 1.1.252 1.604 0l5.317-2.659z" />
|
<path d="m14.12 6.576 1.715.858c.22.11.22.424 0 .534l-7.568 3.784a.598.598 0 0 1-.534 0L.165 7.968a.299.299 0 0 1 0-.534l1.716-.858 5.317 2.659c.505.252 1.1.252 1.604 0l5.317-2.659z" />
|
||||||
</svg>
|
</svg>
|
||||||
<p className="text-center text-2xl">
|
<p className="text-center text-2xl">
|
||||||
The Link preservation is currently in the queue
|
{t("link_preservation_in_queue")}
|
||||||
</p>
|
|
||||||
<p className="text-center text-lg mt-2">
|
|
||||||
Please check back later to see the result
|
|
||||||
</p>
|
</p>
|
||||||
|
<p className="text-center text-lg mt-2">{t("check_back_later")}</p>
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -1,20 +1,18 @@
|
||||||
import useCollectionStore from "@/store/collections";
|
|
||||||
import Link from "next/link";
|
import Link from "next/link";
|
||||||
import { useRouter } from "next/router";
|
import { useRouter } from "next/router";
|
||||||
import React, { useEffect, useState } from "react";
|
import React, { useEffect, useState } from "react";
|
||||||
|
import { useTranslation } from "next-i18next";
|
||||||
|
|
||||||
export default function SettingsSidebar({ className }: { className?: string }) {
|
export default function SettingsSidebar({ className }: { className?: string }) {
|
||||||
const LINKWARDEN_VERSION = "v2.5.1";
|
const { t } = useTranslation();
|
||||||
|
const LINKWARDEN_VERSION = process.env.version;
|
||||||
const { collections } = useCollectionStore();
|
|
||||||
|
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
|
|
||||||
const [active, setActive] = useState("");
|
const [active, setActive] = useState("");
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
setActive(router.asPath);
|
setActive(router.asPath);
|
||||||
}, [router, collections]);
|
}, [router]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
|
@ -26,71 +24,69 @@ export default function SettingsSidebar({ className }: { className?: string }) {
|
||||||
<Link href="/settings/account">
|
<Link href="/settings/account">
|
||||||
<div
|
<div
|
||||||
className={`${
|
className={`${
|
||||||
active === `/settings/account`
|
active === "/settings/account"
|
||||||
? "bg-primary/20"
|
? "bg-primary/20"
|
||||||
: "hover:bg-neutral/20"
|
: "hover:bg-neutral/20"
|
||||||
} duration-100 py-5 px-2 cursor-pointer flex items-center gap-2 w-full rounded-md h-8`}
|
} duration-100 py-5 px-2 cursor-pointer flex items-center gap-2 w-full rounded-md h-8`}
|
||||||
>
|
>
|
||||||
<i className="bi-person text-primary text-2xl"></i>
|
<i className="bi-person text-primary text-2xl"></i>
|
||||||
|
<p className="truncate w-full pr-7">{t("account")}</p>
|
||||||
<p className="truncate w-full pr-7">Account</p>
|
|
||||||
</div>
|
</div>
|
||||||
</Link>
|
</Link>
|
||||||
|
|
||||||
<Link href="/settings/preference">
|
<Link href="/settings/preference">
|
||||||
<div
|
<div
|
||||||
className={`${
|
className={`${
|
||||||
active === `/settings/preference`
|
active === "/settings/preference"
|
||||||
? "bg-primary/20"
|
? "bg-primary/20"
|
||||||
: "hover:bg-neutral/20"
|
: "hover:bg-neutral/20"
|
||||||
} duration-100 py-5 px-2 cursor-pointer flex items-center gap-2 w-full rounded-md h-8`}
|
} duration-100 py-5 px-2 cursor-pointer flex items-center gap-2 w-full rounded-md h-8`}
|
||||||
>
|
>
|
||||||
<i className="bi-sliders text-primary text-2xl"></i>
|
<i className="bi-sliders text-primary text-2xl"></i>
|
||||||
|
<p className="truncate w-full pr-7">{t("preference")}</p>
|
||||||
<p className="truncate w-full pr-7">Preference</p>
|
|
||||||
</div>
|
</div>
|
||||||
</Link>
|
</Link>
|
||||||
|
|
||||||
<Link href="/settings/access-tokens">
|
<Link href="/settings/access-tokens">
|
||||||
<div
|
<div
|
||||||
className={`${
|
className={`${
|
||||||
active === `/settings/access-tokens`
|
active === "/settings/access-tokens"
|
||||||
? "bg-primary/20"
|
? "bg-primary/20"
|
||||||
: "hover:bg-neutral/20"
|
: "hover:bg-neutral/20"
|
||||||
} duration-100 py-5 px-2 cursor-pointer flex items-center gap-2 w-full rounded-md h-8`}
|
} duration-100 py-5 px-2 cursor-pointer flex items-center gap-2 w-full rounded-md h-8`}
|
||||||
>
|
>
|
||||||
<i className="bi-key text-primary text-2xl"></i>
|
<i className="bi-key text-primary text-2xl"></i>
|
||||||
<p className="truncate w-full pr-7">Access Tokens</p>
|
<p className="truncate w-full pr-7">{t("access_tokens")}</p>
|
||||||
</div>
|
</div>
|
||||||
</Link>
|
</Link>
|
||||||
|
|
||||||
<Link href="/settings/password">
|
<Link href="/settings/password">
|
||||||
<div
|
<div
|
||||||
className={`${
|
className={`${
|
||||||
active === `/settings/password`
|
active === "/settings/password"
|
||||||
? "bg-primary/20"
|
? "bg-primary/20"
|
||||||
: "hover:bg-neutral/20"
|
: "hover:bg-neutral/20"
|
||||||
} duration-100 py-5 px-2 cursor-pointer flex items-center gap-2 w-full rounded-md h-8`}
|
} duration-100 py-5 px-2 cursor-pointer flex items-center gap-2 w-full rounded-md h-8`}
|
||||||
>
|
>
|
||||||
<i className="bi-lock text-primary text-2xl"></i>
|
<i className="bi-lock text-primary text-2xl"></i>
|
||||||
<p className="truncate w-full pr-7">Password</p>
|
<p className="truncate w-full pr-7">{t("password")}</p>
|
||||||
</div>
|
</div>
|
||||||
</Link>
|
</Link>
|
||||||
|
|
||||||
{process.env.NEXT_PUBLIC_STRIPE ? (
|
{process.env.NEXT_PUBLIC_STRIPE && (
|
||||||
<Link href="/settings/billing">
|
<Link href="/settings/billing">
|
||||||
<div
|
<div
|
||||||
className={`${
|
className={`${
|
||||||
active === `/settings/billing`
|
active === "/settings/billing"
|
||||||
? "bg-primary/20"
|
? "bg-primary/20"
|
||||||
: "hover:bg-neutral/20"
|
: "hover:bg-neutral/20"
|
||||||
} duration-100 py-5 px-2 cursor-pointer flex items-center gap-2 w-full rounded-md h-8`}
|
} duration-100 py-5 px-2 cursor-pointer flex items-center gap-2 w-full rounded-md h-8`}
|
||||||
>
|
>
|
||||||
<i className="bi-credit-card text-primary text-xl"></i>
|
<i className="bi-credit-card text-primary text-xl"></i>
|
||||||
<p className="truncate w-full pr-7">Billing</p>
|
<p className="truncate w-full pr-7">{t("billing")}</p>
|
||||||
</div>
|
</div>
|
||||||
</Link>
|
</Link>
|
||||||
) : undefined}
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="flex flex-col gap-1">
|
<div className="flex flex-col gap-1">
|
||||||
|
@ -99,42 +95,38 @@ export default function SettingsSidebar({ className }: { className?: string }) {
|
||||||
target="_blank"
|
target="_blank"
|
||||||
className="text-neutral text-sm ml-2 hover:opacity-50 duration-100"
|
className="text-neutral text-sm ml-2 hover:opacity-50 duration-100"
|
||||||
>
|
>
|
||||||
Linkwarden {LINKWARDEN_VERSION}
|
{t("linkwarden_version", { version: LINKWARDEN_VERSION })}
|
||||||
</Link>
|
</Link>
|
||||||
<Link href="https://docs.linkwarden.app" target="_blank">
|
<Link href="https://docs.linkwarden.app" target="_blank">
|
||||||
<div
|
<div
|
||||||
className={`hover:bg-neutral/20 duration-100 py-2 px-2 cursor-pointer flex items-center gap-2 w-full rounded-md h-8`}
|
className={`hover:bg-neutral/20 duration-100 py-2 px-2 cursor-pointer flex items-center gap-2 w-full rounded-md h-8`}
|
||||||
>
|
>
|
||||||
<i className="bi-question-circle text-primary text-xl"></i>
|
<i className="bi-question-circle text-primary text-xl"></i>
|
||||||
|
<p className="truncate w-full pr-7">{t("help")}</p>
|
||||||
<p className="truncate w-full pr-7">Help</p>
|
|
||||||
</div>
|
</div>
|
||||||
</Link>
|
</Link>
|
||||||
|
|
||||||
<Link href="https://github.com/linkwarden/linkwarden" target="_blank">
|
<Link href="https://github.com/linkwarden/linkwarden" target="_blank">
|
||||||
<div
|
<div
|
||||||
className={`hover:bg-neutral/20 duration-100 py-2 px-2 cursor-pointer flex items-center gap-2 w-full rounded-md h-8`}
|
className={`hover:bg-neutral/20 duration-100 py-2 px-2 cursor-pointer flex items-center gap-2 w-full rounded-md h-8`}
|
||||||
>
|
>
|
||||||
<i className="bi-github text-primary text-xl"></i>
|
<i className="bi-github text-primary text-xl"></i>
|
||||||
<p className="truncate w-full pr-7">GitHub</p>
|
<p className="truncate w-full pr-7">{t("github")}</p>
|
||||||
</div>
|
</div>
|
||||||
</Link>
|
</Link>
|
||||||
|
|
||||||
<Link href="https://twitter.com/LinkwardenHQ" target="_blank">
|
<Link href="https://twitter.com/LinkwardenHQ" target="_blank">
|
||||||
<div
|
<div
|
||||||
className={`hover:bg-neutral/20 duration-100 py-2 px-2 cursor-pointer flex items-center gap-2 w-full rounded-md h-8`}
|
className={`hover:bg-neutral/20 duration-100 py-2 px-2 cursor-pointer flex items-center gap-2 w-full rounded-md h-8`}
|
||||||
>
|
>
|
||||||
<i className="bi-twitter-x text-primary text-xl"></i>
|
<i className="bi-twitter-x text-primary text-xl"></i>
|
||||||
<p className="truncate w-full pr-7">Twitter</p>
|
<p className="truncate w-full pr-7">{t("twitter")}</p>
|
||||||
</div>
|
</div>
|
||||||
</Link>
|
</Link>
|
||||||
|
|
||||||
<Link href="https://fosstodon.org/@linkwarden" target="_blank">
|
<Link href="https://fosstodon.org/@linkwarden" target="_blank">
|
||||||
<div
|
<div
|
||||||
className={`hover:bg-neutral/20 duration-100 py-2 px-2 cursor-pointer flex items-center gap-2 w-full rounded-md h-8`}
|
className={`hover:bg-neutral/20 duration-100 py-2 px-2 cursor-pointer flex items-center gap-2 w-full rounded-md h-8`}
|
||||||
>
|
>
|
||||||
<i className="bi-mastodon text-primary text-xl"></i>
|
<i className="bi-mastodon text-primary text-xl"></i>
|
||||||
<p className="truncate w-full pr-7">Mastodon</p>
|
<p className="truncate w-full pr-7">{t("mastodon")}</p>
|
||||||
</div>
|
</div>
|
||||||
</Link>
|
</Link>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -6,8 +6,10 @@ import { useEffect, useState } from "react";
|
||||||
import { Disclosure, Transition } from "@headlessui/react";
|
import { Disclosure, Transition } from "@headlessui/react";
|
||||||
import SidebarHighlightLink from "@/components/SidebarHighlightLink";
|
import SidebarHighlightLink from "@/components/SidebarHighlightLink";
|
||||||
import CollectionListing from "@/components/CollectionListing";
|
import CollectionListing from "@/components/CollectionListing";
|
||||||
|
import { useTranslation } from "next-i18next";
|
||||||
|
|
||||||
export default function Sidebar({ className }: { className?: string }) {
|
export default function Sidebar({ className }: { className?: string }) {
|
||||||
|
const { t } = useTranslation();
|
||||||
const [tagDisclosure, setTagDisclosure] = useState<boolean>(() => {
|
const [tagDisclosure, setTagDisclosure] = useState<boolean>(() => {
|
||||||
const storedValue = localStorage.getItem("tagDisclosure");
|
const storedValue = localStorage.getItem("tagDisclosure");
|
||||||
return storedValue ? storedValue === "true" : true;
|
return storedValue ? storedValue === "true" : true;
|
||||||
|
@ -82,7 +84,7 @@ export default function Sidebar({ className }: { className?: string }) {
|
||||||
}}
|
}}
|
||||||
className="flex items-center justify-between w-full text-left mb-2 pl-2 font-bold text-neutral mt-5"
|
className="flex items-center justify-between w-full text-left mb-2 pl-2 font-bold text-neutral mt-5"
|
||||||
>
|
>
|
||||||
<p className="text-sm">Collections</p>
|
<p className="text-sm">{t("collections")}</p>
|
||||||
<i
|
<i
|
||||||
className={`bi-chevron-down ${
|
className={`bi-chevron-down ${
|
||||||
collectionDisclosure ? "rotate-reverse" : "rotate"
|
collectionDisclosure ? "rotate-reverse" : "rotate"
|
||||||
|
@ -109,7 +111,7 @@ export default function Sidebar({ className }: { className?: string }) {
|
||||||
}}
|
}}
|
||||||
className="flex items-center justify-between w-full text-left mb-2 pl-2 font-bold text-neutral mt-5"
|
className="flex items-center justify-between w-full text-left mb-2 pl-2 font-bold text-neutral mt-5"
|
||||||
>
|
>
|
||||||
<p className="text-sm">Tags</p>
|
<p className="text-sm">{t("tags")}</p>
|
||||||
<i
|
<i
|
||||||
className={`bi-chevron-down ${
|
className={`bi-chevron-down ${
|
||||||
tagDisclosure ? "rotate-reverse" : "rotate"
|
tagDisclosure ? "rotate-reverse" : "rotate"
|
||||||
|
@ -152,7 +154,7 @@ export default function Sidebar({ className }: { className?: string }) {
|
||||||
className={`duration-100 py-1 px-2 flex items-center gap-2 w-full rounded-md h-8 capitalize`}
|
className={`duration-100 py-1 px-2 flex items-center gap-2 w-full rounded-md h-8 capitalize`}
|
||||||
>
|
>
|
||||||
<p className="text-neutral text-xs font-semibold truncate w-full pr-7">
|
<p className="text-neutral text-xs font-semibold truncate w-full pr-7">
|
||||||
You Have No Tags...
|
{t("you_have_no_tags")}
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
|
|
@ -1,13 +1,15 @@
|
||||||
import React, { Dispatch, SetStateAction } from "react";
|
import React, { Dispatch, SetStateAction } from "react";
|
||||||
import { Sort } from "@/types/global";
|
import { Sort } from "@/types/global";
|
||||||
import { dropdownTriggerer } from "@/lib/client/utils";
|
import { dropdownTriggerer } from "@/lib/client/utils";
|
||||||
|
import { TFunction } from "i18next";
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
sortBy: Sort;
|
sortBy: Sort;
|
||||||
setSort: Dispatch<SetStateAction<Sort>>;
|
setSort: Dispatch<SetStateAction<Sort>>;
|
||||||
|
t: TFunction<"translation", undefined>;
|
||||||
};
|
};
|
||||||
|
|
||||||
export default function SortDropdown({ sortBy, setSort }: Props) {
|
export default function SortDropdown({ sortBy, setSort, t }: Props) {
|
||||||
return (
|
return (
|
||||||
<div className="dropdown dropdown-bottom dropdown-end">
|
<div className="dropdown dropdown-bottom dropdown-end">
|
||||||
<div
|
<div
|
||||||
|
@ -29,13 +31,10 @@ export default function SortDropdown({ sortBy, setSort }: Props) {
|
||||||
type="radio"
|
type="radio"
|
||||||
name="sort-radio"
|
name="sort-radio"
|
||||||
className="radio checked:bg-primary"
|
className="radio checked:bg-primary"
|
||||||
value="Date (Newest First)"
|
|
||||||
checked={sortBy === Sort.DateNewestFirst}
|
checked={sortBy === Sort.DateNewestFirst}
|
||||||
onChange={() => {
|
onChange={() => setSort(Sort.DateNewestFirst)}
|
||||||
setSort(Sort.DateNewestFirst);
|
|
||||||
}}
|
|
||||||
/>
|
/>
|
||||||
<span className="label-text">Date (Newest First)</span>
|
<span className="label-text">{t("date_newest_first")}</span>
|
||||||
</label>
|
</label>
|
||||||
</li>
|
</li>
|
||||||
<li>
|
<li>
|
||||||
|
@ -48,11 +47,10 @@ export default function SortDropdown({ sortBy, setSort }: Props) {
|
||||||
type="radio"
|
type="radio"
|
||||||
name="sort-radio"
|
name="sort-radio"
|
||||||
className="radio checked:bg-primary"
|
className="radio checked:bg-primary"
|
||||||
value="Date (Oldest First)"
|
|
||||||
checked={sortBy === Sort.DateOldestFirst}
|
checked={sortBy === Sort.DateOldestFirst}
|
||||||
onChange={() => setSort(Sort.DateOldestFirst)}
|
onChange={() => setSort(Sort.DateOldestFirst)}
|
||||||
/>
|
/>
|
||||||
<span className="label-text">Date (Oldest First)</span>
|
<span className="label-text">{t("date_oldest_first")}</span>
|
||||||
</label>
|
</label>
|
||||||
</li>
|
</li>
|
||||||
<li>
|
<li>
|
||||||
|
@ -65,11 +63,10 @@ export default function SortDropdown({ sortBy, setSort }: Props) {
|
||||||
type="radio"
|
type="radio"
|
||||||
name="sort-radio"
|
name="sort-radio"
|
||||||
className="radio checked:bg-primary"
|
className="radio checked:bg-primary"
|
||||||
value="Name (A-Z)"
|
|
||||||
checked={sortBy === Sort.NameAZ}
|
checked={sortBy === Sort.NameAZ}
|
||||||
onChange={() => setSort(Sort.NameAZ)}
|
onChange={() => setSort(Sort.NameAZ)}
|
||||||
/>
|
/>
|
||||||
<span className="label-text">Name (A-Z)</span>
|
<span className="label-text">{t("name_az")}</span>
|
||||||
</label>
|
</label>
|
||||||
</li>
|
</li>
|
||||||
<li>
|
<li>
|
||||||
|
@ -82,11 +79,10 @@ export default function SortDropdown({ sortBy, setSort }: Props) {
|
||||||
type="radio"
|
type="radio"
|
||||||
name="sort-radio"
|
name="sort-radio"
|
||||||
className="radio checked:bg-primary"
|
className="radio checked:bg-primary"
|
||||||
value="Name (Z-A)"
|
|
||||||
checked={sortBy === Sort.NameZA}
|
checked={sortBy === Sort.NameZA}
|
||||||
onChange={() => setSort(Sort.NameZA)}
|
onChange={() => setSort(Sort.NameZA)}
|
||||||
/>
|
/>
|
||||||
<span className="label-text">Name (Z-A)</span>
|
<span className="label-text">{t("name_za")}</span>
|
||||||
</label>
|
</label>
|
||||||
</li>
|
</li>
|
||||||
<li>
|
<li>
|
||||||
|
@ -99,11 +95,10 @@ export default function SortDropdown({ sortBy, setSort }: Props) {
|
||||||
type="radio"
|
type="radio"
|
||||||
name="sort-radio"
|
name="sort-radio"
|
||||||
className="radio checked:bg-primary"
|
className="radio checked:bg-primary"
|
||||||
value="Description (A-Z)"
|
|
||||||
checked={sortBy === Sort.DescriptionAZ}
|
checked={sortBy === Sort.DescriptionAZ}
|
||||||
onChange={() => setSort(Sort.DescriptionAZ)}
|
onChange={() => setSort(Sort.DescriptionAZ)}
|
||||||
/>
|
/>
|
||||||
<span className="label-text">Description (A-Z)</span>
|
<span className="label-text">{t("description_az")}</span>
|
||||||
</label>
|
</label>
|
||||||
</li>
|
</li>
|
||||||
<li>
|
<li>
|
||||||
|
@ -116,11 +111,10 @@ export default function SortDropdown({ sortBy, setSort }: Props) {
|
||||||
type="radio"
|
type="radio"
|
||||||
name="sort-radio"
|
name="sort-radio"
|
||||||
className="radio checked:bg-primary"
|
className="radio checked:bg-primary"
|
||||||
value="Description (Z-A)"
|
|
||||||
checked={sortBy === Sort.DescriptionZA}
|
checked={sortBy === Sort.DescriptionZA}
|
||||||
onChange={() => setSort(Sort.DescriptionZA)}
|
onChange={() => setSort(Sort.DescriptionZA)}
|
||||||
/>
|
/>
|
||||||
<span className="label-text">Description (Z-A)</span>
|
<span className="label-text">{t("description_za")}</span>
|
||||||
</label>
|
</label>
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
|
|
|
@ -9,6 +9,7 @@ type Props = {
|
||||||
onKeyDown?: KeyboardEventHandler<HTMLInputElement> | undefined;
|
onKeyDown?: KeyboardEventHandler<HTMLInputElement> | undefined;
|
||||||
className?: string;
|
className?: string;
|
||||||
spellCheck?: boolean;
|
spellCheck?: boolean;
|
||||||
|
"data-testid"?: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
export default function TextInput({
|
export default function TextInput({
|
||||||
|
@ -20,9 +21,11 @@ export default function TextInput({
|
||||||
onKeyDown,
|
onKeyDown,
|
||||||
className,
|
className,
|
||||||
spellCheck,
|
spellCheck,
|
||||||
|
"data-testid": dataTestId,
|
||||||
}: Props) {
|
}: Props) {
|
||||||
return (
|
return (
|
||||||
<input
|
<input
|
||||||
|
data-testid={dataTestId}
|
||||||
spellCheck={spellCheck}
|
spellCheck={spellCheck}
|
||||||
autoFocus={autoFocus}
|
autoFocus={autoFocus}
|
||||||
type={type ? type : "text"}
|
type={type ? type : "text"}
|
||||||
|
|
|
@ -1,11 +1,13 @@
|
||||||
import useLocalSettingsStore from "@/store/localSettings";
|
import useLocalSettingsStore from "@/store/localSettings";
|
||||||
import { useEffect, useState } from "react";
|
import { useEffect, useState } from "react";
|
||||||
|
import { useTranslation } from "next-i18next";
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
className?: string;
|
className?: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
export default function ToggleDarkMode({ className }: Props) {
|
export default function ToggleDarkMode({ className }: Props) {
|
||||||
|
const { t } = useTranslation();
|
||||||
const { settings, updateSettings } = useLocalSettingsStore();
|
const { settings, updateSettings } = useLocalSettingsStore();
|
||||||
|
|
||||||
const [theme, setTheme] = useState(localStorage.getItem("theme"));
|
const [theme, setTheme] = useState(localStorage.getItem("theme"));
|
||||||
|
@ -21,7 +23,9 @@ export default function ToggleDarkMode({ className }: Props) {
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
className="tooltip tooltip-bottom"
|
className="tooltip tooltip-bottom"
|
||||||
data-tip={`Switch to ${settings.theme === "light" ? "Dark" : "Light"}`}
|
data-tip={t("switch_to", {
|
||||||
|
theme: settings.theme === "light" ? "Dark" : "Light",
|
||||||
|
})}
|
||||||
>
|
>
|
||||||
<label
|
<label
|
||||||
className={`swap swap-rotate btn-square text-neutral btn btn-ghost btn-sm ${className}`}
|
className={`swap swap-rotate btn-square text-neutral btn btn-ghost btn-sm ${className}`}
|
||||||
|
|
|
@ -0,0 +1,87 @@
|
||||||
|
import DeleteUserModal from "@/components/ModalContent/DeleteUserModal";
|
||||||
|
import { User as U } from "@prisma/client";
|
||||||
|
import { TFunction } from "i18next";
|
||||||
|
|
||||||
|
interface User extends U {
|
||||||
|
subscriptions: {
|
||||||
|
active: boolean;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
type UserModal = {
|
||||||
|
isOpen: boolean;
|
||||||
|
userId: number | null;
|
||||||
|
};
|
||||||
|
|
||||||
|
const UserListing = (
|
||||||
|
users: User[],
|
||||||
|
deleteUserModal: UserModal,
|
||||||
|
setDeleteUserModal: Function,
|
||||||
|
t: TFunction<"translation", undefined>
|
||||||
|
) => {
|
||||||
|
return (
|
||||||
|
<div className="overflow-x-auto whitespace-nowrap w-full">
|
||||||
|
<table className="table w-full">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th></th>
|
||||||
|
<th>{t("username")}</th>
|
||||||
|
{process.env.NEXT_PUBLIC_EMAIL_PROVIDER === "true" && (
|
||||||
|
<th>{t("email")}</th>
|
||||||
|
)}
|
||||||
|
{process.env.NEXT_PUBLIC_STRIPE === "true" && (
|
||||||
|
<th>{t("subscribed")}</th>
|
||||||
|
)}
|
||||||
|
<th>{t("created_at")}</th>
|
||||||
|
<th></th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
{users.map((user, index) => (
|
||||||
|
<tr
|
||||||
|
key={index}
|
||||||
|
className="group hover:bg-neutral-content hover:bg-opacity-30 duration-100"
|
||||||
|
>
|
||||||
|
<td className="text-primary">{index + 1}</td>
|
||||||
|
<td>
|
||||||
|
{user.username ? user.username : <b>{t("not_available")}</b>}
|
||||||
|
</td>
|
||||||
|
{process.env.NEXT_PUBLIC_EMAIL_PROVIDER === "true" && (
|
||||||
|
<td>{user.email}</td>
|
||||||
|
)}
|
||||||
|
{process.env.NEXT_PUBLIC_STRIPE === "true" && (
|
||||||
|
<td>
|
||||||
|
{user.subscriptions?.active ? (
|
||||||
|
<i className="bi bi-check text-green-500"></i>
|
||||||
|
) : (
|
||||||
|
<i className="bi bi-x text-red-500"></i>
|
||||||
|
)}
|
||||||
|
</td>
|
||||||
|
)}
|
||||||
|
<td>{new Date(user.createdAt).toLocaleString()}</td>
|
||||||
|
<td className="relative">
|
||||||
|
<button
|
||||||
|
className="btn btn-sm btn-ghost duration-100 hidden group-hover:block absolute z-20 right-[0.35rem] top-[0.35rem]"
|
||||||
|
onClick={() =>
|
||||||
|
setDeleteUserModal({ isOpen: true, userId: user.id })
|
||||||
|
}
|
||||||
|
>
|
||||||
|
<i className="bi bi-trash"></i>
|
||||||
|
</button>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
))}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
|
||||||
|
{deleteUserModal.isOpen && deleteUserModal.userId ? (
|
||||||
|
<DeleteUserModal
|
||||||
|
onClose={() => setDeleteUserModal({ isOpen: false, userId: null })}
|
||||||
|
userId={deleteUserModal.userId}
|
||||||
|
/>
|
||||||
|
) : null}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default UserListing;
|
|
@ -35,6 +35,17 @@ export default function ViewDropdown({ viewMode, setViewMode }: Props) {
|
||||||
<i className="bi-grid w-4 h-4 text-neutral"></i>
|
<i className="bi-grid w-4 h-4 text-neutral"></i>
|
||||||
</button>
|
</button>
|
||||||
|
|
||||||
|
<button
|
||||||
|
onClick={(e) => onChangeViewMode(e, ViewMode.Masonry)}
|
||||||
|
className={`btn btn-square btn-sm btn-ghost ${
|
||||||
|
viewMode == ViewMode.Masonry
|
||||||
|
? "bg-primary/20 hover:bg-primary/20"
|
||||||
|
: "hover:bg-neutral/20"
|
||||||
|
}`}
|
||||||
|
>
|
||||||
|
<i className="bi bi-columns-gap w-4 h-4 text-neutral"></i>
|
||||||
|
</button>
|
||||||
|
|
||||||
<button
|
<button
|
||||||
onClick={(e) => onChangeViewMode(e, ViewMode.List)}
|
onClick={(e) => onChangeViewMode(e, ViewMode.List)}
|
||||||
className={`btn btn-square btn-sm btn-ghost ${
|
className={`btn btn-square btn-sm btn-ghost ${
|
||||||
|
|
|
@ -0,0 +1,62 @@
|
||||||
|
import { cn } from "@/lib/client/utils";
|
||||||
|
|
||||||
|
import { cva, type VariantProps } from "class-variance-authority";
|
||||||
|
|
||||||
|
const buttonVariants = cva(
|
||||||
|
"select-none relative duration-200 rounded-lg text-center w-fit flex justify-center items-center gap-2 disabled:pointer-events-none disabled:opacity-50",
|
||||||
|
{
|
||||||
|
variants: {
|
||||||
|
intent: {
|
||||||
|
accent:
|
||||||
|
"bg-accent text-white hover:bg-accent/80 border border-violet-400",
|
||||||
|
primary: "bg-primary text-primary-content hover:bg-primary/80",
|
||||||
|
secondary:
|
||||||
|
"bg-neutral-content text-secondary-foreground hover:bg-neutral-content/80 border border-neutral/30",
|
||||||
|
destructive:
|
||||||
|
"bg-error text-white hover:bg-error/80 border border-neutral/60",
|
||||||
|
outline:
|
||||||
|
"border border-input bg-background hover:bg-accent hover:text-accent-content",
|
||||||
|
ghost: "hover:bg-accent hover:text-accent-foreground",
|
||||||
|
link: "text-primary underline-offset-4 hover:underline",
|
||||||
|
},
|
||||||
|
size: {
|
||||||
|
small: "h-7 px-2",
|
||||||
|
medium: "h-10 px-4 py-2",
|
||||||
|
large: "h-12 px-7 py-2",
|
||||||
|
full: "px-4 py-2 w-full",
|
||||||
|
icon: "h-10 w-10",
|
||||||
|
},
|
||||||
|
loading: {
|
||||||
|
true: "cursor-wait",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
defaultVariants: {
|
||||||
|
intent: "primary",
|
||||||
|
size: "medium",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
export interface ButtonProps
|
||||||
|
extends React.ButtonHTMLAttributes<HTMLButtonElement>,
|
||||||
|
VariantProps<typeof buttonVariants> {}
|
||||||
|
|
||||||
|
const Button: React.FC<ButtonProps> = ({
|
||||||
|
className,
|
||||||
|
intent,
|
||||||
|
size,
|
||||||
|
children,
|
||||||
|
disabled,
|
||||||
|
loading = false,
|
||||||
|
...props
|
||||||
|
}) => (
|
||||||
|
<button
|
||||||
|
className={cn(buttonVariants({ intent, size, className }))}
|
||||||
|
disabled={loading || disabled}
|
||||||
|
{...props}
|
||||||
|
>
|
||||||
|
{children}
|
||||||
|
</button>
|
||||||
|
);
|
||||||
|
|
||||||
|
export default Button;
|
|
@ -0,0 +1,2 @@
|
||||||
|
TEST_USERNAME=test
|
||||||
|
TEST_PASSWORD=password
|
|
@ -0,0 +1,20 @@
|
||||||
|
import axios, { AxiosError } from "axios"
|
||||||
|
|
||||||
|
axios.defaults.baseURL = "http://localhost:3000"
|
||||||
|
|
||||||
|
export async function seedUser (username?: string, password?: string, name?: string) {
|
||||||
|
try {
|
||||||
|
return await axios.post("/api/v1/users", {
|
||||||
|
username: username || "test",
|
||||||
|
password: password || "password",
|
||||||
|
name: name || "Test User",
|
||||||
|
})
|
||||||
|
} catch (e: any) {
|
||||||
|
if (e instanceof AxiosError) {
|
||||||
|
if (e.response?.status === 400) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
throw e
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,10 @@
|
||||||
|
import { Locator, Page } from "playwright";
|
||||||
|
import { BasePage } from "./page";
|
||||||
|
|
||||||
|
export class DashboardPage extends BasePage {
|
||||||
|
container: Locator;
|
||||||
|
constructor(page: Page) {
|
||||||
|
super(page);
|
||||||
|
this.container = this.page.getByTestId("dashboard-wrapper");
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,45 @@
|
||||||
|
import { Locator, Page } from "@playwright/test";
|
||||||
|
|
||||||
|
export class BaseModal {
|
||||||
|
page: Page;
|
||||||
|
container: Locator;
|
||||||
|
mobileContainer: Locator;
|
||||||
|
closeModalButton: Locator;
|
||||||
|
mobileModalSlider: Locator;
|
||||||
|
|
||||||
|
constructor(page: Page) {
|
||||||
|
this.page = page;
|
||||||
|
this.container = page.getByTestId("modal-container");
|
||||||
|
this.mobileContainer = page.getByTestId("mobile-modal-container");
|
||||||
|
this.closeModalButton = this.container.getByTestId("close-modal-button");
|
||||||
|
this.mobileModalSlider = this.mobileContainer.getByTestId(
|
||||||
|
"mobile-modal-slider"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
async close() {
|
||||||
|
if (await this.container.isVisible()) {
|
||||||
|
await this.closeModalButton.click();
|
||||||
|
}
|
||||||
|
if (await this.mobileContainer.isVisible()) {
|
||||||
|
const box = await this.mobileModalSlider.boundingBox();
|
||||||
|
if (!box) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const pageHeight = await this.page.evaluate(() => window.innerHeight);
|
||||||
|
const startX = box.x + box.width / 2;
|
||||||
|
const startY = box.y + box.height / 2;
|
||||||
|
await this.page.mouse.move(startX, startY);
|
||||||
|
await this.page.mouse.down();
|
||||||
|
await this.page.mouse.move(startX, startY + pageHeight / 2);
|
||||||
|
await this.page.mouse.up();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async isOpen() {
|
||||||
|
return (
|
||||||
|
(await this.container.isVisible()) ||
|
||||||
|
(await this.mobileContainer.isVisible())
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,20 @@
|
||||||
|
import { Locator, Page } from "@playwright/test";
|
||||||
|
|
||||||
|
export class BasePage {
|
||||||
|
page: Page;
|
||||||
|
toastMessage: Locator;
|
||||||
|
|
||||||
|
constructor(page: Page) {
|
||||||
|
this.page = page;
|
||||||
|
this.toastMessage = this.page.getByTestId("toast-message-container");
|
||||||
|
}
|
||||||
|
|
||||||
|
async getLatestToast() {
|
||||||
|
const toast = this.toastMessage.first();
|
||||||
|
return {
|
||||||
|
locator: toast,
|
||||||
|
closeButton: toast.getByTestId("close-toast-button"),
|
||||||
|
message: toast.getByTestId("toast-message"),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,27 @@
|
||||||
|
import { test as baseTest } from "@playwright/test";
|
||||||
|
import { LoginPage } from "./login-page";
|
||||||
|
import { RegistrationPage } from "./registration-page";
|
||||||
|
import { DashboardPage } from "./base/dashboard-page";
|
||||||
|
|
||||||
|
export const test = baseTest.extend<{
|
||||||
|
dashboardPage: DashboardPage;
|
||||||
|
loginPage: LoginPage;
|
||||||
|
registrationPage: RegistrationPage;
|
||||||
|
}>({
|
||||||
|
page: async ({ page }, use) => {
|
||||||
|
await page.goto("/");
|
||||||
|
use(page);
|
||||||
|
},
|
||||||
|
dashboardPage: async ({ page }, use) => {
|
||||||
|
const dashboardPage = new DashboardPage(page);
|
||||||
|
await use(dashboardPage);
|
||||||
|
},
|
||||||
|
loginPage: async ({ page }, use) => {
|
||||||
|
const loginPage = new LoginPage(page);
|
||||||
|
await use(loginPage);
|
||||||
|
},
|
||||||
|
registrationPage: async ({ page }, use) => {
|
||||||
|
const registrationPage = new RegistrationPage(page);
|
||||||
|
await use(registrationPage);
|
||||||
|
},
|
||||||
|
});
|
|
@ -0,0 +1,27 @@
|
||||||
|
import { Locator, Page } from "@playwright/test";
|
||||||
|
import { BasePage } from "./base/page";
|
||||||
|
|
||||||
|
export class LoginPage extends BasePage {
|
||||||
|
submitLoginButton: Locator;
|
||||||
|
loginForm: Locator;
|
||||||
|
registerLink: Locator;
|
||||||
|
passwordInput: Locator;
|
||||||
|
usernameInput: Locator;
|
||||||
|
|
||||||
|
constructor(page: Page) {
|
||||||
|
super(page);
|
||||||
|
|
||||||
|
this.submitLoginButton = page.getByTestId("submit-login-button");
|
||||||
|
|
||||||
|
this.loginForm = page.getByTestId("login-form");
|
||||||
|
|
||||||
|
this.registerLink = page.getByTestId("register-link");
|
||||||
|
|
||||||
|
this.passwordInput = page.getByTestId("password-input");
|
||||||
|
this.usernameInput = page.getByTestId("username-input");
|
||||||
|
}
|
||||||
|
|
||||||
|
async goto() {
|
||||||
|
await this.page.goto("/login");
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,28 @@
|
||||||
|
import { Locator, Page } from "@playwright/test";
|
||||||
|
import { BasePage } from "./base/page";
|
||||||
|
|
||||||
|
export class RegistrationPage extends BasePage {
|
||||||
|
registerButton: Locator;
|
||||||
|
registrationForm: Locator;
|
||||||
|
|
||||||
|
loginLink: Locator;
|
||||||
|
|
||||||
|
displayNameInput: Locator;
|
||||||
|
passwordConfirmInput: Locator;
|
||||||
|
passwordInput: Locator;
|
||||||
|
usernameInput: Locator;
|
||||||
|
|
||||||
|
constructor(page: Page) {
|
||||||
|
super(page);
|
||||||
|
|
||||||
|
this.registerButton = page.getByTestId("register-button");
|
||||||
|
this.registrationForm = page.getByTestId("registration-form");
|
||||||
|
|
||||||
|
this.loginLink = page.getByTestId("login-link");
|
||||||
|
|
||||||
|
this.displayNameInput = page.getByTestId("display-name-input");
|
||||||
|
this.passwordConfirmInput = page.getByTestId("password-confirm-input");
|
||||||
|
this.passwordInput = page.getByTestId("password-input");
|
||||||
|
this.usernameInput = page.getByTestId("username-input");
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,2 @@
|
||||||
|
export { test } from "./fixtures";
|
||||||
|
export { expect } from "@playwright/test";
|
|
@ -0,0 +1,19 @@
|
||||||
|
import { seedUser } from "@/e2e/data/user";
|
||||||
|
import { test as setup } from "../../index";
|
||||||
|
import { STORAGE_STATE } from "../../../playwright.config";
|
||||||
|
|
||||||
|
setup("Setup the default user", async ({ page, dashboardPage, loginPage }) => {
|
||||||
|
const username = process.env["TEST_USERNAME"] || "";
|
||||||
|
const password = process.env["TEST_PASSWORD"] || "";
|
||||||
|
await seedUser(username, password);
|
||||||
|
|
||||||
|
await loginPage.goto();
|
||||||
|
await loginPage.usernameInput.fill(username);
|
||||||
|
await loginPage.passwordInput.fill(password);
|
||||||
|
await loginPage.submitLoginButton.click();
|
||||||
|
await dashboardPage.container.waitFor({ state: "visible" });
|
||||||
|
|
||||||
|
await page.context().storageState({
|
||||||
|
path: STORAGE_STATE,
|
||||||
|
});
|
||||||
|
});
|
|
@ -0,0 +1,8 @@
|
||||||
|
import { seedUser } from "@/e2e/data/user";
|
||||||
|
import { test as setup } from "../../index";
|
||||||
|
|
||||||
|
setup("Setup the default user", async () => {
|
||||||
|
const username = process.env["TEST_USERNAME"] || "";
|
||||||
|
const password = process.env["TEST_PASSWORD"] || "";
|
||||||
|
await seedUser(username, password);
|
||||||
|
});
|
|
@ -0,0 +1,50 @@
|
||||||
|
import { expect, test } from "../../index";
|
||||||
|
|
||||||
|
test.describe(
|
||||||
|
"Login test suite",
|
||||||
|
{
|
||||||
|
tag: "@login",
|
||||||
|
},
|
||||||
|
async () => {
|
||||||
|
test("Logging in without credentials displays an error", async ({
|
||||||
|
loginPage,
|
||||||
|
}) => {
|
||||||
|
await loginPage.submitLoginButton.click();
|
||||||
|
const toast = await loginPage.getLatestToast();
|
||||||
|
await expect(toast.locator).toBeVisible();
|
||||||
|
await expect(toast.locator).toHaveAttribute("data-type", "error");
|
||||||
|
});
|
||||||
|
|
||||||
|
test("Logging in with an erroneous password displays an error", async ({
|
||||||
|
loginPage,
|
||||||
|
}) => {
|
||||||
|
await loginPage.usernameInput.fill(process.env["TEST_USERNAME"] || "");
|
||||||
|
await loginPage.passwordInput.fill("NOT_MY_PASSWORD_DNE_ERROR");
|
||||||
|
await loginPage.submitLoginButton.click();
|
||||||
|
const toast = await loginPage.getLatestToast();
|
||||||
|
await expect(toast.locator).toBeVisible();
|
||||||
|
await expect(toast.locator).toHaveAttribute("data-type", "error");
|
||||||
|
});
|
||||||
|
|
||||||
|
test("Logging in without valid credentials displays an error", async ({
|
||||||
|
loginPage,
|
||||||
|
}) => {
|
||||||
|
await loginPage.submitLoginButton.click();
|
||||||
|
const toast = await loginPage.getLatestToast();
|
||||||
|
await expect(toast.locator).toBeVisible();
|
||||||
|
await expect(toast.locator).toHaveAttribute("data-type", "error");
|
||||||
|
});
|
||||||
|
|
||||||
|
test("Logging in with a valid username and password works as expected", async ({
|
||||||
|
page,
|
||||||
|
loginPage,
|
||||||
|
dashboardPage,
|
||||||
|
}) => {
|
||||||
|
await loginPage.usernameInput.fill(process.env["TEST_USERNAME"] || "");
|
||||||
|
await loginPage.passwordInput.fill(process.env["TEST_PASSWORD"] || "");
|
||||||
|
await loginPage.submitLoginButton.click();
|
||||||
|
await expect(loginPage.loginForm).not.toBeVisible();
|
||||||
|
await expect(dashboardPage.container).toBeVisible();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
);
|
|
@ -29,4 +29,6 @@ export default function useInitialData() {
|
||||||
// setLinks();
|
// setLinks();
|
||||||
}
|
}
|
||||||
}, [account]);
|
}, [account]);
|
||||||
|
|
||||||
|
return status;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +1,6 @@
|
||||||
import { ReactNode } from "react";
|
import { ReactNode, useEffect, useState } from "react";
|
||||||
import { useSession } from "next-auth/react";
|
|
||||||
import Loader from "../components/Loader";
|
|
||||||
import { useRouter } from "next/router";
|
import { useRouter } from "next/router";
|
||||||
import { useEffect, useState } from "react";
|
import { useSession } from "next-auth/react";
|
||||||
import useInitialData from "@/hooks/useInitialData";
|
import useInitialData from "@/hooks/useInitialData";
|
||||||
import useAccountStore from "@/store/account";
|
import useAccountStore from "@/store/account";
|
||||||
|
|
||||||
|
@ -10,75 +8,70 @@ interface Props {
|
||||||
children: ReactNode;
|
children: ReactNode;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const stripeEnabled = process.env.NEXT_PUBLIC_STRIPE === "true";
|
||||||
|
|
||||||
export default function AuthRedirect({ children }: Props) {
|
export default function AuthRedirect({ children }: Props) {
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
const { status, data } = useSession();
|
const { status } = useSession();
|
||||||
const [redirect, setRedirect] = useState(true);
|
const [shouldRenderChildren, setShouldRenderChildren] = useState(false);
|
||||||
const { account } = useAccountStore();
|
const { account } = useAccountStore();
|
||||||
|
|
||||||
const emailEnabled = process.env.NEXT_PUBLIC_EMAIL_PROVIDER === "true";
|
|
||||||
const stripeEnabled = process.env.NEXT_PUBLIC_STRIPE === "true";
|
|
||||||
|
|
||||||
useInitialData();
|
useInitialData();
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!router.pathname.startsWith("/public")) {
|
const isLoggedIn = status === "authenticated";
|
||||||
if (
|
const isUnauthenticated = status === "unauthenticated";
|
||||||
status === "authenticated" &&
|
const isPublicPage = router.pathname.startsWith("/public");
|
||||||
account.id &&
|
const hasInactiveSubscription =
|
||||||
!account.subscription?.active &&
|
account.id && !account.subscription?.active && stripeEnabled;
|
||||||
stripeEnabled
|
|
||||||
) {
|
// There are better ways of doing this... but this one works for now
|
||||||
router.push("/subscribe").then(() => {
|
const routes = [
|
||||||
setRedirect(false);
|
{ path: "/login", isProtected: false },
|
||||||
});
|
{ path: "/register", isProtected: false },
|
||||||
}
|
{ path: "/confirmation", isProtected: false },
|
||||||
// Redirect to "/choose-username" if user is authenticated and is either a subscriber OR subscription is undefiend, and doesn't have a username
|
{ path: "/forgot", isProtected: false },
|
||||||
else if (
|
{ path: "/auth/reset-password", isProtected: false },
|
||||||
emailEnabled &&
|
{ path: "/", isProtected: false },
|
||||||
status === "authenticated" &&
|
{ path: "/subscribe", isProtected: true },
|
||||||
account.subscription?.active &&
|
{ path: "/dashboard", isProtected: true },
|
||||||
stripeEnabled &&
|
{ path: "/settings", isProtected: true },
|
||||||
account.id &&
|
{ path: "/collections", isProtected: true },
|
||||||
!account.username
|
{ path: "/links", isProtected: true },
|
||||||
) {
|
{ path: "/tags", isProtected: true },
|
||||||
router.push("/choose-username").then(() => {
|
{ path: "/preserved", isProtected: true },
|
||||||
setRedirect(false);
|
{ path: "/admin", isProtected: true },
|
||||||
});
|
{ path: "/search", isProtected: true },
|
||||||
} else if (
|
];
|
||||||
status === "authenticated" &&
|
|
||||||
account.id &&
|
if (isPublicPage) {
|
||||||
(router.pathname === "/login" ||
|
setShouldRenderChildren(true);
|
||||||
router.pathname === "/register" ||
|
|
||||||
router.pathname === "/confirmation" ||
|
|
||||||
router.pathname === "/subscribe" ||
|
|
||||||
router.pathname === "/choose-username" ||
|
|
||||||
router.pathname === "/forgot" ||
|
|
||||||
router.pathname === "/")
|
|
||||||
) {
|
|
||||||
router.push("/dashboard").then(() => {
|
|
||||||
setRedirect(false);
|
|
||||||
});
|
|
||||||
} else if (
|
|
||||||
status === "unauthenticated" &&
|
|
||||||
!(
|
|
||||||
router.pathname === "/login" ||
|
|
||||||
router.pathname === "/register" ||
|
|
||||||
router.pathname === "/confirmation" ||
|
|
||||||
router.pathname === "/forgot"
|
|
||||||
)
|
|
||||||
) {
|
|
||||||
router.push("/login").then(() => {
|
|
||||||
setRedirect(false);
|
|
||||||
});
|
|
||||||
} else if (status === "loading") setRedirect(true);
|
|
||||||
else setRedirect(false);
|
|
||||||
} else {
|
} else {
|
||||||
setRedirect(false);
|
if (isLoggedIn && hasInactiveSubscription) {
|
||||||
|
redirectTo("/subscribe");
|
||||||
|
} else if (
|
||||||
|
isLoggedIn &&
|
||||||
|
!routes.some((e) => router.pathname.startsWith(e.path) && e.isProtected)
|
||||||
|
) {
|
||||||
|
redirectTo("/dashboard");
|
||||||
|
} else if (
|
||||||
|
isUnauthenticated &&
|
||||||
|
routes.some((e) => router.pathname.startsWith(e.path) && e.isProtected)
|
||||||
|
) {
|
||||||
|
redirectTo("/login");
|
||||||
|
} else {
|
||||||
|
setShouldRenderChildren(true);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}, [status, account, router.pathname]);
|
}, [status, account, router.pathname]);
|
||||||
|
|
||||||
if (status !== "loading" && !redirect) return <>{children}</>;
|
function redirectTo(destination: string) {
|
||||||
else return <></>;
|
router.push(destination).then(() => setShouldRenderChildren(true));
|
||||||
// return <>{children}</>;
|
}
|
||||||
|
|
||||||
|
if (status !== "loading" && shouldRenderChildren) {
|
||||||
|
return <>{children}</>;
|
||||||
|
} else {
|
||||||
|
return <></>;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,18 +1,27 @@
|
||||||
import useLocalSettingsStore from "@/store/localSettings";
|
import useLocalSettingsStore from "@/store/localSettings";
|
||||||
import Image from "next/image";
|
import Image from "next/image";
|
||||||
import Link from "next/link";
|
import Link from "next/link";
|
||||||
import React, { ReactNode, useEffect } from "react";
|
import React, { ReactNode } from "react";
|
||||||
|
import { Trans } from "next-i18next";
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
text?: string;
|
text?: string;
|
||||||
children: ReactNode;
|
children: ReactNode;
|
||||||
|
"data-testid"?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export default function CenteredForm({ text, children }: Props) {
|
export default function CenteredForm({
|
||||||
|
text,
|
||||||
|
children,
|
||||||
|
"data-testid": dataTestId,
|
||||||
|
}: Props) {
|
||||||
const { settings } = useLocalSettingsStore();
|
const { settings } = useLocalSettingsStore();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="absolute top-0 bottom-0 left-0 right-0 flex justify-center items-center p-5">
|
<div
|
||||||
|
className="absolute top-0 bottom-0 left-0 right-0 flex justify-center items-center p-5"
|
||||||
|
data-testid={dataTestId}
|
||||||
|
>
|
||||||
<div className="m-auto flex flex-col gap-2 w-full">
|
<div className="m-auto flex flex-col gap-2 w-full">
|
||||||
{settings.theme ? (
|
{settings.theme ? (
|
||||||
<Image
|
<Image
|
||||||
|
@ -32,11 +41,13 @@ export default function CenteredForm({ text, children }: Props) {
|
||||||
) : undefined}
|
) : undefined}
|
||||||
{children}
|
{children}
|
||||||
<p className="text-center text-xs text-neutral mb-5">
|
<p className="text-center text-xs text-neutral mb-5">
|
||||||
© {new Date().getFullYear()}{" "}
|
<Trans
|
||||||
<Link href="https://linkwarden.app" className="font-semibold">
|
values={{ date: new Date().getFullYear() }}
|
||||||
Linkwarden
|
i18nKey="all_rights_reserved"
|
||||||
</Link>
|
components={[
|
||||||
. All rights reserved.
|
<Link href="https://linkwarden.app" className="font-semibold" />,
|
||||||
|
]}
|
||||||
|
/>
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import Navbar from "@/components/Navbar";
|
import Navbar from "@/components/Navbar";
|
||||||
import AnnouncementBar from "@/components/AnnouncementBar";
|
import Announcement from "@/components/Announcement";
|
||||||
import Sidebar from "@/components/Sidebar";
|
import Sidebar from "@/components/Sidebar";
|
||||||
import { ReactNode, useEffect, useState } from "react";
|
import { ReactNode, useEffect, useState } from "react";
|
||||||
import getLatestVersion from "@/lib/client/getLatestVersion";
|
import getLatestVersion from "@/lib/client/getLatestVersion";
|
||||||
|
@ -33,27 +33,20 @@ export default function MainLayout({ children }: Props) {
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<div className="flex" data-testid="dashboard-wrapper">
|
||||||
{showAnnouncement ? (
|
{showAnnouncement ? (
|
||||||
<AnnouncementBar toggleAnnouncementBar={toggleAnnouncementBar} />
|
<Announcement toggleAnnouncementBar={toggleAnnouncementBar} />
|
||||||
) : undefined}
|
) : undefined}
|
||||||
|
|
||||||
<div className="flex">
|
|
||||||
<div className="hidden lg:block">
|
<div className="hidden lg:block">
|
||||||
<Sidebar
|
<Sidebar className={`fixed top-0`} />
|
||||||
className={`fixed ${showAnnouncement ? "top-10" : "top-0"}`}
|
|
||||||
/>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div
|
<div
|
||||||
className={`w-full sm:pb-0 pb-20 flex flex-col min-h-${
|
className={`w-full sm:pb-0 pb-20 flex flex-col min-h-screen lg:ml-80`}
|
||||||
showAnnouncement ? "full" : "screen"
|
|
||||||
} lg:ml-80 ${showAnnouncement ? "mt-10" : ""}`}
|
|
||||||
>
|
>
|
||||||
<Navbar />
|
<Navbar />
|
||||||
{children}
|
{children}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</>
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,9 +4,9 @@ import createFile from "./storage/createFile";
|
||||||
import sendToWayback from "./preservationScheme/sendToWayback";
|
import sendToWayback from "./preservationScheme/sendToWayback";
|
||||||
import { Collection, Link, User } from "@prisma/client";
|
import { Collection, Link, User } from "@prisma/client";
|
||||||
import validateUrlSize from "./validateUrlSize";
|
import validateUrlSize from "./validateUrlSize";
|
||||||
import removeFile from "./storage/removeFile";
|
|
||||||
import Jimp from "jimp";
|
|
||||||
import createFolder from "./storage/createFolder";
|
import createFolder from "./storage/createFolder";
|
||||||
|
import generatePreview from "./generatePreview";
|
||||||
|
import { removeFiles } from "./manageLinkFiles";
|
||||||
import archiveAsSinglefile from "./preservationScheme/archiveAsSinglefile";
|
import archiveAsSinglefile from "./preservationScheme/archiveAsSinglefile";
|
||||||
import archiveAsReadability from "./preservationScheme/archiveAsReadablility";
|
import archiveAsReadability from "./preservationScheme/archiveAsReadablility";
|
||||||
|
|
||||||
|
@ -43,6 +43,32 @@ export default async function archiveHandler(link: LinksAndCollectionAndOwner) {
|
||||||
}
|
}
|
||||||
|
|
||||||
const browser = await chromium.launch(browserOptions);
|
const browser = await chromium.launch(browserOptions);
|
||||||
|
const context = await browser.newContext({
|
||||||
|
...devices["Desktop Chrome"],
|
||||||
|
ignoreHTTPSErrors: process.env.IGNORE_HTTPS_ERRORS === "true",
|
||||||
|
});
|
||||||
|
|
||||||
|
const page = await context.newPage();
|
||||||
|
|
||||||
|
const timeoutPromise = new Promise((_, reject) => {
|
||||||
|
setTimeout(
|
||||||
|
() =>
|
||||||
|
reject(
|
||||||
|
new Error(
|
||||||
|
`Browser has been open for more than ${BROWSER_TIMEOUT} minutes.`
|
||||||
|
)
|
||||||
|
),
|
||||||
|
BROWSER_TIMEOUT * 60000
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
createFolder({
|
||||||
|
filePath: `archives/preview/${link.collectionId}`,
|
||||||
|
});
|
||||||
|
|
||||||
|
createFolder({
|
||||||
|
filePath: `archives/${link.collectionId}`,
|
||||||
|
});
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await Promise.race([
|
await Promise.race([
|
||||||
|
@ -53,7 +79,10 @@ export default async function archiveHandler(link: LinksAndCollectionAndOwner) {
|
||||||
? await validateUrlSize(link.url)
|
? await validateUrlSize(link.url)
|
||||||
: undefined;
|
: undefined;
|
||||||
|
|
||||||
if (validatedUrl === null)
|
if (
|
||||||
|
validatedUrl === null &&
|
||||||
|
process.env.IGNORE_URL_SIZE_LIMIT !== "true"
|
||||||
|
)
|
||||||
throw "Something went wrong while retrieving the file size.";
|
throw "Something went wrong while retrieving the file size.";
|
||||||
|
|
||||||
const contentType = validatedUrl?.get("content-type");
|
const contentType = validatedUrl?.get("content-type");
|
||||||
|
@ -134,21 +163,11 @@ export default async function archiveHandler(link: LinksAndCollectionAndOwner) {
|
||||||
|
|
||||||
// Preview
|
// Preview
|
||||||
|
|
||||||
if (
|
|
||||||
!link.preview?.startsWith("archives") &&
|
|
||||||
!link.preview?.startsWith("unavailable")
|
|
||||||
) {
|
|
||||||
const ogImageUrl = await page.evaluate(() => {
|
const ogImageUrl = await page.evaluate(() => {
|
||||||
const metaTag = document.querySelector(
|
const metaTag = document.querySelector('meta[property="og:image"]');
|
||||||
'meta[property="og:image"]'
|
|
||||||
);
|
|
||||||
return metaTag ? (metaTag as any).content : null;
|
return metaTag ? (metaTag as any).content : null;
|
||||||
});
|
});
|
||||||
|
|
||||||
createFolder({
|
|
||||||
filePath: `archives/preview/${link.collectionId}`,
|
|
||||||
});
|
|
||||||
|
|
||||||
if (ogImageUrl) {
|
if (ogImageUrl) {
|
||||||
console.log("Found og:image URL:", ogImageUrl);
|
console.log("Found og:image URL:", ogImageUrl);
|
||||||
|
|
||||||
|
@ -158,6 +177,7 @@ export default async function archiveHandler(link: LinksAndCollectionAndOwner) {
|
||||||
// Check if imageResponse is not null
|
// Check if imageResponse is not null
|
||||||
if (imageResponse && !link.preview?.startsWith("archive")) {
|
if (imageResponse && !link.preview?.startsWith("archive")) {
|
||||||
const buffer = await imageResponse.body();
|
const buffer = await imageResponse.body();
|
||||||
|
await generatePreview(buffer, link.collectionId, link.id);
|
||||||
|
|
||||||
// Check if buffer is not null
|
// Check if buffer is not null
|
||||||
if (buffer) {
|
if (buffer) {
|
||||||
|
@ -317,15 +337,7 @@ export default async function archiveHandler(link: LinksAndCollectionAndOwner) {
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
else {
|
else {
|
||||||
removeFile({ filePath: `archives/${link.collectionId}/${link.id}.png` });
|
await removeFiles(link.id, link.collectionId);
|
||||||
removeFile({ filePath: `archives/${link.collectionId}/${link.id}.html` });
|
|
||||||
removeFile({ filePath: `archives/${link.collectionId}/${link.id}.pdf` });
|
|
||||||
removeFile({
|
|
||||||
filePath: `archives/${link.collectionId}/${link.id}_readability.json`,
|
|
||||||
});
|
|
||||||
removeFile({
|
|
||||||
filePath: `archives/preview/${link.collectionId}/${link.id}.jpeg`,
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
await browser.close();
|
await browser.close();
|
||||||
|
|
|
@ -14,7 +14,7 @@ export default async function getDashboardData(
|
||||||
else if (query.sort === Sort.DescriptionZA) order = { description: "desc" };
|
else if (query.sort === Sort.DescriptionZA) order = { description: "desc" };
|
||||||
|
|
||||||
const pinnedLinks = await prisma.link.findMany({
|
const pinnedLinks = await prisma.link.findMany({
|
||||||
take: 8,
|
take: 10,
|
||||||
where: {
|
where: {
|
||||||
AND: [
|
AND: [
|
||||||
{
|
{
|
||||||
|
@ -46,7 +46,7 @@ export default async function getDashboardData(
|
||||||
});
|
});
|
||||||
|
|
||||||
const recentlyAddedLinks = await prisma.link.findMany({
|
const recentlyAddedLinks = await prisma.link.findMany({
|
||||||
take: 8,
|
take: 10,
|
||||||
where: {
|
where: {
|
||||||
collection: {
|
collection: {
|
||||||
OR: [
|
OR: [
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import { prisma } from "@/lib/api/db";
|
import { prisma } from "@/lib/api/db";
|
||||||
import { UsersAndCollections } from "@prisma/client";
|
import { UsersAndCollections } from "@prisma/client";
|
||||||
import getPermission from "@/lib/api/getPermission";
|
import getPermission from "@/lib/api/getPermission";
|
||||||
import removeFile from "@/lib/api/storage/removeFile";
|
import { removeFiles } from "@/lib/api/manageLinkFiles";
|
||||||
|
|
||||||
export default async function deleteLinksById(
|
export default async function deleteLinksById(
|
||||||
userId: number,
|
userId: number,
|
||||||
|
@ -43,18 +43,7 @@ export default async function deleteLinksById(
|
||||||
const linkId = linkIds[i];
|
const linkId = linkIds[i];
|
||||||
const collectionIsAccessible = collectionIsAccessibleArray[i];
|
const collectionIsAccessible = collectionIsAccessibleArray[i];
|
||||||
|
|
||||||
removeFile({
|
if (collectionIsAccessible) removeFiles(linkId, collectionIsAccessible.id);
|
||||||
filePath: `archives/${collectionIsAccessible?.id}/${linkId}.pdf`,
|
|
||||||
});
|
|
||||||
removeFile({
|
|
||||||
filePath: `archives/${collectionIsAccessible?.id}/${linkId}.png`,
|
|
||||||
});
|
|
||||||
removeFile({
|
|
||||||
filePath: `archives/${collectionIsAccessible?.id}/${linkId}_readability.json`,
|
|
||||||
});
|
|
||||||
removeFile({
|
|
||||||
filePath: `archives/${collectionIsAccessible?.id}/${linkId}.html`,
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return { response: deletedLinks, status: 200 };
|
return { response: deletedLinks, status: 200 };
|
||||||
|
|
|
@ -2,6 +2,7 @@ import { prisma } from "@/lib/api/db";
|
||||||
import { Link, UsersAndCollections } from "@prisma/client";
|
import { Link, UsersAndCollections } from "@prisma/client";
|
||||||
import getPermission from "@/lib/api/getPermission";
|
import getPermission from "@/lib/api/getPermission";
|
||||||
import removeFile from "@/lib/api/storage/removeFile";
|
import removeFile from "@/lib/api/storage/removeFile";
|
||||||
|
import { removeFiles } from "@/lib/api/manageLinkFiles";
|
||||||
|
|
||||||
export default async function deleteLink(userId: number, linkId: number) {
|
export default async function deleteLink(userId: number, linkId: number) {
|
||||||
if (!linkId) return { response: "Please choose a valid link.", status: 401 };
|
if (!linkId) return { response: "Please choose a valid link.", status: 401 };
|
||||||
|
@ -12,7 +13,10 @@ export default async function deleteLink(userId: number, linkId: number) {
|
||||||
(e: UsersAndCollections) => e.userId === userId && e.canDelete
|
(e: UsersAndCollections) => e.userId === userId && e.canDelete
|
||||||
);
|
);
|
||||||
|
|
||||||
if (!(collectionIsAccessible?.ownerId === userId || memberHasAccess))
|
if (
|
||||||
|
!collectionIsAccessible ||
|
||||||
|
!(collectionIsAccessible?.ownerId === userId || memberHasAccess)
|
||||||
|
)
|
||||||
return { response: "Collection is not accessible.", status: 401 };
|
return { response: "Collection is not accessible.", status: 401 };
|
||||||
|
|
||||||
const deleteLink: Link = await prisma.link.delete({
|
const deleteLink: Link = await prisma.link.delete({
|
||||||
|
@ -21,18 +25,7 @@ export default async function deleteLink(userId: number, linkId: number) {
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
removeFile({
|
removeFiles(linkId, collectionIsAccessible.id);
|
||||||
filePath: `archives/${collectionIsAccessible?.id}/${linkId}.pdf`,
|
|
||||||
});
|
|
||||||
removeFile({
|
|
||||||
filePath: `archives/${collectionIsAccessible?.id}/${linkId}.png`,
|
|
||||||
});
|
|
||||||
removeFile({
|
|
||||||
filePath: `archives/${collectionIsAccessible?.id}/${linkId}_readability.json`,
|
|
||||||
});
|
|
||||||
removeFile({
|
|
||||||
filePath: `archives/${collectionIsAccessible?.id}/${linkId}.html`,
|
|
||||||
});
|
|
||||||
|
|
||||||
return { response: deleteLink, status: 200 };
|
return { response: deleteLink, status: 200 };
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,7 @@ import { prisma } from "@/lib/api/db";
|
||||||
import { LinkIncludingShortenedCollectionAndTags } from "@/types/global";
|
import { LinkIncludingShortenedCollectionAndTags } from "@/types/global";
|
||||||
import { UsersAndCollections } from "@prisma/client";
|
import { UsersAndCollections } from "@prisma/client";
|
||||||
import getPermission from "@/lib/api/getPermission";
|
import getPermission from "@/lib/api/getPermission";
|
||||||
import moveFile from "@/lib/api/storage/moveFile";
|
import { moveFiles } from "@/lib/api/manageLinkFiles";
|
||||||
|
|
||||||
export default async function updateLinkById(
|
export default async function updateLinkById(
|
||||||
userId: number,
|
userId: number,
|
||||||
|
@ -146,25 +146,7 @@ export default async function updateLinkById(
|
||||||
});
|
});
|
||||||
|
|
||||||
if (collectionIsAccessible?.id !== data.collection.id) {
|
if (collectionIsAccessible?.id !== data.collection.id) {
|
||||||
await moveFile(
|
await moveFiles(linkId, collectionIsAccessible?.id, data.collection.id);
|
||||||
`archives/${collectionIsAccessible?.id}/${linkId}.pdf`,
|
|
||||||
`archives/${data.collection.id}/${linkId}.pdf`
|
|
||||||
);
|
|
||||||
|
|
||||||
await moveFile(
|
|
||||||
`archives/${collectionIsAccessible?.id}/${linkId}.png`,
|
|
||||||
`archives/${data.collection.id}/${linkId}.png`
|
|
||||||
);
|
|
||||||
|
|
||||||
await moveFile(
|
|
||||||
`archives/${collectionIsAccessible?.id}/${linkId}_readability.json`,
|
|
||||||
`archives/${data.collection.id}/${linkId}_readability.json`
|
|
||||||
);
|
|
||||||
|
|
||||||
await moveFile(
|
|
||||||
`archives/${collectionIsAccessible?.id}/${linkId}.html`,
|
|
||||||
`archives/${data.collection.id}/${linkId}.html`
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return { response: updatedLink, status: 200 };
|
return { response: updatedLink, status: 200 };
|
||||||
|
|
|
@ -12,6 +12,7 @@ export default async function postLink(
|
||||||
link: LinkIncludingShortenedCollectionAndTags,
|
link: LinkIncludingShortenedCollectionAndTags,
|
||||||
userId: number
|
userId: number
|
||||||
) {
|
) {
|
||||||
|
if (link.url || link.type === "url") {
|
||||||
try {
|
try {
|
||||||
new URL(link.url || "");
|
new URL(link.url || "");
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
@ -21,6 +22,7 @@ export default async function postLink(
|
||||||
status: 400,
|
status: 400,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (!link.collection.id && link.collection.name) {
|
if (!link.collection.id && link.collection.name) {
|
||||||
link.collection.name = link.collection.name.trim();
|
link.collection.name = link.collection.name.trim();
|
||||||
|
@ -117,15 +119,24 @@ export default async function postLink(
|
||||||
});
|
});
|
||||||
|
|
||||||
if (user?.preventDuplicateLinks) {
|
if (user?.preventDuplicateLinks) {
|
||||||
|
const url = link.url?.trim().replace(/\/+$/, ""); // trim and remove trailing slashes from the URL
|
||||||
|
const hasWwwPrefix = url?.includes(`://www.`);
|
||||||
|
const urlWithoutWww = hasWwwPrefix ? url?.replace(`://www.`, "://") : url;
|
||||||
|
const urlWithWww = hasWwwPrefix ? url : url?.replace("://", `://www.`);
|
||||||
|
|
||||||
|
console.log(url, urlWithoutWww, urlWithWww);
|
||||||
|
|
||||||
const existingLink = await prisma.link.findFirst({
|
const existingLink = await prisma.link.findFirst({
|
||||||
where: {
|
where: {
|
||||||
url: link.url?.trim(),
|
OR: [{ url: urlWithWww }, { url: urlWithoutWww }],
|
||||||
collection: {
|
collection: {
|
||||||
ownerId: userId,
|
ownerId: userId,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
console.log(url, urlWithoutWww, urlWithWww, "DONE!");
|
||||||
|
|
||||||
if (existingLink)
|
if (existingLink)
|
||||||
return {
|
return {
|
||||||
response: "Link already exists",
|
response: "Link already exists",
|
||||||
|
@ -149,12 +160,13 @@ export default async function postLink(
|
||||||
|
|
||||||
link.collection.name = link.collection.name.trim();
|
link.collection.name = link.collection.name.trim();
|
||||||
|
|
||||||
const description =
|
const title =
|
||||||
link.description && link.description !== ""
|
!(link.name && link.name !== "") && link.url
|
||||||
? link.description
|
|
||||||
: link.url
|
|
||||||
? await getTitle(link.url)
|
? await getTitle(link.url)
|
||||||
: undefined;
|
: "";
|
||||||
|
|
||||||
|
const name =
|
||||||
|
link.name && link.name !== "" ? link.name : link.url ? title : "";
|
||||||
|
|
||||||
const validatedUrl = link.url ? await validateUrlSize(link.url) : undefined;
|
const validatedUrl = link.url ? await validateUrlSize(link.url) : undefined;
|
||||||
|
|
||||||
|
@ -172,9 +184,9 @@ export default async function postLink(
|
||||||
|
|
||||||
const newLink = await prisma.link.create({
|
const newLink = await prisma.link.create({
|
||||||
data: {
|
data: {
|
||||||
url: link.url?.trim(),
|
url: link.url?.trim().replace(/\/+$/, "") || null,
|
||||||
name: link.name,
|
name,
|
||||||
description,
|
description: link.description,
|
||||||
type: linkType,
|
type: linkType,
|
||||||
collection: {
|
collection: {
|
||||||
connect: {
|
connect: {
|
||||||
|
|
|
@ -2,6 +2,7 @@ import { prisma } from "@/lib/api/db";
|
||||||
import createFolder from "@/lib/api/storage/createFolder";
|
import createFolder from "@/lib/api/storage/createFolder";
|
||||||
import { JSDOM } from "jsdom";
|
import { JSDOM } from "jsdom";
|
||||||
import { parse, Node, Element, TextNode } from "himalaya";
|
import { parse, Node, Element, TextNode } from "himalaya";
|
||||||
|
import { writeFileSync } from "fs";
|
||||||
|
|
||||||
const MAX_LINKS_PER_USER = Number(process.env.MAX_LINKS_PER_USER) || 30000;
|
const MAX_LINKS_PER_USER = Number(process.env.MAX_LINKS_PER_USER) || 30000;
|
||||||
|
|
||||||
|
@ -36,7 +37,9 @@ export default async function importFromHTMLFile(
|
||||||
|
|
||||||
const jsonData = parse(document.documentElement.outerHTML);
|
const jsonData = parse(document.documentElement.outerHTML);
|
||||||
|
|
||||||
for (const item of jsonData) {
|
const processedArray = processNodes(jsonData);
|
||||||
|
|
||||||
|
for (const item of processedArray) {
|
||||||
console.log(item);
|
console.log(item);
|
||||||
await processBookmarks(userId, item as Element);
|
await processBookmarks(userId, item as Element);
|
||||||
}
|
}
|
||||||
|
@ -74,7 +77,9 @@ async function processBookmarks(
|
||||||
} else if (item.type === "element" && item.tagName === "a") {
|
} else if (item.type === "element" && item.tagName === "a") {
|
||||||
// process link
|
// process link
|
||||||
|
|
||||||
const linkUrl = item?.attributes.find((e) => e.key === "href")?.value;
|
const linkUrl = item?.attributes.find(
|
||||||
|
(e) => e.key.toLowerCase() === "href"
|
||||||
|
)?.value;
|
||||||
const linkName = (
|
const linkName = (
|
||||||
item?.children.find((e) => e.type === "text") as TextNode
|
item?.children.find((e) => e.type === "text") as TextNode
|
||||||
)?.content;
|
)?.content;
|
||||||
|
@ -82,14 +87,33 @@ async function processBookmarks(
|
||||||
.find((e) => e.key === "tags")
|
.find((e) => e.key === "tags")
|
||||||
?.value.split(",");
|
?.value.split(",");
|
||||||
|
|
||||||
|
// set date if available
|
||||||
|
const linkDateValue = item?.attributes.find(
|
||||||
|
(e) => e.key.toLowerCase() === "add_date"
|
||||||
|
)?.value;
|
||||||
|
|
||||||
|
const linkDate = linkDateValue
|
||||||
|
? new Date(Number(linkDateValue) * 1000)
|
||||||
|
: undefined;
|
||||||
|
|
||||||
|
let linkDesc =
|
||||||
|
(
|
||||||
|
(
|
||||||
|
item?.children?.find(
|
||||||
|
(e) => e.type === "element" && e.tagName === "dd"
|
||||||
|
) as Element
|
||||||
|
)?.children[0] as TextNode
|
||||||
|
)?.content || "";
|
||||||
|
|
||||||
if (linkUrl && parentCollectionId) {
|
if (linkUrl && parentCollectionId) {
|
||||||
await createLink(
|
await createLink(
|
||||||
userId,
|
userId,
|
||||||
linkUrl,
|
linkUrl,
|
||||||
parentCollectionId,
|
parentCollectionId,
|
||||||
linkName,
|
linkName,
|
||||||
"",
|
linkDesc,
|
||||||
linkTags
|
linkTags,
|
||||||
|
linkDate
|
||||||
);
|
);
|
||||||
} else if (linkUrl) {
|
} else if (linkUrl) {
|
||||||
// create a collection named "Imported Bookmarks" and add the link to it
|
// create a collection named "Imported Bookmarks" and add the link to it
|
||||||
|
@ -100,8 +124,9 @@ async function processBookmarks(
|
||||||
linkUrl,
|
linkUrl,
|
||||||
collectionId,
|
collectionId,
|
||||||
linkName,
|
linkName,
|
||||||
"",
|
linkDesc,
|
||||||
linkTags
|
linkTags,
|
||||||
|
linkDate
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -160,7 +185,8 @@ const createLink = async (
|
||||||
collectionId: number,
|
collectionId: number,
|
||||||
name?: string,
|
name?: string,
|
||||||
description?: string,
|
description?: string,
|
||||||
tags?: string[]
|
tags?: string[],
|
||||||
|
importDate?: Date
|
||||||
) => {
|
) => {
|
||||||
await prisma.link.create({
|
await prisma.link.create({
|
||||||
data: {
|
data: {
|
||||||
|
@ -193,6 +219,48 @@ const createLink = async (
|
||||||
}),
|
}),
|
||||||
}
|
}
|
||||||
: undefined,
|
: undefined,
|
||||||
|
importDate: importDate || undefined,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
function processNodes(nodes: Node[]) {
|
||||||
|
const findAndProcessDL = (node: Node) => {
|
||||||
|
if (node.type === "element" && node.tagName === "dl") {
|
||||||
|
processDLChildren(node);
|
||||||
|
} else if (
|
||||||
|
node.type === "element" &&
|
||||||
|
node.children &&
|
||||||
|
node.children.length
|
||||||
|
) {
|
||||||
|
node.children.forEach((child) => findAndProcessDL(child));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const processDLChildren = (dlNode: Element) => {
|
||||||
|
dlNode.children.forEach((child, i) => {
|
||||||
|
if (child.type === "element" && child.tagName === "dt") {
|
||||||
|
const nextSibling = dlNode.children[i + 1];
|
||||||
|
if (
|
||||||
|
nextSibling &&
|
||||||
|
nextSibling.type === "element" &&
|
||||||
|
nextSibling.tagName === "dd"
|
||||||
|
) {
|
||||||
|
const aElement = child.children.find(
|
||||||
|
(el) => el.type === "element" && el.tagName === "a"
|
||||||
|
);
|
||||||
|
if (aElement && aElement.type === "element") {
|
||||||
|
// Add the 'dd' element as a child of the 'a' element
|
||||||
|
aElement.children.push(nextSibling);
|
||||||
|
// Remove the 'dd' from the parent 'dl' to avoid duplicate processing
|
||||||
|
dlNode.children.splice(i + 1, 1);
|
||||||
|
// Adjust the loop counter due to the removal
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
nodes.forEach(findAndProcessDL);
|
||||||
|
return nodes;
|
||||||
|
}
|
||||||
|
|
|
@ -54,7 +54,7 @@ export default async function importFromLinkwarden(
|
||||||
|
|
||||||
// Import Links
|
// Import Links
|
||||||
for (const link of e.links) {
|
for (const link of e.links) {
|
||||||
const newLink = await prisma.link.create({
|
await prisma.link.create({
|
||||||
data: {
|
data: {
|
||||||
url: link.url,
|
url: link.url,
|
||||||
name: link.name,
|
name: link.name,
|
||||||
|
|
|
@ -0,0 +1,115 @@
|
||||||
|
import { prisma } from "@/lib/api/db";
|
||||||
|
import { Backup } from "@/types/global";
|
||||||
|
import createFolder from "@/lib/api/storage/createFolder";
|
||||||
|
|
||||||
|
const MAX_LINKS_PER_USER = Number(process.env.MAX_LINKS_PER_USER) || 30000;
|
||||||
|
|
||||||
|
type WallabagBackup = {
|
||||||
|
is_archived: number;
|
||||||
|
is_starred: number;
|
||||||
|
tags: String[];
|
||||||
|
is_public: boolean;
|
||||||
|
id: number;
|
||||||
|
title: string;
|
||||||
|
url: string;
|
||||||
|
content: string;
|
||||||
|
created_at: Date;
|
||||||
|
updated_at: Date;
|
||||||
|
published_by: string[];
|
||||||
|
starred_at: Date;
|
||||||
|
annotations: any[];
|
||||||
|
mimetype: string;
|
||||||
|
language: string;
|
||||||
|
reading_time: number;
|
||||||
|
domain_name: string;
|
||||||
|
preview_picture: string;
|
||||||
|
http_status: string;
|
||||||
|
headers: Record<string, string>;
|
||||||
|
}[];
|
||||||
|
|
||||||
|
export default async function importFromWallabag(
|
||||||
|
userId: number,
|
||||||
|
rawData: string
|
||||||
|
) {
|
||||||
|
const data: WallabagBackup = JSON.parse(rawData);
|
||||||
|
|
||||||
|
const backup = data.filter((e) => e.url);
|
||||||
|
|
||||||
|
let totalImports = backup.length;
|
||||||
|
|
||||||
|
const numberOfLinksTheUserHas = await prisma.link.count({
|
||||||
|
where: {
|
||||||
|
collection: {
|
||||||
|
ownerId: userId,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
if (totalImports + numberOfLinksTheUserHas > MAX_LINKS_PER_USER)
|
||||||
|
return {
|
||||||
|
response: `Error: Each user can only have a maximum of ${MAX_LINKS_PER_USER} Links.`,
|
||||||
|
status: 400,
|
||||||
|
};
|
||||||
|
|
||||||
|
await prisma
|
||||||
|
.$transaction(
|
||||||
|
async () => {
|
||||||
|
const newCollection = await prisma.collection.create({
|
||||||
|
data: {
|
||||||
|
owner: {
|
||||||
|
connect: {
|
||||||
|
id: userId,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
name: "Imports",
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
createFolder({ filePath: `archives/${newCollection.id}` });
|
||||||
|
|
||||||
|
for (const link of backup) {
|
||||||
|
await prisma.link.create({
|
||||||
|
data: {
|
||||||
|
pinnedBy: link.is_starred
|
||||||
|
? { connect: { id: userId } }
|
||||||
|
: undefined,
|
||||||
|
url: link.url,
|
||||||
|
name: link.title || "",
|
||||||
|
textContent: link.content || "",
|
||||||
|
importDate: link.created_at || null,
|
||||||
|
collection: {
|
||||||
|
connect: {
|
||||||
|
id: newCollection.id,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
tags:
|
||||||
|
link.tags && link.tags[0]
|
||||||
|
? {
|
||||||
|
connectOrCreate: link.tags.map((tag) => ({
|
||||||
|
where: {
|
||||||
|
name_ownerId: {
|
||||||
|
name: tag.trim(),
|
||||||
|
ownerId: userId,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
create: {
|
||||||
|
name: tag.trim(),
|
||||||
|
owner: {
|
||||||
|
connect: {
|
||||||
|
id: userId,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})),
|
||||||
|
}
|
||||||
|
: undefined,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{ timeout: 30000 }
|
||||||
|
)
|
||||||
|
.catch((err) => console.log(err));
|
||||||
|
|
||||||
|
return { response: "Success.", status: 200 };
|
||||||
|
}
|
|
@ -0,0 +1,21 @@
|
||||||
|
import { prisma } from "@/lib/api/db";
|
||||||
|
|
||||||
|
export default async function getUsers() {
|
||||||
|
// Get all users
|
||||||
|
const users = await prisma.user.findMany({
|
||||||
|
select: {
|
||||||
|
id: true,
|
||||||
|
username: true,
|
||||||
|
email: true,
|
||||||
|
emailVerified: true,
|
||||||
|
subscriptions: {
|
||||||
|
select: {
|
||||||
|
active: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
createdAt: true,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
return { response: users, status: 200 };
|
||||||
|
}
|
|
@ -1,12 +1,15 @@
|
||||||
import { prisma } from "@/lib/api/db";
|
import { prisma } from "@/lib/api/db";
|
||||||
import type { NextApiRequest, NextApiResponse } from "next";
|
import type { NextApiRequest, NextApiResponse } from "next";
|
||||||
import bcrypt from "bcrypt";
|
import bcrypt from "bcrypt";
|
||||||
|
import isServerAdmin from "../../isServerAdmin";
|
||||||
|
|
||||||
const emailEnabled =
|
const emailEnabled =
|
||||||
process.env.EMAIL_FROM && process.env.EMAIL_SERVER ? true : false;
|
process.env.EMAIL_FROM && process.env.EMAIL_SERVER ? true : false;
|
||||||
|
const stripeEnabled = process.env.STRIPE_SECRET_KEY ? true : false;
|
||||||
|
|
||||||
interface Data {
|
interface Data {
|
||||||
response: string | object;
|
response: string | object;
|
||||||
|
status: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface User {
|
interface User {
|
||||||
|
@ -18,10 +21,12 @@ interface User {
|
||||||
|
|
||||||
export default async function postUser(
|
export default async function postUser(
|
||||||
req: NextApiRequest,
|
req: NextApiRequest,
|
||||||
res: NextApiResponse<Data>
|
res: NextApiResponse
|
||||||
) {
|
): Promise<Data> {
|
||||||
if (process.env.NEXT_PUBLIC_DISABLE_REGISTRATION === "true") {
|
let isAdmin = await isServerAdmin({ req });
|
||||||
return res.status(400).json({ response: "Registration is disabled." });
|
|
||||||
|
if (process.env.NEXT_PUBLIC_DISABLE_REGISTRATION === "true" && !isAdmin) {
|
||||||
|
return { response: "Registration is disabled.", status: 400 };
|
||||||
}
|
}
|
||||||
|
|
||||||
const body: User = req.body;
|
const body: User = req.body;
|
||||||
|
@ -31,61 +36,106 @@ export default async function postUser(
|
||||||
: !body.username || !body.password || !body.name;
|
: !body.username || !body.password || !body.name;
|
||||||
|
|
||||||
if (!body.password || body.password.length < 8)
|
if (!body.password || body.password.length < 8)
|
||||||
return res
|
return { response: "Password must be at least 8 characters.", status: 400 };
|
||||||
.status(400)
|
|
||||||
.json({ response: "Password must be at least 8 characters." });
|
|
||||||
|
|
||||||
if (checkHasEmptyFields)
|
if (checkHasEmptyFields)
|
||||||
return res
|
return { response: "Please fill out all the fields.", status: 400 };
|
||||||
.status(400)
|
|
||||||
.json({ response: "Please fill out all the fields." });
|
|
||||||
|
|
||||||
// Check email (if enabled)
|
// Check email (if enabled)
|
||||||
const checkEmail =
|
const checkEmail =
|
||||||
/^(([^<>()[\]\.,;:\s@\"]+(\.[^<>()[\]\.,;:\s@\"]+)*)|(\".+\"))@(([^<>()[\]\.,;:\s@\"]+\.)+[^<>()[\]\.,;:\s@\"]{2,})$/i;
|
/^(([^<>()[\]\.,;:\s@\"]+(\.[^<>()[\]\.,;:\s@\"]+)*)|(\".+\"))@(([^<>()[\]\.,;:\s@\"]+\.)+[^<>()[\]\.,;:\s@\"]{2,})$/i;
|
||||||
if (emailEnabled && !checkEmail.test(body.email?.toLowerCase() || ""))
|
if (emailEnabled && !checkEmail.test(body.email?.toLowerCase() || ""))
|
||||||
return res.status(400).json({
|
return { response: "Please enter a valid email.", status: 400 };
|
||||||
response: "Please enter a valid email.",
|
|
||||||
});
|
|
||||||
|
|
||||||
// Check username (if email was disabled)
|
// Check username (if email was disabled)
|
||||||
const checkUsername = RegExp("^[a-z0-9_-]{3,31}$");
|
const checkUsername = RegExp("^[a-z0-9_-]{3,31}$");
|
||||||
if (!emailEnabled && !checkUsername.test(body.username?.toLowerCase() || ""))
|
if (!emailEnabled && !checkUsername.test(body.username?.toLowerCase() || ""))
|
||||||
return res.status(400).json({
|
return {
|
||||||
response:
|
response:
|
||||||
"Username has to be between 3-30 characters, no spaces and special characters are allowed.",
|
"Username has to be between 3-30 characters, no spaces and special characters are allowed.",
|
||||||
});
|
status: 400,
|
||||||
|
};
|
||||||
|
|
||||||
const checkIfUserExists = await prisma.user.findFirst({
|
const checkIfUserExists = await prisma.user.findFirst({
|
||||||
where: emailEnabled
|
where: {
|
||||||
? {
|
OR: [
|
||||||
email: body.email?.toLowerCase().trim(),
|
{
|
||||||
}
|
email: body.email ? body.email.toLowerCase().trim() : undefined,
|
||||||
: {
|
},
|
||||||
username: (body.username as string).toLowerCase().trim(),
|
{
|
||||||
|
username: body.username
|
||||||
|
? body.username.toLowerCase().trim()
|
||||||
|
: undefined,
|
||||||
|
},
|
||||||
|
],
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!checkIfUserExists) {
|
if (!checkIfUserExists) {
|
||||||
|
const autoGeneratedUsername =
|
||||||
|
"user" + Math.round(Math.random() * 1000000000);
|
||||||
|
|
||||||
const saltRounds = 10;
|
const saltRounds = 10;
|
||||||
|
|
||||||
const hashedPassword = bcrypt.hashSync(body.password, saltRounds);
|
const hashedPassword = bcrypt.hashSync(body.password, saltRounds);
|
||||||
|
|
||||||
|
// Subscription dates
|
||||||
|
const currentPeriodStart = new Date();
|
||||||
|
const currentPeriodEnd = new Date();
|
||||||
|
currentPeriodEnd.setFullYear(currentPeriodEnd.getFullYear() + 1000); // end date is in 1000 years...
|
||||||
|
|
||||||
|
if (isAdmin) {
|
||||||
|
const user = await prisma.user.create({
|
||||||
|
data: {
|
||||||
|
name: body.name,
|
||||||
|
username: emailEnabled
|
||||||
|
? autoGeneratedUsername
|
||||||
|
: (body.username as string).toLowerCase().trim(),
|
||||||
|
email: emailEnabled ? body.email?.toLowerCase().trim() : undefined,
|
||||||
|
password: hashedPassword,
|
||||||
|
emailVerified: new Date(),
|
||||||
|
subscriptions: stripeEnabled
|
||||||
|
? {
|
||||||
|
create: {
|
||||||
|
stripeSubscriptionId:
|
||||||
|
"fake_sub_" + Math.round(Math.random() * 10000000000000),
|
||||||
|
active: true,
|
||||||
|
currentPeriodStart,
|
||||||
|
currentPeriodEnd,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
: undefined,
|
||||||
|
},
|
||||||
|
select: {
|
||||||
|
id: true,
|
||||||
|
username: true,
|
||||||
|
email: true,
|
||||||
|
emailVerified: true,
|
||||||
|
subscriptions: {
|
||||||
|
select: {
|
||||||
|
active: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
createdAt: true,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
return { response: user, status: 201 };
|
||||||
|
} else {
|
||||||
await prisma.user.create({
|
await prisma.user.create({
|
||||||
data: {
|
data: {
|
||||||
name: body.name,
|
name: body.name,
|
||||||
username: emailEnabled
|
username: emailEnabled
|
||||||
? undefined
|
? autoGeneratedUsername
|
||||||
: (body.username as string).toLowerCase().trim(),
|
: (body.username as string).toLowerCase().trim(),
|
||||||
email: emailEnabled ? body.email?.toLowerCase().trim() : undefined,
|
email: emailEnabled ? body.email?.toLowerCase().trim() : undefined,
|
||||||
password: hashedPassword,
|
password: hashedPassword,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
return res.status(201).json({ response: "User successfully created." });
|
return { response: "User successfully created.", status: 201 };
|
||||||
} else if (checkIfUserExists) {
|
}
|
||||||
return res.status(400).json({
|
} else {
|
||||||
response: `${emailEnabled ? "Email" : "Username"} already exists.`,
|
return { response: "Email or Username already exists.", status: 400 };
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,12 +5,10 @@ import Stripe from "stripe";
|
||||||
import { DeleteUserBody } from "@/types/global";
|
import { DeleteUserBody } from "@/types/global";
|
||||||
import removeFile from "@/lib/api/storage/removeFile";
|
import removeFile from "@/lib/api/storage/removeFile";
|
||||||
|
|
||||||
const keycloakEnabled = process.env.KEYCLOAK_CLIENT_SECRET;
|
|
||||||
const authentikEnabled = process.env.AUTHENTIK_CLIENT_SECRET;
|
|
||||||
|
|
||||||
export default async function deleteUserById(
|
export default async function deleteUserById(
|
||||||
userId: number,
|
userId: number,
|
||||||
body: DeleteUserBody
|
body: DeleteUserBody,
|
||||||
|
isServerAdmin?: boolean
|
||||||
) {
|
) {
|
||||||
// First, we retrieve the user from the database
|
// First, we retrieve the user from the database
|
||||||
const user = await prisma.user.findUnique({
|
const user = await prisma.user.findUnique({
|
||||||
|
@ -24,25 +22,37 @@ export default async function deleteUserById(
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
// Then, we check if the provided password matches the one stored in the database (disabled in Keycloak integration)
|
if (!isServerAdmin) {
|
||||||
if (!keycloakEnabled && !authentikEnabled) {
|
if (user.password) {
|
||||||
const isPasswordValid = bcrypt.compareSync(
|
const isPasswordValid = bcrypt.compareSync(
|
||||||
body.password,
|
body.password,
|
||||||
user.password as string
|
user.password as string
|
||||||
);
|
);
|
||||||
|
|
||||||
if (!isPasswordValid) {
|
if (!isPasswordValid && !isServerAdmin) {
|
||||||
return {
|
return {
|
||||||
response: "Invalid credentials.",
|
response: "Invalid credentials.",
|
||||||
status: 401, // Unauthorized
|
status: 401, // Unauthorized
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
return {
|
||||||
|
response:
|
||||||
|
"User has no password. Please reset your password from the forgot password page.",
|
||||||
|
status: 401, // Unauthorized
|
||||||
|
};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Delete the user and all related data within a transaction
|
// Delete the user and all related data within a transaction
|
||||||
await prisma
|
await prisma
|
||||||
.$transaction(
|
.$transaction(
|
||||||
async (prisma) => {
|
async (prisma) => {
|
||||||
|
// Delete Access Tokens
|
||||||
|
await prisma.accessToken.deleteMany({
|
||||||
|
where: { userId },
|
||||||
|
});
|
||||||
|
|
||||||
// Delete whitelisted users
|
// Delete whitelisted users
|
||||||
await prisma.whitelistedUser.deleteMany({
|
await prisma.whitelistedUser.deleteMany({
|
||||||
where: { userId },
|
where: { userId },
|
||||||
|
@ -71,6 +81,10 @@ export default async function deleteUserById(
|
||||||
|
|
||||||
// Delete archive folders
|
// Delete archive folders
|
||||||
removeFolder({ filePath: `archives/${collection.id}` });
|
removeFolder({ filePath: `archives/${collection.id}` });
|
||||||
|
|
||||||
|
await removeFolder({
|
||||||
|
filePath: `archives/preview/${collection.id}`,
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// Delete collections after cleaning up related data
|
// Delete collections after cleaning up related data
|
||||||
|
@ -80,9 +94,11 @@ export default async function deleteUserById(
|
||||||
|
|
||||||
// Delete subscription
|
// Delete subscription
|
||||||
if (process.env.STRIPE_SECRET_KEY)
|
if (process.env.STRIPE_SECRET_KEY)
|
||||||
await prisma.subscription.delete({
|
await prisma.subscription
|
||||||
|
.delete({
|
||||||
where: { userId },
|
where: { userId },
|
||||||
});
|
})
|
||||||
|
.catch((err) => console.log(err));
|
||||||
|
|
||||||
await prisma.usersAndCollections.deleteMany({
|
await prisma.usersAndCollections.deleteMany({
|
||||||
where: {
|
where: {
|
||||||
|
|
|
@ -3,8 +3,9 @@ import { AccountSettings } from "@/types/global";
|
||||||
import bcrypt from "bcrypt";
|
import bcrypt from "bcrypt";
|
||||||
import removeFile from "@/lib/api/storage/removeFile";
|
import removeFile from "@/lib/api/storage/removeFile";
|
||||||
import createFile from "@/lib/api/storage/createFile";
|
import createFile from "@/lib/api/storage/createFile";
|
||||||
import updateCustomerEmail from "@/lib/api/updateCustomerEmail";
|
|
||||||
import createFolder from "@/lib/api/storage/createFolder";
|
import createFolder from "@/lib/api/storage/createFolder";
|
||||||
|
import sendChangeEmailVerificationRequest from "@/lib/api/sendChangeEmailVerificationRequest";
|
||||||
|
import { i18n } from "next-i18next.config";
|
||||||
|
|
||||||
const emailEnabled =
|
const emailEnabled =
|
||||||
process.env.EMAIL_FROM && process.env.EMAIL_SERVER ? true : false;
|
process.env.EMAIL_FROM && process.env.EMAIL_SERVER ? true : false;
|
||||||
|
@ -13,52 +14,6 @@ export default async function updateUserById(
|
||||||
userId: number,
|
userId: number,
|
||||||
data: AccountSettings
|
data: AccountSettings
|
||||||
) {
|
) {
|
||||||
const ssoUser = await prisma.account.findFirst({
|
|
||||||
where: {
|
|
||||||
userId: userId,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
const user = await prisma.user.findUnique({
|
|
||||||
where: {
|
|
||||||
id: userId,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
if (ssoUser) {
|
|
||||||
// deny changes to SSO-defined properties
|
|
||||||
if (data.email !== user?.email) {
|
|
||||||
return {
|
|
||||||
response: "SSO users cannot change their email.",
|
|
||||||
status: 400,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
if (data.newPassword) {
|
|
||||||
return {
|
|
||||||
response: "SSO Users cannot change their password.",
|
|
||||||
status: 400,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
if (data.name !== user?.name) {
|
|
||||||
return {
|
|
||||||
response: "SSO Users cannot change their name.",
|
|
||||||
status: 400,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
if (data.username !== user?.username) {
|
|
||||||
return {
|
|
||||||
response: "SSO Users cannot change their username.",
|
|
||||||
status: 400,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
if (data.image?.startsWith("data:image/jpeg;base64")) {
|
|
||||||
return {
|
|
||||||
response: "SSO Users cannot change their avatar.",
|
|
||||||
status: 400,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// verify only for non-SSO users
|
|
||||||
// SSO users cannot change their email, password, name, username, or avatar
|
|
||||||
if (emailEnabled && !data.email)
|
if (emailEnabled && !data.email)
|
||||||
return {
|
return {
|
||||||
response: "Email invalid.",
|
response: "Email invalid.",
|
||||||
|
@ -69,11 +24,7 @@ export default async function updateUserById(
|
||||||
response: "Username invalid.",
|
response: "Username invalid.",
|
||||||
status: 400,
|
status: 400,
|
||||||
};
|
};
|
||||||
if (data.newPassword && data.newPassword?.length < 8)
|
|
||||||
return {
|
|
||||||
response: "Password must be at least 8 characters.",
|
|
||||||
status: 400,
|
|
||||||
};
|
|
||||||
// Check email (if enabled)
|
// Check email (if enabled)
|
||||||
const checkEmail =
|
const checkEmail =
|
||||||
/^(([^<>()[\]\.,;:\s@\"]+(\.[^<>()[\]\.,;:\s@\"]+)*)|(\".+\"))@(([^<>()[\]\.,;:\s@\"]+\.)+[^<>()[\]\.,;:\s@\"]{2,})$/i;
|
/^(([^<>()[\]\.,;:\s@\"]+(\.[^<>()[\]\.,;:\s@\"]+)*)|(\".+\"))@(([^<>()[\]\.,;:\s@\"]+\.)+[^<>()[\]\.,;:\s@\"]{2,})$/i;
|
||||||
|
@ -134,13 +85,12 @@ export default async function updateUserById(
|
||||||
|
|
||||||
// Avatar Settings
|
// Avatar Settings
|
||||||
|
|
||||||
if (data.image?.startsWith("data:image/jpeg;base64")) {
|
if (
|
||||||
if (data.image.length < 1572864) {
|
data.image?.startsWith("data:image/jpeg;base64") &&
|
||||||
|
data.image.length < 1572864
|
||||||
|
) {
|
||||||
try {
|
try {
|
||||||
const base64Data = data.image.replace(
|
const base64Data = data.image.replace(/^data:image\/jpeg;base64,/, "");
|
||||||
/^data:image\/jpeg;base64,/,
|
|
||||||
""
|
|
||||||
);
|
|
||||||
|
|
||||||
createFolder({ filePath: `uploads/avatar` });
|
createFolder({ filePath: `uploads/avatar` });
|
||||||
|
|
||||||
|
@ -152,23 +102,88 @@ export default async function updateUserById(
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.log("Error saving image:", err);
|
console.log("Error saving image:", err);
|
||||||
}
|
}
|
||||||
} else {
|
} else if (data.image?.length && data.image?.length >= 1572864) {
|
||||||
console.log("A file larger than 1.5MB was uploaded.");
|
console.log("A file larger than 1.5MB was uploaded.");
|
||||||
return {
|
return {
|
||||||
response: "A file larger than 1.5MB was uploaded.",
|
response: "A file larger than 1.5MB was uploaded.",
|
||||||
status: 400,
|
status: 400,
|
||||||
};
|
};
|
||||||
}
|
|
||||||
} else if (data.image == "") {
|
} else if (data.image == "") {
|
||||||
removeFile({ filePath: `uploads/avatar/${userId}.jpg` });
|
removeFile({ filePath: `uploads/avatar/${userId}.jpg` });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Email Settings
|
||||||
|
|
||||||
|
const user = await prisma.user.findUnique({
|
||||||
|
where: { id: userId },
|
||||||
|
select: { email: true, password: true },
|
||||||
|
});
|
||||||
|
|
||||||
|
if (user && user.email && data.email && data.email !== user.email) {
|
||||||
|
if (!data.password) {
|
||||||
|
return {
|
||||||
|
response: "Invalid password.",
|
||||||
|
status: 400,
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
const previousEmail = (
|
// Verify password
|
||||||
await prisma.user.findUnique({ where: { id: userId } })
|
if (!user.password) {
|
||||||
)?.email;
|
return {
|
||||||
|
response:
|
||||||
|
"User has no password. Please reset your password from the forgot password page.",
|
||||||
|
status: 400,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
// Other settings
|
const passwordMatch = bcrypt.compareSync(data.password, user.password);
|
||||||
|
|
||||||
|
if (!passwordMatch) {
|
||||||
|
return {
|
||||||
|
response: "Password is incorrect.",
|
||||||
|
status: 400,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
sendChangeEmailVerificationRequest(
|
||||||
|
user.email,
|
||||||
|
data.email,
|
||||||
|
data.name.trim()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Password Settings
|
||||||
|
|
||||||
|
if (data.newPassword || data.oldPassword) {
|
||||||
|
if (!data.oldPassword || !data.newPassword)
|
||||||
|
return {
|
||||||
|
response: "Please fill out all the fields.",
|
||||||
|
status: 400,
|
||||||
|
};
|
||||||
|
else if (!user?.password)
|
||||||
|
return {
|
||||||
|
response:
|
||||||
|
"User has no password. Please reset your password from the forgot password page.",
|
||||||
|
status: 400,
|
||||||
|
};
|
||||||
|
else if (!bcrypt.compareSync(data.oldPassword, user.password))
|
||||||
|
return {
|
||||||
|
response: "Old password is incorrect.",
|
||||||
|
status: 400,
|
||||||
|
};
|
||||||
|
else if (data.newPassword?.length < 8)
|
||||||
|
return {
|
||||||
|
response: "Password must be at least 8 characters.",
|
||||||
|
status: 400,
|
||||||
|
};
|
||||||
|
else if (data.newPassword === data.oldPassword)
|
||||||
|
return {
|
||||||
|
response: "New password must be different from the old password.",
|
||||||
|
status: 400,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
// Other settings / Apply changes
|
||||||
|
|
||||||
const saltRounds = 10;
|
const saltRounds = 10;
|
||||||
const newHashedPassword = bcrypt.hashSync(data.newPassword || "", saltRounds);
|
const newHashedPassword = bcrypt.hashSync(data.newPassword || "", saltRounds);
|
||||||
|
@ -178,14 +193,19 @@ export default async function updateUserById(
|
||||||
id: userId,
|
id: userId,
|
||||||
},
|
},
|
||||||
data: {
|
data: {
|
||||||
name: data.name,
|
name: data.name.trim(),
|
||||||
username: data.username?.toLowerCase().trim(),
|
username: data.username?.toLowerCase().trim(),
|
||||||
email: data.email?.toLowerCase().trim(),
|
|
||||||
isPrivate: data.isPrivate,
|
isPrivate: data.isPrivate,
|
||||||
image: data.image ? `uploads/avatar/${userId}.jpg` : "",
|
image:
|
||||||
|
data.image && data.image.startsWith("http")
|
||||||
|
? data.image
|
||||||
|
: data.image
|
||||||
|
? `uploads/avatar/${userId}.jpg`
|
||||||
|
: "",
|
||||||
collectionOrder: data.collectionOrder.filter(
|
collectionOrder: data.collectionOrder.filter(
|
||||||
(value, index, self) => self.indexOf(value) === index
|
(value, index, self) => self.indexOf(value) === index
|
||||||
),
|
),
|
||||||
|
locale: i18n.locales.includes(data.locale) ? data.locale : "en",
|
||||||
archiveAsScreenshot: data.archiveAsScreenshot,
|
archiveAsScreenshot: data.archiveAsScreenshot,
|
||||||
archiveAsSinglefile: data.archiveAsSinglefile,
|
archiveAsSinglefile: data.archiveAsSinglefile,
|
||||||
archiveAsPDF: data.archiveAsPDF,
|
archiveAsPDF: data.archiveAsPDF,
|
||||||
|
@ -245,15 +265,6 @@ export default async function updateUserById(
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
const STRIPE_SECRET_KEY = process.env.STRIPE_SECRET_KEY;
|
|
||||||
|
|
||||||
if (STRIPE_SECRET_KEY && emailEnabled && previousEmail !== data.email)
|
|
||||||
await updateCustomerEmail(
|
|
||||||
STRIPE_SECRET_KEY,
|
|
||||||
previousEmail as string,
|
|
||||||
data.email as string
|
|
||||||
);
|
|
||||||
|
|
||||||
const response: Omit<AccountSettings, "password"> = {
|
const response: Omit<AccountSettings, "password"> = {
|
||||||
...userInfo,
|
...userInfo,
|
||||||
whitelistedUsers: newWhitelistedUsernames,
|
whitelistedUsers: newWhitelistedUsernames,
|
||||||
|
|
|
@ -0,0 +1,36 @@
|
||||||
|
import Jimp from "jimp";
|
||||||
|
import { prisma } from "./db";
|
||||||
|
import createFile from "./storage/createFile";
|
||||||
|
import createFolder from "./storage/createFolder";
|
||||||
|
|
||||||
|
const generatePreview = async (
|
||||||
|
buffer: Buffer,
|
||||||
|
collectionId: number,
|
||||||
|
linkId: number
|
||||||
|
) => {
|
||||||
|
if (buffer && collectionId && linkId) {
|
||||||
|
// Load the image using Jimp
|
||||||
|
await Jimp.read(buffer, async (err, image) => {
|
||||||
|
if (image && !err) {
|
||||||
|
image?.resize(1280, Jimp.AUTO).quality(20);
|
||||||
|
const processedBuffer = await image?.getBufferAsync(Jimp.MIME_JPEG);
|
||||||
|
|
||||||
|
createFile({
|
||||||
|
data: processedBuffer,
|
||||||
|
filePath: `archives/preview/${collectionId}/${linkId}.jpeg`,
|
||||||
|
}).then(() => {
|
||||||
|
return prisma.link.update({
|
||||||
|
where: { id: linkId },
|
||||||
|
data: {
|
||||||
|
preview: `archives/preview/${collectionId}/${linkId}.jpeg`,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}).catch((err) => {
|
||||||
|
console.error("Error processing the image:", err);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
export default generatePreview;
|
|
@ -0,0 +1,44 @@
|
||||||
|
import { NextApiRequest } from "next";
|
||||||
|
import { getToken } from "next-auth/jwt";
|
||||||
|
import { prisma } from "./db";
|
||||||
|
|
||||||
|
type Props = {
|
||||||
|
req: NextApiRequest;
|
||||||
|
};
|
||||||
|
|
||||||
|
export default async function isServerAdmin({ req }: Props): Promise<boolean> {
|
||||||
|
const token = await getToken({ req });
|
||||||
|
const userId = token?.id;
|
||||||
|
|
||||||
|
if (!userId) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (token.exp < Date.now() / 1000) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// check if token is revoked
|
||||||
|
const revoked = await prisma.accessToken.findFirst({
|
||||||
|
where: {
|
||||||
|
token: token.jti,
|
||||||
|
revoked: true,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
if (revoked) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
const findUser = await prisma.user.findFirst({
|
||||||
|
where: {
|
||||||
|
id: userId,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
if (findUser?.username === process.env.ADMINISTRATOR) {
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,61 @@
|
||||||
|
import moveFile from "./storage/moveFile";
|
||||||
|
import removeFile from "./storage/removeFile";
|
||||||
|
|
||||||
|
const removeFiles = async (linkId: number, collectionId: number) => {
|
||||||
|
// PDF
|
||||||
|
await removeFile({
|
||||||
|
filePath: `archives/${collectionId}/${linkId}.pdf`,
|
||||||
|
});
|
||||||
|
// Images
|
||||||
|
await removeFile({
|
||||||
|
filePath: `archives/${collectionId}/${linkId}.png`,
|
||||||
|
});
|
||||||
|
await removeFile({
|
||||||
|
filePath: `archives/${collectionId}/${linkId}.jpeg`,
|
||||||
|
});
|
||||||
|
await removeFile({
|
||||||
|
filePath: `archives/${collectionId}/${linkId}.jpg`,
|
||||||
|
});
|
||||||
|
// Preview
|
||||||
|
await removeFile({
|
||||||
|
filePath: `archives/preview/${collectionId}/${linkId}.jpeg`,
|
||||||
|
});
|
||||||
|
// Readability
|
||||||
|
await removeFile({
|
||||||
|
filePath: `archives/${collectionId}/${linkId}_readability.json`,
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
const moveFiles = async (linkId: number, from: number, to: number) => {
|
||||||
|
await moveFile(
|
||||||
|
`archives/${from}/${linkId}.pdf`,
|
||||||
|
`archives/${to}/${linkId}.pdf`
|
||||||
|
);
|
||||||
|
|
||||||
|
await moveFile(
|
||||||
|
`archives/${from}/${linkId}.png`,
|
||||||
|
`archives/${to}/${linkId}.png`
|
||||||
|
);
|
||||||
|
|
||||||
|
await moveFile(
|
||||||
|
`archives/${from}/${linkId}.jpeg`,
|
||||||
|
`archives/${to}/${linkId}.jpeg`
|
||||||
|
);
|
||||||
|
|
||||||
|
await moveFile(
|
||||||
|
`archives/${from}/${linkId}.jpg`,
|
||||||
|
`archives/${to}/${linkId}.jpg`
|
||||||
|
);
|
||||||
|
|
||||||
|
await moveFile(
|
||||||
|
`archives/preview/${from}/${linkId}.jpeg`,
|
||||||
|
`archives/preview/${to}/${linkId}.jpeg`
|
||||||
|
);
|
||||||
|
|
||||||
|
await moveFile(
|
||||||
|
`archives/${from}/${linkId}_readability.json`,
|
||||||
|
`archives/${to}/${linkId}_readability.json`
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export { removeFiles, moveFiles };
|
|
@ -0,0 +1,57 @@
|
||||||
|
import { randomBytes } from "crypto";
|
||||||
|
import { prisma } from "./db";
|
||||||
|
import transporter from "./transporter";
|
||||||
|
import Handlebars from "handlebars";
|
||||||
|
import { readFileSync } from "fs";
|
||||||
|
import path from "path";
|
||||||
|
|
||||||
|
export default async function sendChangeEmailVerificationRequest(
|
||||||
|
oldEmail: string,
|
||||||
|
newEmail: string,
|
||||||
|
user: string
|
||||||
|
) {
|
||||||
|
const token = randomBytes(32).toString("hex");
|
||||||
|
|
||||||
|
await prisma.$transaction(async () => {
|
||||||
|
await prisma.verificationToken.create({
|
||||||
|
data: {
|
||||||
|
identifier: oldEmail?.toLowerCase(),
|
||||||
|
token,
|
||||||
|
expires: new Date(Date.now() + 24 * 3600 * 1000), // 1 day
|
||||||
|
},
|
||||||
|
});
|
||||||
|
await prisma.user.update({
|
||||||
|
where: {
|
||||||
|
email: oldEmail?.toLowerCase(),
|
||||||
|
},
|
||||||
|
data: {
|
||||||
|
unverifiedNewEmail: newEmail?.toLowerCase(),
|
||||||
|
},
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
const emailsDir = path.resolve(process.cwd(), "templates");
|
||||||
|
|
||||||
|
const templateFile = readFileSync(
|
||||||
|
path.join(emailsDir, "verifyEmailChange.html"),
|
||||||
|
"utf8"
|
||||||
|
);
|
||||||
|
|
||||||
|
const emailTemplate = Handlebars.compile(templateFile);
|
||||||
|
|
||||||
|
transporter.sendMail({
|
||||||
|
from: {
|
||||||
|
name: "Linkwarden",
|
||||||
|
address: process.env.EMAIL_FROM as string,
|
||||||
|
},
|
||||||
|
to: newEmail,
|
||||||
|
subject: "Verify your new Linkwarden email address",
|
||||||
|
html: emailTemplate({
|
||||||
|
user,
|
||||||
|
baseUrl: process.env.BASE_URL,
|
||||||
|
oldEmail,
|
||||||
|
newEmail,
|
||||||
|
verifyUrl: `${process.env.BASE_URL}/auth/verify-email?token=${token}`,
|
||||||
|
}),
|
||||||
|
});
|
||||||
|
}
|
|
@ -0,0 +1,44 @@
|
||||||
|
import { randomBytes } from "crypto";
|
||||||
|
import { prisma } from "./db";
|
||||||
|
import transporter from "./transporter";
|
||||||
|
import Handlebars from "handlebars";
|
||||||
|
import { readFileSync } from "fs";
|
||||||
|
import path from "path";
|
||||||
|
|
||||||
|
export default async function sendPasswordResetRequest(
|
||||||
|
email: string,
|
||||||
|
user: string
|
||||||
|
) {
|
||||||
|
const token = randomBytes(32).toString("hex");
|
||||||
|
|
||||||
|
await prisma.passwordResetToken.create({
|
||||||
|
data: {
|
||||||
|
identifier: email?.toLowerCase(),
|
||||||
|
token,
|
||||||
|
expires: new Date(Date.now() + 24 * 3600 * 1000), // 1 day
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
const emailsDir = path.resolve(process.cwd(), "templates");
|
||||||
|
|
||||||
|
const templateFile = readFileSync(
|
||||||
|
path.join(emailsDir, "passwordReset.html"),
|
||||||
|
"utf8"
|
||||||
|
);
|
||||||
|
|
||||||
|
const emailTemplate = Handlebars.compile(templateFile);
|
||||||
|
|
||||||
|
transporter.sendMail({
|
||||||
|
from: {
|
||||||
|
name: "Linkwarden",
|
||||||
|
address: process.env.EMAIL_FROM as string,
|
||||||
|
},
|
||||||
|
to: email,
|
||||||
|
subject: "Linkwarden: Reset password instructions",
|
||||||
|
html: emailTemplate({
|
||||||
|
user,
|
||||||
|
baseUrl: process.env.BASE_URL,
|
||||||
|
url: `${process.env.BASE_URL}/auth/reset-password?token=${token}`,
|
||||||
|
}),
|
||||||
|
});
|
||||||
|
}
|
|
@ -1,19 +1,44 @@
|
||||||
import { Theme } from "next-auth";
|
import { readFileSync } from "fs";
|
||||||
import { SendVerificationRequestParams } from "next-auth/providers";
|
import path from "path";
|
||||||
import { createTransport } from "nodemailer";
|
import Handlebars from "handlebars";
|
||||||
|
import transporter from "./transporter";
|
||||||
|
|
||||||
|
type Params = {
|
||||||
|
identifier: string;
|
||||||
|
url: string;
|
||||||
|
from: string;
|
||||||
|
token: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
export default async function sendVerificationRequest({
|
||||||
|
identifier,
|
||||||
|
url,
|
||||||
|
from,
|
||||||
|
token,
|
||||||
|
}: Params) {
|
||||||
|
const emailsDir = path.resolve(process.cwd(), "templates");
|
||||||
|
|
||||||
|
const templateFile = readFileSync(
|
||||||
|
path.join(emailsDir, "verifyEmail.html"),
|
||||||
|
"utf8"
|
||||||
|
);
|
||||||
|
|
||||||
|
const emailTemplate = Handlebars.compile(templateFile);
|
||||||
|
|
||||||
export default async function sendVerificationRequest(
|
|
||||||
params: SendVerificationRequestParams
|
|
||||||
) {
|
|
||||||
const { identifier, url, provider, theme } = params;
|
|
||||||
const { host } = new URL(url);
|
const { host } = new URL(url);
|
||||||
const transport = createTransport(provider.server);
|
const result = await transporter.sendMail({
|
||||||
const result = await transport.sendMail({
|
|
||||||
to: identifier,
|
to: identifier,
|
||||||
from: provider.from,
|
from: {
|
||||||
subject: `Sign in to ${host}`,
|
name: "Linkwarden",
|
||||||
|
address: from as string,
|
||||||
|
},
|
||||||
|
subject: `Please verify your email address`,
|
||||||
text: text({ url, host }),
|
text: text({ url, host }),
|
||||||
html: html({ url, host, theme }),
|
html: emailTemplate({
|
||||||
|
url: `${
|
||||||
|
process.env.NEXTAUTH_URL
|
||||||
|
}/callback/email?token=${token}&email=${encodeURIComponent(identifier)}`,
|
||||||
|
}),
|
||||||
});
|
});
|
||||||
const failed = result.rejected.concat(result.pending).filter(Boolean);
|
const failed = result.rejected.concat(result.pending).filter(Boolean);
|
||||||
if (failed.length) {
|
if (failed.length) {
|
||||||
|
@ -21,55 +46,6 @@ export default async function sendVerificationRequest(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function html(params: { url: string; host: string; theme: Theme }) {
|
|
||||||
const { url, host, theme } = params;
|
|
||||||
|
|
||||||
const escapedHost = host.replace(/\./g, "​.");
|
|
||||||
|
|
||||||
const brandColor = theme.brandColor || "#0029cf";
|
|
||||||
const color = {
|
|
||||||
background: "#f9f9f9",
|
|
||||||
text: "#444",
|
|
||||||
mainBackground: "#fff",
|
|
||||||
buttonBackground: brandColor,
|
|
||||||
buttonBorder: brandColor,
|
|
||||||
buttonText: theme.buttonText || "#fff",
|
|
||||||
};
|
|
||||||
|
|
||||||
return `
|
|
||||||
<body style="background: ${color.background};">
|
|
||||||
<table width="100%" border="0" cellspacing="20" cellpadding="0"
|
|
||||||
style="background: ${color.mainBackground}; max-width: 600px; margin: auto; border-radius: 10px;">
|
|
||||||
<tr>
|
|
||||||
<td align="center"
|
|
||||||
style="padding: 10px 0px; font-size: 22px; font-family: Helvetica, Arial, sans-serif; color: ${color.text};">
|
|
||||||
Sign in to <strong>${escapedHost}</strong>
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
<tr>
|
|
||||||
<td align="center" style="padding: 20px 0;">
|
|
||||||
<table border="0" cellspacing="0" cellpadding="0">
|
|
||||||
<tr>
|
|
||||||
<td align="center" style="border-radius: 5px;" bgcolor="${color.buttonBackground}">
|
|
||||||
<a href="${url}" target="_blank" style="font-size: 18px; font-family: Helvetica, Arial, sans-serif; color: ${color.buttonText}; text-decoration: none; border-radius: 5px; padding: 10px 20px; border: 1px solid ${color.buttonBorder}; display: inline-block; font-weight: bold;">
|
|
||||||
Sign in
|
|
||||||
</a>
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
</table>
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
<tr>
|
|
||||||
<td align="center"
|
|
||||||
style="padding: 0px 0px 10px 0px; font-size: 16px; line-height: 22px; font-family: Helvetica, Arial, sans-serif; color: ${color.text};">
|
|
||||||
If you did not request this email you can safely ignore it.
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
</table>
|
|
||||||
</body>
|
|
||||||
`;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Email Text body (fallback for email clients that don't render HTML, e.g. feature phones) */
|
/** Email Text body (fallback for email clients that don't render HTML, e.g. feature phones) */
|
||||||
function text({ url, host }: { url: string; host: string }) {
|
function text({ url, host }: { url: string; host: string }) {
|
||||||
return `Sign in to ${host}\n${url}\n\n`;
|
return `Sign in to ${host}\n${url}\n\n`;
|
||||||
|
|
|
@ -0,0 +1,8 @@
|
||||||
|
import { createTransport } from "nodemailer";
|
||||||
|
|
||||||
|
export default createTransport({
|
||||||
|
url: process.env.EMAIL_SERVER,
|
||||||
|
auth: {
|
||||||
|
user: process.env.EMAIL_FROM,
|
||||||
|
},
|
||||||
|
});
|
|
@ -1,17 +1,35 @@
|
||||||
import fetch from "node-fetch";
|
import fetch from "node-fetch";
|
||||||
import https from "https";
|
import https from "https";
|
||||||
|
import { SocksProxyAgent } from "socks-proxy-agent";
|
||||||
|
|
||||||
export default async function validateUrlSize(url: string) {
|
export default async function validateUrlSize(url: string) {
|
||||||
|
if (process.env.IGNORE_URL_SIZE_LIMIT === "true") return null;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const httpsAgent = new https.Agent({
|
const httpsAgent = new https.Agent({
|
||||||
rejectUnauthorized:
|
rejectUnauthorized:
|
||||||
process.env.IGNORE_UNAUTHORIZED_CA === "true" ? false : true,
|
process.env.IGNORE_UNAUTHORIZED_CA === "true" ? false : true,
|
||||||
});
|
});
|
||||||
|
|
||||||
const response = await fetch(url, {
|
let fetchOpts = {
|
||||||
method: "HEAD",
|
method: "HEAD",
|
||||||
agent: httpsAgent,
|
agent: httpsAgent,
|
||||||
});
|
};
|
||||||
|
|
||||||
|
if (process.env.PROXY) {
|
||||||
|
let proxy = new URL(process.env.PROXY);
|
||||||
|
if (process.env.PROXY_USERNAME) {
|
||||||
|
proxy.username = process.env.PROXY_USERNAME;
|
||||||
|
proxy.password = process.env.PROXY_PASSWORD || "";
|
||||||
|
}
|
||||||
|
|
||||||
|
fetchOpts = {
|
||||||
|
method: "HEAD",
|
||||||
|
agent: new SocksProxyAgent(proxy.toString()),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
const response = await fetch(url, fetchOpts);
|
||||||
|
|
||||||
const totalSizeMB =
|
const totalSizeMB =
|
||||||
Number(response.headers.get("content-length")) / Math.pow(1024, 2);
|
Number(response.headers.get("content-length")) / Math.pow(1024, 2);
|
||||||
|
|
|
@ -32,19 +32,13 @@ export default async function verifyUser({
|
||||||
subscriptions: true,
|
subscriptions: true,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
const ssoUser = await prisma.account.findFirst({
|
|
||||||
where: {
|
|
||||||
userId: userId,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
if (!user) {
|
if (!user) {
|
||||||
res.status(404).json({ response: "User not found." });
|
res.status(404).json({ response: "User not found." });
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!user.username && !ssoUser) {
|
if (!user.username) {
|
||||||
// SSO users don't need a username
|
|
||||||
res.status(401).json({
|
res.status(401).json({
|
||||||
response: "Username not found.",
|
response: "Username not found.",
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,12 +1,14 @@
|
||||||
import { CollectionIncludingMembersAndLinkCount, Member } from "@/types/global";
|
import { CollectionIncludingMembersAndLinkCount, Member } from "@/types/global";
|
||||||
import getPublicUserData from "./getPublicUserData";
|
import getPublicUserData from "./getPublicUserData";
|
||||||
import { toast } from "react-hot-toast";
|
import { toast } from "react-hot-toast";
|
||||||
|
import { TFunction } from "i18next";
|
||||||
|
|
||||||
const addMemberToCollection = async (
|
const addMemberToCollection = async (
|
||||||
ownerUsername: string,
|
ownerUsername: string,
|
||||||
memberUsername: string,
|
memberUsername: string,
|
||||||
collection: CollectionIncludingMembersAndLinkCount,
|
collection: CollectionIncludingMembersAndLinkCount,
|
||||||
setMember: (newMember: Member) => null | undefined
|
setMember: (newMember: Member) => null | undefined,
|
||||||
|
t: TFunction<"translation", undefined>
|
||||||
) => {
|
) => {
|
||||||
const checkIfMemberAlreadyExists = collection.members.find((e) => {
|
const checkIfMemberAlreadyExists = collection.members.find((e) => {
|
||||||
const username = (e.user.username || "").toLowerCase();
|
const username = (e.user.username || "").toLowerCase();
|
||||||
|
@ -39,9 +41,9 @@ const addMemberToCollection = async (
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
} else if (checkIfMemberAlreadyExists) toast.error("User already exists.");
|
} else if (checkIfMemberAlreadyExists) toast.error(t("user_already_member"));
|
||||||
else if (memberUsername.trim().toLowerCase() === ownerUsername.toLowerCase())
|
else if (memberUsername.trim().toLowerCase() === ownerUsername.toLowerCase())
|
||||||
toast.error("You are already the collection owner.");
|
toast.error(t("you_are_already_collection_owner"));
|
||||||
};
|
};
|
||||||
|
|
||||||
export default addMemberToCollection;
|
export default addMemberToCollection;
|
||||||
|
|
Some files were not shown because too many files have changed in this diff Show More
Ŝarĝante…
Reference in New Issue