add link actions to readable view

This commit is contained in:
Matthew Jacobs 2024-04-24 00:56:00 +00:00
parent 4640c1c966
commit 1a96ca32f9
2 changed files with 28 additions and 5 deletions

View File

@ -18,6 +18,7 @@ type Props = {
position?: string; position?: string;
toggleShowInfo?: () => void; toggleShowInfo?: () => void;
linkInfo?: boolean; linkInfo?: boolean;
alignToTop?: boolean;
flipDropdown?: boolean; flipDropdown?: boolean;
}; };
@ -26,6 +27,7 @@ export default function LinkActions({
toggleShowInfo, toggleShowInfo,
position, position,
linkInfo, linkInfo,
alignToTop,
flipDropdown, flipDropdown,
}: Props) { }: Props) {
const permissions = usePermissions(link.collection.id as number); const permissions = usePermissions(link.collection.id as number);
@ -67,9 +69,9 @@ export default function LinkActions({
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 +81,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"

View File

@ -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,9 @@ 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";
type LinkContent = { type LinkContent = {
title: string; title: string;
@ -41,6 +44,13 @@ export default function ReadableView({ link }: Props) {
const router = useRouter(); const router = useRouter();
const { links, getLink } = useLinkStore(); const { links, 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 () => {
@ -131,7 +141,7 @@ export default function ReadableView({ link }: Props) {
<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 py-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>
@ -226,6 +236,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">