aboutsummaryrefslogtreecommitdiffstats
path: root/apps/web/components/dashboard/lists/PublicListLink.tsx
blob: 9cd1f795c55a607c047ea50299ef74984b501fe1 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
"use client";

import { CopyBtnV2 } from "@/components/ui/copy-button";
import { Input } from "@/components/ui/input";
import { Label } from "@/components/ui/label";
import { Switch } from "@/components/ui/switch";
import { useClientConfig } from "@/lib/clientConfig";
import { useTranslation } from "react-i18next";

import { useEditBookmarkList } from "@karakeep/shared-react/hooks/lists";
import { ZBookmarkList } from "@karakeep/shared/types/lists";

export default function PublicListLink({ list }: { list: ZBookmarkList }) {
  const { t } = useTranslation();
  const clientConfig = useClientConfig();

  const { mutate: editList, isPending: isLoading } = useEditBookmarkList();

  const publicListUrl = `${clientConfig.publicUrl}/public/lists/${list.id}`;
  const isPublic = list.public;

  return (
    <>
      {/* Public List Toggle */}
      <div className="flex items-center justify-between">
        <div className="space-y-1">
          <Label htmlFor="public-toggle" className="text-sm font-medium">
            {t("lists.public_list.title")}
          </Label>
          <p className="text-xs text-muted-foreground">
            {t("lists.public_list.description")}
          </p>
        </div>
        <Switch
          id="public-toggle"
          checked={isPublic}
          disabled={isLoading || !!clientConfig.demoMode}
          onCheckedChange={(checked) => {
            editList({
              listId: list.id,
              public: checked,
            });
          }}
        />
      </div>

      {/* Share URL - only show when public */}
      {isPublic && (
        <>
          <div className="space-y-3">
            <Label className="text-sm font-medium">
              {t("lists.public_list.share_link")}
            </Label>
            <div className="flex items-center space-x-2">
              <Input
                value={publicListUrl}
                readOnly
                className="flex-1 text-sm"
              />
              <CopyBtnV2 getStringToCopy={() => publicListUrl} />
            </div>
          </div>
        </>
      )}
    </>
  );
}