Skip to content

⚡️⚡️⚡️ Self-hosted collaborative bookmark manager to collect, read, annotate, and fully preserve what matters, all in one place.

format

Isaac048842efa4d0
diff --git a/apps/web/components/DashboardLayoutDropdown.tsx b/apps/web/components/DashboardLayoutDropdown.tsx
index 0d50bf27..32bee2f7 100644
--- a/apps/web/components/DashboardLayoutDropdown.tsx
+++ b/apps/web/components/DashboardLayoutDropdown.tsx
@@ -8,17 +8,20 @@ import { useTranslation } from "next-i18next";
import { Button } from "@/components/ui/button";
import TextInput from "./TextInput";
import { useCollections } from "@linkwarden/router/collections";
-import { DashboardSection, DashboardSectionType } from "@linkwarden/prisma/client";
+import {
+ DashboardSection,
+ DashboardSectionType,
+} from "@linkwarden/prisma/client";
import { useUser } from "@linkwarden/router/user";
import { useUpdateDashboardLayout } from "@linkwarden/router/dashboardData";
import {
draggable,
dropTargetForElements,
- monitorForElements
-} from '@atlaskit/pragmatic-drag-and-drop/element/adapter';
-import { combine } from '@atlaskit/pragmatic-drag-and-drop/combine';
-import { reorder } from '@atlaskit/pragmatic-drag-and-drop/reorder';
-import { triggerPostMoveFlash } from '@atlaskit/pragmatic-drag-and-drop-flourish/trigger-post-move-flash';
+ monitorForElements,
+} from "@atlaskit/pragmatic-drag-and-drop/element/adapter";
+import { combine } from "@atlaskit/pragmatic-drag-and-drop/combine";
+import { reorder } from "@atlaskit/pragmatic-drag-and-drop/reorder";
+import { triggerPostMoveFlash } from "@atlaskit/pragmatic-drag-and-drop-flourish/trigger-post-move-flash";
interface DashboardSectionOption {
type: DashboardSectionType;
@@ -39,55 +42,76 @@ export default function DashboardLayoutDropdown() {
const dashboardSections: DashboardSection[] = user?.dashboardSections || [];
- const getSectionOrder = (type: DashboardSectionType, collectionId?: number): number | undefined => {
- const section = dashboardSections.find(section =>
- section.type === type &&
- (type === DashboardSectionType.COLLECTION ? section.collectionId === collectionId : true)
+ const getSectionOrder = (
+ type: DashboardSectionType,
+ collectionId?: number
+ ): number | undefined => {
+ const section = dashboardSections.find(
+ (section) =>
+ section.type === type &&
+ (type === DashboardSectionType.COLLECTION
+ ? section.collectionId === collectionId
+ : true)
);
return section?.order;
};
- const isSectionEnabled = (type: DashboardSectionType, collectionId?: number): boolean => {
- return dashboardSections.some(section =>
- section.type === type &&
- (type === DashboardSectionType.COLLECTION ? section.collectionId === collectionId : true)
+ const isSectionEnabled = (
+ type: DashboardSectionType,
+ collectionId?: number
+ ): boolean => {
+ return dashboardSections.some(
+ (section) =>
+ section.type === type &&
+ (type === DashboardSectionType.COLLECTION
+ ? section.collectionId === collectionId
+ : true)
);
};
- const defaultSections: DashboardSectionOption[] = useMemo(() => [
- {
- type: DashboardSectionType.STATS,
- name: t("dashboard_stats"),
- enabled: isSectionEnabled(DashboardSectionType.STATS),
- order: getSectionOrder(DashboardSectionType.STATS)
- },
- {
- type: DashboardSectionType.RECENT_LINKS,
- name: t("recent_links"),
- enabled: isSectionEnabled(DashboardSectionType.RECENT_LINKS),
- order: getSectionOrder(DashboardSectionType.RECENT_LINKS)
- },
- {
- type: DashboardSectionType.PINNED_LINKS,
- name: t("pinned_links"),
- enabled: isSectionEnabled(DashboardSectionType.PINNED_LINKS),
- order: getSectionOrder(DashboardSectionType.PINNED_LINKS)
- },
- ], [user]);
-
- const collectionSections = useMemo(() =>
- collections.map((collection) => ({
- type: DashboardSectionType.COLLECTION,
- name: collection.name,
- collectionId: collection.id,
- enabled: isSectionEnabled(DashboardSectionType.COLLECTION, collection.id),
- order: getSectionOrder(DashboardSectionType.COLLECTION, collection.id)
- })), [collections, user]
+ const defaultSections: DashboardSectionOption[] = useMemo(
+ () => [
+ {
+ type: DashboardSectionType.STATS,
+ name: t("dashboard_stats"),
+ enabled: isSectionEnabled(DashboardSectionType.STATS),
+ order: getSectionOrder(DashboardSectionType.STATS),
+ },
+ {
+ type: DashboardSectionType.RECENT_LINKS,
+ name: t("recent_links"),
+ enabled: isSectionEnabled(DashboardSectionType.RECENT_LINKS),
+ order: getSectionOrder(DashboardSectionType.RECENT_LINKS),
+ },
+ {
+ type: DashboardSectionType.PINNED_LINKS,
+ name: t("pinned_links"),
+ enabled: isSectionEnabled(DashboardSectionType.PINNED_LINKS),
+ order: getSectionOrder(DashboardSectionType.PINNED_LINKS),
+ },
+ ],
+ [user]
+ );
+
+ const collectionSections = useMemo(
+ () =>
+ collections.map((collection) => ({
+ type: DashboardSectionType.COLLECTION,
+ name: collection.name,
+ collectionId: collection.id,
+ enabled: isSectionEnabled(
+ DashboardSectionType.COLLECTION,
+ collection.id
+ ),
+ order: getSectionOrder(DashboardSectionType.COLLECTION, collection.id),
+ })),
+ [collections, user]
);
- const allSections = useMemo(() => [...defaultSections, ...collectionSections], [
- collectionSections, defaultSections
- ]);
+ const allSections = useMemo(
+ () => [...defaultSections, ...collectionSections],
+ [collectionSections, defaultSections]
+ );
const filteredSections = useMemo(() => {
let sections = allSections;
@@ -101,7 +125,7 @@ export default function DashboardLayoutDropdown() {
// Separate and sort sections
const enabledSections = sections
- .filter(section => section.enabled)
+ .filter((section) => section.enabled)
.sort((a, b) => {
if (a.order !== undefined && b.order !== undefined) {
return a.order - b.order;
@@ -111,13 +135,13 @@ export default function DashboardLayoutDropdown() {
return 0;
});
- const disabledSections = sections.filter(section => !section.enabled);
+ const disabledSections = sections.filter((section) => !section.enabled);
return [...enabledSections, ...disabledSections];
}, [allSections, searchTerm]);
const getSectionId = (section: DashboardSectionOption) =>
- `${section.type}-${section.collectionId || 'default'}`;
+ `${section.type}-${section.collectionId || "default"}`;
// Set up drag and drop
useEffect(() => {
@@ -131,8 +155,12 @@ export default function DashboardLayoutDropdown() {
if (!sourceId || !destinationId || sourceId === destinationId) return;
- const sourceIndex = filteredSections.findIndex(s => getSectionId(s) === sourceId);
- const destinationIndex = filteredSections.findIndex(s => getSectionId(s) === destinationId);
+ const sourceIndex = filteredSections.findIndex(
+ (s) => getSectionId(s) === sourceId
+ );
+ const destinationIndex = filteredSections.findIndex(
+ (s) => getSectionId(s) === destinationId
+ );
if (sourceIndex === -1 || destinationIndex === -1) return;
@@ -236,10 +264,10 @@ function DraggableListItem({
isDraggedOver,
isDragged,
setIsDraggedOver,
- setDraggedItem
+ setDraggedItem,
}: DraggableListItemProps) {
const [element, setElement] = useState<HTMLElement | null>(null);
- const sectionId = `${section.type}-${section.collectionId || 'default'}`;
+ const sectionId = `${section.type}-${section.collectionId || "default"}`;
useEffect(() => {
const el = element;
@@ -268,20 +296,22 @@ function DraggableListItem({
data-section-id={sectionId}
className={`
py-1 px-2 flex items-center justify-between cursor-pointer rounded
- ${section.enabled ? 'cursor-grab active:cursor-grabbing' : ''}
- ${isDragged ? 'opacity-50' : ''}
+ ${section.enabled ? "cursor-grab active:cursor-grabbing" : ""}
+ ${isDragged ? "opacity-50" : ""}
`}
>
<div className="flex items-center gap-2">
<input
- id={`section-${section.type}-${section.collectionId || 'default'}`}
+ id={`section-${section.type}-${section.collectionId || "default"}`}
className="checkbox checkbox-primary"
type="checkbox"
checked={section.enabled}
onChange={() => onCheckboxChange(section)}
/>
<label
- htmlFor={`section-${section.type}-${section.collectionId || 'default'}`}
+ htmlFor={`section-${section.type}-${
+ section.collectionId || "default"
+ }`}
className="text-sm cursor-pointer"
>
{section.name}
@@ -289,9 +319,10 @@ function DraggableListItem({
</div>
<i
- className={`bi-grip-vertical text-neutral ${section.enabled ? 'cursor-grab' : 'opacity-50'
- }`}
+ className={`bi-grip-vertical text-neutral ${
+ section.enabled ? "cursor-grab" : "opacity-50"
+ }`}
/>
</li>
);
-}
\ No newline at end of file
+}
diff --git a/apps/web/lib/api/controllers/dashboard/getDashboardDataV2.ts b/apps/web/lib/api/controllers/dashboard/getDashboardDataV2.ts
index 1690f59f..8e0cbb17 100644
--- a/apps/web/lib/api/controllers/dashboard/getDashboardDataV2.ts
+++ b/apps/web/lib/api/controllers/dashboard/getDashboardDataV2.ts
@@ -144,8 +144,8 @@ export default async function getDashboardData(
links: {
take: 16,
},
- }
- }
+ },
+ },
},
});
diff --git a/apps/web/lib/api/controllers/dashboard/updateDashboardLayout.ts b/apps/web/lib/api/controllers/dashboard/updateDashboardLayout.ts
index 528148be..ab8af240 100644
--- a/apps/web/lib/api/controllers/dashboard/updateDashboardLayout.ts
+++ b/apps/web/lib/api/controllers/dashboard/updateDashboardLayout.ts
@@ -1,63 +1,66 @@
-import { UpdateDashboardLayoutSchema, UpdateDashboardLayoutSchemaType } from "@linkwarden/lib/schemaValidation";
+import {
+ UpdateDashboardLayoutSchema,
+ UpdateDashboardLayoutSchemaType,
+} from "@linkwarden/lib/schemaValidation";
import { prisma } from "@linkwarden/prisma";
export default async function updateDashboardLayout(
- userId: number,
- body: UpdateDashboardLayoutSchemaType[]
+ userId: number,
+ body: UpdateDashboardLayoutSchemaType[]
): Promise<any> {
- const dataValidation = UpdateDashboardLayoutSchema.safeParse(body);
+ const dataValidation = UpdateDashboardLayoutSchema.safeParse(body);
- if (!dataValidation.success) {
- console.log(dataValidation.error.issues[0].message)
- return {
- response: `Error: ${dataValidation.error.issues[0].message
- } [${dataValidation.error.issues[0].path.join(", ")}]`,
- status: 400,
- };
- }
+ if (!dataValidation.success) {
+ console.log(dataValidation.error.issues[0].message);
+ return {
+ response: `Error: ${
+ dataValidation.error.issues[0].message
+ } [${dataValidation.error.issues[0].path.join(", ")}]`,
+ status: 400,
+ };
+ }
- const data = dataValidation.data;
+ const data = dataValidation.data;
- // This can be improved - less queries and not in a loop
- for (const section of data) {
+ // This can be improved - less queries and not in a loop
+ for (const section of data) {
+ const existingSection = await prisma.dashboardSection.findFirst({
+ where: {
+ userId: userId,
+ type: section.type,
+ collectionId: section.collectionId || undefined,
+ },
+ });
- const existingSection = await prisma.dashboardSection.findFirst({
- where: {
- userId: userId,
- type: section.type,
- collectionId: section.collectionId || undefined,
- },
- });
+ if (existingSection && !section.enabled) {
+ await prisma.dashboardSection.delete({
+ where: {
+ id: existingSection.id,
+ },
+ });
+ } else if (existingSection && section.enabled) {
+ await prisma.dashboardSection.update({
+ where: {
+ id: existingSection.id,
+ },
+ data: {
+ order: section.order,
+ },
+ });
+ } else if (section.enabled) {
+ await prisma.dashboardSection.create({
+ data: {
+ userId: userId,
+ type: section.type,
+ collectionId: section.collectionId || undefined,
+ order: section.order || 0,
+ },
+ });
+ }
+ }
- if (existingSection && !section.enabled) {
- await prisma.dashboardSection.delete({
- where: {
- id: existingSection.id
- }
- })
- } else if (existingSection && section.enabled) {
- await prisma.dashboardSection.update({
- where: {
- id: existingSection.id
- },
- data: {
- order: section.order
- }
- });
- } else if (section.enabled) {
- await prisma.dashboardSection.create({
- data: {
- userId: userId,
- type: section.type,
- collectionId: section.collectionId || undefined,
- order: section.order || 0
- }
- });
- }
- }
-
- return {
- status: 200,
- response: data
- }
-}
\ No newline at end of file
+ return {
+ status: 200,
+ response: data,
+ };
+}
diff --git a/apps/web/lib/api/controllers/users/userId/updateUserById.ts b/apps/web/lib/api/controllers/users/userId/updateUserById.ts
index d22e303e..fec89e00 100644
--- a/apps/web/lib/api/controllers/users/userId/updateUserById.ts
+++ b/apps/web/lib/api/controllers/users/userId/updateUserById.ts
@@ -17,8 +17,9 @@ export default async function updateUserById(
if (!dataValidation.success) {
return {
- response: `Error: ${dataValidation.error.issues[0].message
- } [${dataValidation.error.issues[0].path.join(", ")}]`,
+ response: `Error: ${
+ dataValidation.error.issues[0].message
+ } [${dataValidation.error.issues[0].path.join(", ")}]`,
status: 400,
};
}
@@ -30,18 +31,18 @@ export default async function updateUserById(
id: { not: userId },
OR: emailEnabled
? [
- {
- username: data.username.toLowerCase(),
- },
- {
- email: data.email?.toLowerCase(),
- },
- ]
+ {
+ username: data.username.toLowerCase(),
+ },
+ {
+ email: data.email?.toLowerCase(),
+ },
+ ]
: [
- {
- username: data.username.toLowerCase(),
- },
- ],
+ {
+ username: data.username.toLowerCase(),
+ },
+ ],
},
});
diff --git a/apps/web/lib/api/verifyUser.ts b/apps/web/lib/api/verifyUser.ts
index a478ea2e..56e08114 100644
--- a/apps/web/lib/api/verifyUser.ts
+++ b/apps/web/lib/api/verifyUser.ts
@@ -37,7 +37,7 @@ export default async function verifyUser({
include: {
subscriptions: true,
parentSubscription: true,
- dashboardSections: true
+ dashboardSections: true,
},
});
diff --git a/apps/web/pages/api/v2/dashboard/index.ts b/apps/web/pages/api/v2/dashboard/index.ts
index d7c9e797..5aaff7dd 100644
--- a/apps/web/pages/api/v2/dashboard/index.ts
+++ b/apps/web/pages/api/v2/dashboard/index.ts
@@ -18,8 +18,12 @@ export default async function dashboard(
cursor: req.query.cursor ? Number(req.query.cursor as string) : undefined,
};
- const showRecentLinks = user.dashboardSections.some(section => section.type === 'RECENT_LINKS');
- const showPinnedLinks = user.dashboardSections.some(section => section.type === 'PINNED_LINKS');
+ const showRecentLinks = user.dashboardSections.some(
+ (section) => section.type === "RECENT_LINKS"
+ );
+ const showPinnedLinks = user.dashboardSections.some(
+ (section) => section.type === "PINNED_LINKS"
+ );
const { statusCode, ...data } = await getDashboardDataV2(
user.id,
diff --git a/apps/web/pages/dashboard.tsx b/apps/web/pages/dashboard.tsx
index 54d4f196..698aca49 100644
--- a/apps/web/pages/dashboard.tsx
+++ b/apps/web/pages/dashboard.tsx
@@ -20,7 +20,10 @@ import SurveyModal from "@/components/ModalContent/SurveyModal";
import ImportDropdown from "@/components/ImportDropdown";
import { Button } from "@/components/ui/button";
import DashboardLayoutDropdown from "@/components/DashboardLayoutDropdown";
-import { DashboardSection, DashboardSectionType } from "@linkwarden/prisma/client";
+import {
+ DashboardSection,
+ DashboardSectionType,
+} from "@linkwarden/prisma/client";
export default function Dashboard() {
const { t } = useTranslation();
@@ -54,7 +57,7 @@ export default function Dashboard() {
user.referredBy === null &&
// if user is using Linkwarden for more than 3 days
new Date().getTime() - new Date(user.createdAt).getTime() >
- 3 * 24 * 60 * 60 * 1000
+ 3 * 24 * 60 * 60 * 1000
) {
setTimeout(() => {
setShowsSurveyModal(true);
@@ -66,19 +69,22 @@ export default function Dashboard() {
// Sort sections by order and filter enabled ones
const orderedSections = useMemo(() => {
- return dashboardSections
- .sort((a, b) => {
- if (a.order !== undefined && b.order !== undefined) {
- return a.order - b.order;
- }
- if (a.order !== undefined) return -1;
- if (b.order !== undefined) return 1;
- return 0;
- });
+ return dashboardSections.sort((a, b) => {
+ if (a.order !== undefined && b.order !== undefined) {
+ return a.order - b.order;
+ }
+ if (a.order !== undefined) return -1;
+ if (b.order !== undefined) return 1;
+ return 0;
+ });
}, [dashboardSections]);
- const showRecentLinks = dashboardSections.some(section => section.type === 'RECENT_LINKS');
- const showPinnedLinks = dashboardSections.some(section => section.type === 'PINNED_LINKS');
+ const showRecentLinks = dashboardSections.some(
+ (section) => section.type === "RECENT_LINKS"
+ );
+ const showPinnedLinks = dashboardSections.some(
+ (section) => section.type === "PINNED_LINKS"
+ );
const numberOfLinksToShow = useMemo(() => {
if (showRecentLinks && showPinnedLinks) {
@@ -189,8 +195,7 @@ export default function Dashboard() {
<div
style={{
- flex:
- links || dashboardData.isLoading ? "0 1 auto" : "1 1 auto",
+ flex: links || dashboardData.isLoading ? "0 1 auto" : "1 1 auto",
}}
className="flex flex-col 2xl:flex-row items-start 2xl:gap-2"
>
@@ -207,9 +212,7 @@ export default function Dashboard() {
<Links
links={links.slice(
0,
- settings.columns &&
- showRecentLinks &&
- showPinnedLinks
+ settings.columns && showRecentLinks && showPinnedLinks
? settings.columns * 2
: numberOfLinksToShow
)}
@@ -218,9 +221,7 @@ export default function Dashboard() {
</div>
) : (
<div className="flex flex-col justify-center h-full border border-solid border-neutral-content w-full mx-auto p-10 rounded-xl bg-base-200 bg-gradient-to-tr from-neutral-content/70 to-50% to-base-200">
- <p className="text-center text-xl">
- {t("view_added_links_here")}
- </p>
+ <p className="text-center text-xl">{t("view_added_links_here")}</p>
<p className="text-center mx-auto max-w-96 w-fit text-neutral text-sm mt-2">
{t("view_added_links_here_desc")}
</p>
@@ -282,9 +283,7 @@ export default function Dashboard() {
.filter((e: any) => e.pinnedBy && e.pinnedBy[0])
.slice(
0,
- settings.columns &&
- showRecentLinks &&
- showPinnedLinks
+ settings.columns && showRecentLinks && showPinnedLinks
? settings.columns * 2
: numberOfLinksToShow
)}
@@ -310,7 +309,7 @@ export default function Dashboard() {
);
const renderCollectionSection = (section: DashboardSection) => {
- const collection = collections.find(c => c.id === section.collectionId);
+ const collection = collections.find((c) => c.id === section.collectionId);
if (!collection) return null;
return (
@@ -341,7 +340,8 @@ export default function Dashboard() {
useData={dashboardData}
/>
</div>
- ) : links?.filter((link: any) => link.collection.id === collection.id).length > 0 ? (
+ ) : links?.filter((link: any) => link.collection.id === collection.id)
+ .length > 0 ? (
<div className="w-full">
<Links
links={links
@@ -398,7 +398,11 @@ export default function Dashboard() {
{/* Render sections in their specified order */}
{orderedSections.map((section, index) => (
- <div key={`${section.type}-${section.collectionId || 'default'}-${index}`}>
+ <div
+ key={`${section.type}-${
+ section.collectionId || "default"
+ }-${index}`}
+ >
{renderSection(section)}
</div>
))}
@@ -417,4 +421,4 @@ export default function Dashboard() {
);
}
-export { getServerSideProps };
\ No newline at end of file
+export { getServerSideProps };
diff --git a/apps/web/pages/settings/preference.tsx b/apps/web/pages/settings/preference.tsx
index 2fc2f7a7..2c712770 100644
--- a/apps/web/pages/settings/preference.tsx
+++ b/apps/web/pages/settings/preference.tsx
@@ -149,7 +149,7 @@ export default function Preference() {
newTag.archiveAsPDF !== originalTag.archiveAsPDF ||
newTag.archiveAsReadable !== originalTag.archiveAsReadable ||
newTag.archiveAsWaybackMachine !==
- originalTag.archiveAsWaybackMachine ||
+ originalTag.archiveAsWaybackMachine ||
newTag.aiTag !== originalTag.aiTag
);
});
@@ -208,10 +208,11 @@ export default function Preference() {
].map(({ theme, icon, bgColor, textColor, activeColor }) => (
<div
key={theme}
- className={`w-full text-center outline-solid outline-neutral-content outline h-20 duration-100 rounded-xl flex items-center justify-center cursor-pointer select-none ${bgColor} ${localStorage.getItem("theme") === theme
- ? `outline-primary ${activeColor}`
- : textColor
- }`}
+ className={`w-full text-center outline-solid outline-neutral-content outline h-20 duration-100 rounded-xl flex items-center justify-center cursor-pointer select-none ${bgColor} ${
+ localStorage.getItem("theme") === theme
+ ? `outline-primary ${activeColor}`
+ : textColor
+ }`}
onClick={() => updateSettings({ theme })}
>
<i className={`${icon} text-3xl`}></i>
@@ -352,8 +353,9 @@ export default function Preference() {
</div>
</div>
<div
- className={`mb-3 ${aiTaggingMethod === AiTaggingMethod.DISABLED ? "opacity-50" : ""
- }`}
+ className={`mb-3 ${
+ aiTaggingMethod === AiTaggingMethod.DISABLED ? "opacity-50" : ""
+ }`}
>
<Checkbox
label={t("generate_tags_for_existing_links")}
diff --git a/apps/web/public/locales/en/common.json b/apps/web/public/locales/en/common.json
index 42045803..0f851246 100644
--- a/apps/web/public/locales/en/common.json
+++ b/apps/web/public/locales/en/common.json
@@ -477,4 +477,4 @@
"display_on_dashboard": "Display on Dashboard",
"dashboard_stats": "Dashboard Stats",
"no_results_found": "No results found."
-}
\ No newline at end of file
+}