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
|
import type { DocumentWithMemories } from "@ui/memory-graph/types"
export const formatDate = (date: string | Date) => {
const dateObj = new Date(date)
const now = new Date()
const currentYear = now.getFullYear()
const dateYear = dateObj.getFullYear()
const monthNames = [
"Jan",
"Feb",
"Mar",
"Apr",
"May",
"Jun",
"Jul",
"Aug",
"Sep",
"Oct",
"Nov",
"Dec",
]
const month = monthNames[dateObj.getMonth()]
const day = dateObj.getDate()
const getOrdinalSuffix = (n: number) => {
const s = ["th", "st", "nd", "rd"]
const v = n % 100
return n + (s[(v - 20) % 10] || s[v] || s[0] || "th")
}
const formattedDay = getOrdinalSuffix(day)
if (dateYear !== currentYear) {
return `${month} ${formattedDay}, ${dateYear}`
}
return `${month} ${formattedDay}`
}
export const getSourceUrl = (document: DocumentWithMemories) => {
if (document.type === "google_doc" && document.customId) {
return `https://docs.google.com/document/d/${document.customId}`
}
if (document.type === "google_sheet" && document.customId) {
return `https://docs.google.com/spreadsheets/d/${document.customId}`
}
if (document.type === "google_slide" && document.customId) {
return `https://docs.google.com/presentation/d/${document.customId}`
}
if (document.metadata?.website_url) {
return document.metadata?.website_url as string
}
// Fallback to existing URL for all other document types
return document.url
}
// Simple hash function for consistent color generation
const hashString = (str: string): number => {
let hash = 0
for (let i = 0; i < str.length; i++) {
const char = str.charCodeAt(i)
hash = (hash << 5) - hash + char
hash = hash & hash // Convert to 32-bit integer
}
return Math.abs(hash)
}
// Generate consistent pastel background color based on document ID
export const getPastelBackgroundColor = (
documentId: string | undefined | null,
): string => {
// Handle null/undefined cases
if (!documentId) {
return "rgba(255, 255, 255, 0.06)" // Default fallback color
}
const hash = hashString(documentId)
// Define pastel color palette with good contrast against dark backgrounds
const pastelColors = [
// Soft pinks and roses
"rgba(255, 182, 193, 0.08)", // Light pink
"rgba(255, 218, 221, 0.08)", // Misty rose
"rgba(255, 192, 203, 0.08)", // Pink
// Soft blues and purples
"rgba(173, 216, 230, 0.08)", // Light blue
"rgba(221, 160, 221, 0.08)", // Plum
"rgba(218, 112, 214, 0.08)", // Orchid
"rgba(147, 197, 253, 0.08)", // Sky blue
// Soft greens
"rgba(152, 251, 152, 0.08)", // Pale green
"rgba(175, 238, 238, 0.08)", // Pale turquoise
"rgba(144, 238, 144, 0.08)", // Light green
// Soft oranges and yellows
"rgba(255, 218, 185, 0.08)", // Peach puff
"rgba(255, 239, 213, 0.08)", // Papaya whip
"rgba(255, 228, 196, 0.08)", // Bisque
// Soft corals and salmons
"rgba(250, 128, 114, 0.08)", // Salmon
"rgba(255, 127, 80, 0.08)", // Coral
"rgba(255, 160, 122, 0.08)", // Light salmon
]
// Use hash to consistently pick a color
const colorIndex = hash % pastelColors.length
return pastelColors[colorIndex] || "rgba(255, 255, 255, 0.06)"
}
|