Merge pull request #579 from codingmatty/main

Add link actions to readable view
This commit is contained in:
Daniel 2024-05-14 19:50:42 +03:30 committed by GitHub
commit db446d450f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 33 additions and 10 deletions

View File

@ -200,7 +200,7 @@ export default function LinkCard({ link, flipDropdown, editMode }: Props) {
</span>
)}
</p>
{link.tags[0] && (
{link.tags && link.tags[0] && (
<>
<p className="text-neutral text-lg mt-3 font-semibold">Tags</p>

View File

@ -18,6 +18,7 @@ type Props = {
position?: string;
toggleShowInfo?: () => void;
linkInfo?: boolean;
alignToTop?: boolean;
flipDropdown?: boolean;
};
@ -26,6 +27,7 @@ export default function LinkActions({
toggleShowInfo,
position,
linkInfo,
alignToTop,
flipDropdown,
}: Props) {
const permissions = usePermissions(link.collection.id as number);
@ -67,9 +69,9 @@ export default function LinkActions({
return (
<>
<div
className={`dropdown dropdown-left dropdown-end absolute ${
className={`dropdown dropdown-left absolute ${
position || "top-3 right-3"
} z-20`}
} ${alignToTop ? "" : "dropdown-end"} z-20`}
>
<div
tabIndex={0}
@ -79,7 +81,11 @@ export default function LinkActions({
>
<i title="More" className="bi-three-dots text-xl" />
</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>
<div
role="button"

View File

@ -4,6 +4,7 @@ import isValidUrl from "@/lib/shared/isValidUrl";
import useLinkStore from "@/store/links";
import {
ArchivedFormat,
CollectionIncludingMembersAndLinkCount,
LinkIncludingShortenedCollectionAndTags,
} from "@/types/global";
import ColorThief, { RGBColor } from "colorthief";
@ -11,7 +12,9 @@ import DOMPurify from "dompurify";
import Image from "next/image";
import Link from "next/link";
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";
type LinkContent = {
title: string;
@ -40,7 +43,14 @@ export default function ReadableView({ link }: Props) {
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(() => {
const fetchLinkContent = async () => {
@ -128,10 +138,10 @@ export default function ReadableView({ link }: Props) {
}, [colorPalette]);
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
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>
@ -164,7 +174,7 @@ export default function ReadableView({ link }: Props) {
/>
)}
<div className="flex flex-col">
<p className="text-xl">
<p className="text-xl pr-10">
{unescapeString(
link?.name || link?.description || link?.url || ""
)}
@ -202,7 +212,7 @@ export default function ReadableView({ link }: Props) {
{link?.collection.name}
</p>
</Link>
{link?.tags.map((e, i) => (
{link?.tags?.map((e, i) => (
<Link key={i} href={`/tags/${e.id}`} className="z-10">
<p
title={e.name}
@ -226,6 +236,13 @@ export default function ReadableView({ link }: Props) {
{link?.name ? <p>{unescapeString(link?.description)}</p> : undefined}
</div>
<LinkActions
link={link}
collection={collection}
position="top-3 right-3"
alignToTop
/>
</div>
<div className="flex flex-col gap-5 h-full">