aboutsummaryrefslogtreecommitdiff
path: root/apps/web/components/content-cards/google-docs.tsx
blob: aa7da8cda337e85533d152c1908e27f03e0fcbc3 (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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
"use client"

import { useState } from "react"
import { Card, CardContent } from "@repo/ui/components/card"
import { Badge } from "@repo/ui/components/badge"
import {
	AlertDialog,
	AlertDialogAction,
	AlertDialogCancel,
	AlertDialogContent,
	AlertDialogDescription,
	AlertDialogFooter,
	AlertDialogHeader,
	AlertDialogTitle,
	AlertDialogTrigger,
} from "@repo/ui/components/alert-dialog"
import { ExternalLink, FileText, Brain, Trash2 } from "lucide-react"
import { cn } from "@lib/utils"
import { colors } from "@repo/ui/colors"
import { getPastelBackgroundColor } from "../memories-utils"

interface GoogleDocsCardProps {
	title: string
	url: string | null | undefined
	description?: string | null
	className?: string
	onClick?: () => void
	onDelete?: () => void
	showExternalLink?: boolean
	activeMemories?: Array<{ id: string; isForgotten?: boolean }>
	lastModified?: string | Date
}

export const GoogleDocsCard = ({
	title,
	url,
	description,
	className,
	onClick,
	onDelete,
	showExternalLink = true,
	activeMemories,
	lastModified,
}: GoogleDocsCardProps) => {
	const [isDialogOpen, setIsDialogOpen] = useState(false)

	const handleCardClick = () => {
		if (!isDialogOpen) {
			if (onClick) {
				onClick()
			} else if (url) {
				window.open(url, "_blank", "noopener,noreferrer")
			}
		}
	}

	const handleExternalLinkClick = (e: React.MouseEvent) => {
		e.stopPropagation()
		if (url) {
			window.open(url, "_blank", "noopener,noreferrer")
		}
	}

	return (
		<Card
			className={cn(
				"cursor-pointer transition-all hover:shadow-md group overflow-hidden relative py-4",
				className,
			)}
			onClick={handleCardClick}
			style={{
				backgroundColor: getPastelBackgroundColor(url || title || "googledocs"),
			}}
		>
			{onDelete && (
				<AlertDialog open={isDialogOpen} onOpenChange={setIsDialogOpen}>
					<AlertDialogTrigger asChild>
						<button
							className="absolute top-2 right-2 z-20 opacity-0 group-hover:opacity-100 transition-opacity p-1.5 rounded-md hover:bg-red-500/20"
							onClick={(e) => {
								e.stopPropagation()
							}}
							style={{
								color: colors.text.muted,
								backgroundColor: "rgba(255, 255, 255, 0.1)",
								backdropFilter: "blur(4px)",
							}}
							type="button"
						>
							<Trash2 className="w-3.5 h-3.5" />
						</button>
					</AlertDialogTrigger>
					<AlertDialogContent onClick={(e) => e.stopPropagation()}>
						<AlertDialogHeader>
							<AlertDialogTitle>Delete Document</AlertDialogTitle>
							<AlertDialogDescription>
								Are you sure you want to delete this document and all its
								related memories? This action cannot be undone.
							</AlertDialogDescription>
						</AlertDialogHeader>
						<AlertDialogFooter>
							<AlertDialogCancel
								onClick={(e) => {
									e.stopPropagation()
								}}
							>
								Cancel
							</AlertDialogCancel>
							<AlertDialogAction
								className="bg-red-600 hover:bg-red-700 text-white"
								onClick={(e) => {
									e.stopPropagation()
									onDelete()
								}}
							>
								Delete
							</AlertDialogAction>
						</AlertDialogFooter>
					</AlertDialogContent>
				</AlertDialog>
			)}

			<CardContent className="p-0">
				<div className="px-4 border-b border-white/10">
					<div className="flex items-center justify-between">
						<div className="flex items-center gap-2">
							<svg
								className="w-4 h-4"
								xmlns="http://www.w3.org/2000/svg"
								viewBox="0 0 87.3 78"
								aria-label="Google Docs"
							>
								<title>Google Docs</title>
								<path
									fill="#0066da"
									d="m6.6 66.85 3.85 6.65c.8 1.4 1.95 2.5 3.3 3.3L27.5 53H0c0 1.55.4 3.1 1.2 4.5z"
								/>
								<path
									fill="#00ac47"
									d="M43.65 25 29.9 1.2c-1.35.8-2.5 1.9-3.3 3.3l-25.4 44A9.06 9.06 0 0 0 0 53h27.5z"
								/>
								<path
									fill="#ea4335"
									d="M73.55 76.8c1.35-.8 2.5-1.9 3.3-3.3l1.6-2.75L86.1 57.5c.8-1.4 1.2-2.95 1.2-4.5H59.798l5.852 11.5z"
								/>
								<path
									fill="#00832d"
									d="M43.65 25 57.4 1.2C56.05.4 54.5 0 52.9 0H34.4c-1.6 0-3.15.45-4.5 1.2z"
								/>
								<path
									fill="#2684fc"
									d="M59.8 53H27.5L13.75 76.8c1.35.8 2.9 1.2 4.5 1.2h50.8c1.6 0 3.15-.45 4.5-1.2z"
								/>
								<path
									fill="#ffba00"
									d="m73.4 26.5-12.7-22c-.8-1.4-1.95-2.5-3.3-3.3L43.65 25 59.8 53h27.45c0-1.55-.4-3.1-1.2-4.5z"
								/>
							</svg>
							<div className="flex flex-col">
								<span className="text-xs text-muted-foreground">
									Google Docs
								</span>
							</div>
						</div>
						<div className="flex items-center gap-1">
							{showExternalLink && (
								<button
									onClick={handleExternalLinkClick}
									className="opacity-0 group-hover:opacity-100 transition-opacity p-1 rounded hover:bg-white/10 flex-shrink-0"
									type="button"
									aria-label="Open in Google Docs"
								>
									<ExternalLink className="w-4 h-4" />
								</button>
							)}
						</div>
					</div>
				</div>

				<div className="px-4 space-y-2">
					<div className="flex items-start justify-between gap-2">
						<h3 className="font-semibold text-sm line-clamp-2 leading-tight flex-1">
							{title || "Untitled Document"}
						</h3>
					</div>

					{description && (
						<p className="text-xs text-muted-foreground line-clamp-3 leading-relaxed">
							{description}
						</p>
					)}

					<div className="flex items-center justify-between text-xs text-muted-foreground">
						<div className="flex items-center gap-1">
							<FileText className="w-3 h-3" />
							<span>Google Workspace</span>
						</div>
						{lastModified && (
							<span className="truncate">
								Modified{" "}
								{lastModified instanceof Date
									? lastModified.toLocaleDateString()
									: new Date(lastModified).toLocaleDateString()}
							</span>
						)}
					</div>

					{activeMemories && activeMemories.length > 0 && (
						<div>
							<Badge
								className="text-xs text-accent-foreground"
								style={{
									backgroundColor: colors.memory.secondary,
								}}
								variant="secondary"
							>
								<Brain className="w-3 h-3 mr-1" />
								{activeMemories.length}{" "}
								{activeMemories.length === 1 ? "memory" : "memories"}
							</Badge>
						</div>
					)}
				</div>
			</CardContent>
		</Card>
	)
}

GoogleDocsCard.displayName = "GoogleDocsCard"