Skip to content

Commit

Permalink
Added bookmark exporting
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelschwobe committed Oct 31, 2023
1 parent 7ed4bcc commit b161d79
Show file tree
Hide file tree
Showing 10 changed files with 719 additions and 3 deletions.
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ TagsForDays extends traditional bookmarking with advanced organization and searc
- TODO: Tag: tag colors or other fields

- TODO: Bookmark: assess orderBy (title, date, etc.)
- TODO: Bookmark: export/selection (text, csv, json, html)
- TODO: Bookmark: watchtower route (dead links, redirects, etc.)
- TODO: Bookmark: suggest/postfetch-opt-in title/description
- TODO: Bookmark: suggest tags
Expand Down
60 changes: 58 additions & 2 deletions app/components/bookmarks-table.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { Form } from "@remix-run/react";
import type { ColumnDef } from "@tanstack/react-table";
import {
createColumnHelper,
Expand Down Expand Up @@ -25,6 +26,7 @@ import {
} from "~/components/ui/table";
import type { getBookmarks } from "~/models/bookmark.server";
import type { ItemWithFaviconSrcProp } from "~/models/favicon.server";
import { BOOKMARK_EXPORT_LABEL_MAP } from "~/utils/bookmark";
import { cn } from "~/utils/misc";

type GetBookmarksData = Awaited<ReturnType<typeof getBookmarks>>;
Expand Down Expand Up @@ -253,8 +255,12 @@ export function BookmarksTable<TData, TValue>({
/>
</Td>
<Td className="pl-6 pr-3" colSpan={columns.length - 1}>
{selectedIds.length} of {table.getRowModel().rows.length} Rows
selected
<SelectedBookmarksForm
selectedIds={selectedIds}
totalLength={table.getRowModel().rows.length}
>
<ButtonExportGroup />
</SelectedBookmarksForm>
</Td>
</Tr>
</Tfoot>
Expand Down Expand Up @@ -349,3 +355,53 @@ function ButtonFavorite({
/>
);
}

function ButtonExportGroup() {
return (
<div className="flex flex-wrap items-center gap-2">
{Object.entries(BOOKMARK_EXPORT_LABEL_MAP).map(([ext, label]) => (
<ButtonExport key={ext} formAction={`/bookmarks.${ext}`}>
{label}
</ButtonExport>
))}
</div>
);
}

function ButtonExport({
children,
formAction,
}: {
children: React.ReactNode;
formAction: string;
}) {
return (
<Button type="submit" formAction={formAction} variant="outlined" size="sm">
<Icon type="download" />
<span className="sr-only">Export </span>
{children}
</Button>
);
}

function SelectedBookmarksForm({
children,
selectedIds,
totalLength,
}: {
children: React.ReactNode;
selectedIds: string[];
totalLength: number;
}) {
return (
<Form method="POST" reloadDocument>
<input type="hidden" name="selected-ids" value={selectedIds.join(",")} />
<div className="flex flex-col gap-2 max-sm:max-w-[75vw] sm:flex-row sm:items-center sm:justify-between">
<div className="text-sm tabular-nums">
{selectedIds.length} of {totalLength} rows selected.
</div>
{children}
</div>
</Form>
);
}
8 changes: 8 additions & 0 deletions app/routes/bookmarks[.csv].tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import {
createExportAction,
createExportLoader,
} from "~/utils/bookmark-exports.server";

export const loader = createExportLoader("csv");

export const action = createExportAction("csv");
8 changes: 8 additions & 0 deletions app/routes/bookmarks[.html].tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import {
createExportAction,
createExportLoader,
} from "~/utils/bookmark-exports.server";

export const loader = createExportLoader("html");

export const action = createExportAction("html");
8 changes: 8 additions & 0 deletions app/routes/bookmarks[.json].tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import {
createExportAction,
createExportLoader,
} from "~/utils/bookmark-exports.server";

export const loader = createExportLoader("json");

export const action = createExportAction("json");
8 changes: 8 additions & 0 deletions app/routes/bookmarks[.md].tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import {
createExportAction,
createExportLoader,
} from "~/utils/bookmark-exports.server";

export const loader = createExportLoader("md");

export const action = createExportAction("md");
8 changes: 8 additions & 0 deletions app/routes/bookmarks[.txt].tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import {
createExportAction,
createExportLoader,
} from "~/utils/bookmark-exports.server";

export const loader = createExportLoader("txt");

export const action = createExportAction("txt");
Loading

0 comments on commit b161d79

Please sign in to comment.