aboutsummaryrefslogtreecommitdiffstats
path: root/apps/web/components/dashboard/admin/AdminActions.tsx
blob: a97552f87784fea5022aeb60de256138f532ecfb (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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
"use client";

import { ActionButton } from "@/components/ui/action-button";
import { toast } from "@/components/ui/use-toast";
import { api } from "@/lib/trpc";

export default function AdminActions() {
  const { mutate: recrawlLinks, isPending: isRecrawlPending } =
    api.admin.recrawlLinks.useMutation({
      onSuccess: () => {
        toast({
          description: "Recrawl enqueued",
        });
      },
      onError: (e) => {
        toast({
          variant: "destructive",
          description: e.message,
        });
      },
    });

  const { mutate: reindexBookmarks, isPending: isReindexPending } =
    api.admin.reindexAllBookmarks.useMutation({
      onSuccess: () => {
        toast({
          description: "Reindex enqueued",
        });
      },
      onError: (e) => {
        toast({
          variant: "destructive",
          description: e.message,
        });
      },
    });

  const {
    mutate: reRunInferenceOnAllBookmarks,
    isPending: isInferencePending,
  } = api.admin.reRunInferenceOnAllBookmarks.useMutation({
    onSuccess: () => {
      toast({
        description: "Inference jobs enqueued",
      });
    },
    onError: (e) => {
      toast({
        variant: "destructive",
        description: e.message,
      });
    },
  });

  const { mutateAsync: tidyAssets, isPending: isTidyAssetsPending } =
    api.admin.tidyAssets.useMutation({
      onSuccess: () => {
        toast({
          description: "Tidy assets request has been enqueued!",
        });
      },
      onError: (e) => {
        toast({
          variant: "destructive",
          description: e.message,
        });
      },
    });

  return (
    <div>
      <div className="mb-2 mt-8 text-xl font-medium">Actions</div>
      <div className="flex flex-col gap-2 sm:w-1/2">
        <ActionButton
          variant="destructive"
          loading={isRecrawlPending}
          onClick={() =>
            recrawlLinks({ crawlStatus: "failure", runInference: true })
          }
        >
          Recrawl Failed Links Only
        </ActionButton>
        <ActionButton
          variant="destructive"
          loading={isRecrawlPending}
          onClick={() =>
            recrawlLinks({ crawlStatus: "all", runInference: true })
          }
        >
          Recrawl All Links
        </ActionButton>
        <ActionButton
          variant="destructive"
          loading={isRecrawlPending}
          onClick={() =>
            recrawlLinks({ crawlStatus: "all", runInference: false })
          }
        >
          Recrawl All Links (Without Inference)
        </ActionButton>
        <ActionButton
          variant="destructive"
          loading={isInferencePending}
          onClick={() =>
            reRunInferenceOnAllBookmarks({ taggingStatus: "failure" })
          }
        >
          Regenerate AI Tags for Failed Bookmarks Only
        </ActionButton>
        <ActionButton
          variant="destructive"
          loading={isInferencePending}
          onClick={() => reRunInferenceOnAllBookmarks({ taggingStatus: "all" })}
        >
          Regenerate AI Tags for All Bookmarks
        </ActionButton>
        <ActionButton
          variant="destructive"
          loading={isReindexPending}
          onClick={() => reindexBookmarks()}
        >
          Reindex All Bookmarks
        </ActionButton>
        <ActionButton
          variant="destructive"
          loading={isTidyAssetsPending}
          onClick={() => tidyAssets()}
        >
          Compact Assets
        </ActionButton>
      </div>
    </div>
  );
}