nice flow and all working!!!!
This commit is contained in:
@@ -93,8 +93,8 @@ export default function Links() {
|
|||||||
const allLinks = Array.from(linksMap.values());
|
const allLinks = Array.from(linksMap.values());
|
||||||
|
|
||||||
const meLinks = allLinks.filter((link) => {
|
const meLinks = allLinks.filter((link) => {
|
||||||
// if archived, don't show
|
// if archived or deleted, don't show
|
||||||
if (link.state == LinkState.archived) {
|
if (link.state != LinkState.active) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -112,7 +112,7 @@ export default function Links() {
|
|||||||
});
|
});
|
||||||
const teamLinks = allLinks.filter((link) => {
|
const teamLinks = allLinks.filter((link) => {
|
||||||
// not archived and does not have a recipients list
|
// not archived and does not have a recipients list
|
||||||
if (link.state != LinkState.archived && !link.recipients) {
|
if (link.state == LinkState.active && !link.recipients) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
@@ -158,21 +158,6 @@ export default function Links() {
|
|||||||
</span>
|
</span>
|
||||||
</span>
|
</span>
|
||||||
|
|
||||||
{/* tab pane */}
|
|
||||||
{/* <span className="ml-auto flex flex-row space-x-5 uppercase mr-5">
|
|
||||||
<span className="underline underline-offset-8 decoration-white text-white hover:text-white hover:cursor-pointer">
|
|
||||||
Team
|
|
||||||
</span>
|
|
||||||
|
|
||||||
<span className="text-gray-300 hover:text-white hover:cursor-pointer">
|
|
||||||
Personal
|
|
||||||
</span>
|
|
||||||
|
|
||||||
<span className="text-gray-300 hover:text-white hover:cursor-pointer">
|
|
||||||
Favorites
|
|
||||||
</span>
|
|
||||||
</span> */}
|
|
||||||
|
|
||||||
<Dropdown overlay={TimePeriodFilterMenu}>
|
<Dropdown overlay={TimePeriodFilterMenu}>
|
||||||
<span className="text-sm text-gray-300 flex flex-row items-center uppercase hover:cursor-pointer">
|
<span className="text-sm text-gray-300 flex flex-row items-center uppercase hover:cursor-pointer">
|
||||||
Week <FaAngleDown />
|
Week <FaAngleDown />
|
||||||
@@ -208,27 +193,27 @@ export default function Links() {
|
|||||||
>
|
>
|
||||||
<Radio.Button value={LinkTypeFilter.me}>
|
<Radio.Button value={LinkTypeFilter.me}>
|
||||||
{LinkTypeFilter.me}{" "}
|
{LinkTypeFilter.me}{" "}
|
||||||
{/* <span className="text-xs text-orange-500">
|
<span className="text-xs text-orange-500">
|
||||||
{meRooms.length > 0 ? meRooms.length : ""}
|
{meLinks.length > 0 ? meLinks.length : ""}
|
||||||
</span> */}
|
</span>
|
||||||
</Radio.Button>
|
</Radio.Button>
|
||||||
<Radio.Button value={LinkTypeFilter.team}>
|
<Radio.Button value={LinkTypeFilter.team}>
|
||||||
{LinkTypeFilter.team}{" "}
|
{LinkTypeFilter.team}{" "}
|
||||||
{/* <span className="text-xs text-orange-500">{teamRooms.length}</span> */}
|
<span className="text-xs text-orange-500">{teamLinks.length}</span>
|
||||||
</Radio.Button>
|
</Radio.Button>
|
||||||
<Tooltip title={"coming soon"}>
|
<Tooltip title={"coming soon"}>
|
||||||
<Radio.Button disabled value={LinkTypeFilter.favorites}>
|
<Radio.Button disabled value={LinkTypeFilter.favorites}>
|
||||||
{LinkTypeFilter.favorites}{" "}
|
{LinkTypeFilter.favorites}{" "}
|
||||||
{/* <span className="text-xs text-orange-500">
|
{/* <span className="text-xs text-orange-500">
|
||||||
{liveRooms.length > 0 ? liveRooms.length : ""}
|
{liveRooms.length > 0 ? fa.length : ""}
|
||||||
</span> */}
|
</span> */}
|
||||||
</Radio.Button>
|
</Radio.Button>
|
||||||
</Tooltip>
|
</Tooltip>
|
||||||
<Radio.Button value={LinkTypeFilter.archived}>
|
<Radio.Button value={LinkTypeFilter.archived}>
|
||||||
{LinkTypeFilter.archived}{" "}
|
{LinkTypeFilter.archived}{" "}
|
||||||
{/* <span className="text-xs text-orange-500">
|
<span className="text-xs text-orange-500">
|
||||||
{archivedRooms.length > 0 ? archivedRooms.length : ""}
|
{archivedLinks.length > 0 ? archivedLinks.length : ""}
|
||||||
</span> */}
|
</span>
|
||||||
</Radio.Button>
|
</Radio.Button>
|
||||||
</Radio.Group>
|
</Radio.Group>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
+51
-31
@@ -5,7 +5,7 @@ import {
|
|||||||
FaFilePdf,
|
FaFilePdf,
|
||||||
FaTrash,
|
FaTrash,
|
||||||
} from "react-icons/fa";
|
} from "react-icons/fa";
|
||||||
import Link, { LinkType } from "../models/link";
|
import Link, { LinkState, LinkType } from "../models/link";
|
||||||
import Image from "next/image";
|
import Image from "next/image";
|
||||||
import { BsThreeDots } from "react-icons/bs";
|
import { BsThreeDots } from "react-icons/bs";
|
||||||
import LinkIcon from "./LinkIcon";
|
import LinkIcon from "./LinkIcon";
|
||||||
@@ -16,11 +16,14 @@ import { Avatar, Dropdown, Menu, Tooltip } from "antd";
|
|||||||
import { useState } from "react";
|
import { useState } from "react";
|
||||||
import SkeletonLoader from "./Loading/skeletonLoader";
|
import SkeletonLoader from "./Loading/skeletonLoader";
|
||||||
import moment from "moment";
|
import moment from "moment";
|
||||||
|
import { LinkService } from "../services/linkService";
|
||||||
|
|
||||||
interface ILinkCardProps {
|
interface ILinkCardProps {
|
||||||
link: Link;
|
link: Link;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const linkService = new LinkService();
|
||||||
|
|
||||||
export default function LinkCard(props: ILinkCardProps) {
|
export default function LinkCard(props: ILinkCardProps) {
|
||||||
const { currUser } = useAuth();
|
const { currUser } = useAuth();
|
||||||
const { teamUsersMap, user } = useTeamDashboardContext();
|
const { teamUsersMap, user } = useTeamDashboardContext();
|
||||||
@@ -46,28 +49,38 @@ export default function LinkCard(props: ILinkCardProps) {
|
|||||||
return results;
|
return results;
|
||||||
}, [] as User[]);
|
}, [] as User[]);
|
||||||
|
|
||||||
function handleDeleteLink() {
|
async function handleDeleteLink() {
|
||||||
|
setLoading(true);
|
||||||
if (
|
if (
|
||||||
confirm(
|
confirm(
|
||||||
"Are you sure you want to delete link? It will disappear for all recipients."
|
"Are you sure you want to delete link? It will disappear for all recipients."
|
||||||
)
|
)
|
||||||
) {
|
) {
|
||||||
console.log("deleting link");
|
console.log("deleting link");
|
||||||
|
|
||||||
|
await linkService.updateLinkState(props.link.id, LinkState.deleted);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
} catch (error) {}
|
} catch (error) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
setLoading(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
function handleArchivingLink() {
|
async function handleArchivingLink() {
|
||||||
|
setLoading(true);
|
||||||
|
|
||||||
if (
|
if (
|
||||||
confirm(
|
confirm(
|
||||||
"Are you sure you want to archive link? It will be in the archive tab."
|
"Are you sure you want to archive link? It will be in the archive tab."
|
||||||
)
|
)
|
||||||
) {
|
) {
|
||||||
console.log("archiving link");
|
await linkService.updateLinkState(props.link.id, LinkState.archived);
|
||||||
try {
|
try {
|
||||||
} catch (error) {}
|
} catch (error) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
setLoading(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (loading) {
|
if (loading) {
|
||||||
@@ -76,11 +89,16 @@ export default function LinkCard(props: ILinkCardProps) {
|
|||||||
|
|
||||||
const LinkOptionsMenu = (
|
const LinkOptionsMenu = (
|
||||||
<Menu>
|
<Menu>
|
||||||
<Menu.Item key={1} danger onClick={handleDeleteLink} icon={<FaArchive />}>
|
<Menu.Item
|
||||||
|
key={2}
|
||||||
|
danger
|
||||||
|
onClick={handleArchivingLink}
|
||||||
|
icon={<FaArchive />}
|
||||||
|
>
|
||||||
<button>Archive Link</button>
|
<button>Archive Link</button>
|
||||||
</Menu.Item>
|
</Menu.Item>
|
||||||
<Menu.Item
|
<Menu.Item
|
||||||
key={2}
|
key={3}
|
||||||
danger
|
danger
|
||||||
onClick={handleArchivingLink}
|
onClick={handleArchivingLink}
|
||||||
icon={<FaTrash />}
|
icon={<FaTrash />}
|
||||||
@@ -94,7 +112,7 @@ export default function LinkCard(props: ILinkCardProps) {
|
|||||||
props.link.createdDate.toDate()
|
props.link.createdDate.toDate()
|
||||||
).fromNow();
|
).fromNow();
|
||||||
|
|
||||||
var receiversNames = "";
|
var receiversNames = "team";
|
||||||
if (receivers) {
|
if (receivers) {
|
||||||
receiversNames = receivers.map((receiver) => receiver.firstName).join(", ");
|
receiversNames = receivers.map((receiver) => receiver.firstName).join(", ");
|
||||||
}
|
}
|
||||||
@@ -104,32 +122,34 @@ export default function LinkCard(props: ILinkCardProps) {
|
|||||||
return (
|
return (
|
||||||
<span className="flex flex-col rounded-lg ">
|
<span className="flex flex-col rounded-lg ">
|
||||||
{/* attmnt header */}
|
{/* attmnt header */}
|
||||||
<span
|
<Tooltip title={props.link.link}>
|
||||||
onClick={() => window.open(props.link.link, "_blank")}
|
<span
|
||||||
className="flex flex-row bg-gray-300 bg-opacity-25 py-5 px-3 items-center justify-start hover:cursor-pointer"
|
|
||||||
>
|
|
||||||
<LinkIcon className="text-4xl mr-2" linkType={props.link.type} />
|
|
||||||
|
|
||||||
<span className="flex flex-col items-baseline mr-10 space-y-1">
|
|
||||||
<span className="text-md font-bold text-white">
|
|
||||||
{props.link.name}
|
|
||||||
</span>
|
|
||||||
|
|
||||||
<span
|
|
||||||
className={`text-gray-200 text-xs mb-auto text-ellipsis whitespace-pre-line max-h-10 overflow-hidden`}
|
|
||||||
>
|
|
||||||
{props.link.description}
|
|
||||||
</span>
|
|
||||||
</span>
|
|
||||||
|
|
||||||
{/* attachment actions */}
|
|
||||||
<button
|
|
||||||
onClick={() => window.open(props.link.link, "_blank")}
|
onClick={() => window.open(props.link.link, "_blank")}
|
||||||
className="bg-gray-300 bg-opacity-25 p-2 ml-auto rounded hover:bg-opacity-40"
|
className="flex flex-row bg-gray-300 bg-opacity-25 py-5 px-3 items-center justify-start hover:cursor-pointer"
|
||||||
>
|
>
|
||||||
<FaExternalLinkAlt className="text-sm text-white" />
|
<LinkIcon className="text-4xl mr-2" linkType={props.link.type} />
|
||||||
</button>
|
|
||||||
</span>
|
<span className="flex flex-col items-baseline mr-10 space-y-1">
|
||||||
|
<span className="text-md font-bold text-white">
|
||||||
|
{props.link.name}
|
||||||
|
</span>
|
||||||
|
|
||||||
|
<span
|
||||||
|
className={`text-gray-200 text-xs mb-auto text-ellipsis whitespace-pre-line max-h-10 overflow-hidden`}
|
||||||
|
>
|
||||||
|
{props.link.description}
|
||||||
|
</span>
|
||||||
|
</span>
|
||||||
|
|
||||||
|
{/* attachment actions */}
|
||||||
|
<button
|
||||||
|
onClick={() => window.open(props.link.link, "_blank")}
|
||||||
|
className="bg-gray-300 bg-opacity-25 p-2 ml-auto rounded hover:bg-opacity-40"
|
||||||
|
>
|
||||||
|
<FaExternalLinkAlt className="text-sm text-white" />
|
||||||
|
</button>
|
||||||
|
</span>
|
||||||
|
</Tooltip>
|
||||||
|
|
||||||
{/* attmnt footer */}
|
{/* attmnt footer */}
|
||||||
<Tooltip
|
<Tooltip
|
||||||
|
|||||||
@@ -70,6 +70,7 @@ export default class Link {
|
|||||||
export enum LinkState {
|
export enum LinkState {
|
||||||
active = "active",
|
active = "active",
|
||||||
archived = "archived",
|
archived = "archived",
|
||||||
|
deleted = "deleted",
|
||||||
}
|
}
|
||||||
|
|
||||||
export enum LinkType {
|
export enum LinkType {
|
||||||
|
|||||||
@@ -0,0 +1,24 @@
|
|||||||
|
import {
|
||||||
|
addDoc,
|
||||||
|
collection,
|
||||||
|
doc,
|
||||||
|
Firestore,
|
||||||
|
getFirestore,
|
||||||
|
serverTimestamp,
|
||||||
|
setDoc,
|
||||||
|
} from "firebase/firestore";
|
||||||
|
import Link, { LinkState } from "../models/link";
|
||||||
|
import { Collections } from "./collections";
|
||||||
|
|
||||||
|
export class LinkService {
|
||||||
|
private db: Firestore = getFirestore();
|
||||||
|
|
||||||
|
async updateLinkState(linkId: string, newState: LinkState) {
|
||||||
|
const docRef = doc(this.db, Collections.links, linkId);
|
||||||
|
await setDoc(
|
||||||
|
docRef,
|
||||||
|
{ state: newState, lastUpdatedDate: serverTimestamp() },
|
||||||
|
{ merge: true }
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user