Added selectedLinks to store & checkbox on list view

This commit is contained in:
Isaac Wise 2024-02-09 23:24:22 -06:00
parent c78aa2da0d
commit 0a070deebd
4 changed files with 17 additions and 4 deletions

View File

@ -26,7 +26,11 @@ export default function LinkCardCompact({
flipDropdown, flipDropdown,
}: Props) { }: Props) {
const { collections } = useCollectionStore(); const { collections } = useCollectionStore();
const { links } = useLinkStore(); const { links, setSelectedLinks, selectedLinks } = useLinkStore();
const handleCheckboxClick = (checkboxId: number) => {
setSelectedLinks((selectedLinks.includes(checkboxId) ? selectedLinks.filter((id) => id !== checkboxId) : [...selectedLinks, checkboxId]));
};
let shortendURL; let shortendURL;
@ -56,9 +60,15 @@ export default function LinkCardCompact({
return ( return (
<> <>
<div <div
className={`border-neutral-content relative ${!showInfo && !isPWA() ? "hover:bg-base-300 p-3" : "py-3" className={`border-neutral-content relative items-center flex ${!showInfo && !isPWA() ? "hover:bg-base-300 p-3" : "py-3"
} duration-200 rounded-lg`} } duration-200 rounded-lg`}
> >
<input
type="checkbox"
className="checkbox checkbox-primary my-auto mr-2"
checked={selectedLinks.includes(link.id)}
onChange={() => handleCheckboxClick(link.id)}
/>
<Link <Link
href={generateLinkHref(link)} href={generateLinkHref(link)}
target="_blank" target="_blank"

View File

@ -10,10 +10,12 @@ type ResponseObject = {
type LinkStore = { type LinkStore = {
links: LinkIncludingShortenedCollectionAndTags[]; links: LinkIncludingShortenedCollectionAndTags[];
selectedLinks: number[];
setLinks: ( setLinks: (
data: LinkIncludingShortenedCollectionAndTags[], data: LinkIncludingShortenedCollectionAndTags[],
isInitialCall: boolean isInitialCall: boolean
) => void; ) => void;
setSelectedLinks: (linkIds: number[]) => void;
addLink: ( addLink: (
body: LinkIncludingShortenedCollectionAndTags body: LinkIncludingShortenedCollectionAndTags
) => Promise<ResponseObject>; ) => Promise<ResponseObject>;
@ -27,6 +29,7 @@ type LinkStore = {
const useLinkStore = create<LinkStore>()((set) => ({ const useLinkStore = create<LinkStore>()((set) => ({
links: [], links: [],
selectedLinks: [],
setLinks: async (data, isInitialCall) => { setLinks: async (data, isInitialCall) => {
isInitialCall && isInitialCall &&
set(() => ({ set(() => ({
@ -45,6 +48,7 @@ const useLinkStore = create<LinkStore>()((set) => ({
), ),
})); }));
}, },
setSelectedLinks: (linkIds) => set({ selectedLinks: linkIds }),
addLink: async (body) => { addLink: async (body) => {
const response = await fetch("/api/v1/links", { const response = await fetch("/api/v1/links", {
body: JSON.stringify(body), body: JSON.stringify(body),

View File

@ -1,5 +1,4 @@
import { create } from "zustand"; import { create } from "zustand";
import { ViewMode } from "@/types/global";
type LocalSettings = { type LocalSettings = {
theme?: string; theme?: string;

View File

@ -9,7 +9,7 @@ export interface LinkIncludingShortenedCollectionAndTags
Link, Link,
"id" | "createdAt" | "collectionId" | "updatedAt" | "lastPreserved" "id" | "createdAt" | "collectionId" | "updatedAt" | "lastPreserved"
> { > {
id?: number; id: number;
createdAt?: string; createdAt?: string;
collectionId?: number; collectionId?: number;
tags: Tag[]; tags: Tag[];