Spaces:
Running
Running
File size: 8,390 Bytes
469f625 8c453b0 469f625 8c453b0 469f625 817573b 469f625 817573b 469f625 817573b 469f625 817573b 469f625 b9cb929 469f625 8c453b0 469f625 b9cb929 469f625 b9cb929 469f625 b9cb929 469f625 b9cb929 469f625 |
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 |
class TaskCard extends HTMLElement {
connectedCallback() {
this.attachShadow({ mode: 'open' });
const id = this.getAttribute('id');
const text = this.getAttribute('text');
const email = this.getAttribute('email');
const completed = this.getAttribute('completed') === 'true';
const hasReminder = this.getAttribute('has-reminder') === 'true';
const reminderStopped = this.getAttribute('reminder-stopped') === 'true';
const reminderFrequency = this.getAttribute('reminder-frequency');
const createdAt = this.getAttribute('created-at');
const createdDate = new Date(createdAt).toLocaleDateString();
const timeAgo = this.getTimeAgo(createdAt);
this.shadowRoot.innerHTML = `
<style>
.task-card {
background: white;
border-radius: 12px;
padding: 20px;
box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
transition: all 0.3s ease;
position: relative;
overflow: hidden;
}
.task-card:hover {
transform: translateY(-2px);
box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
}
.task-card.completed {
opacity: 0.7;
background: #f9fafb;
}
.task-text {
transition: all 0.3s ease;
}
.task-card.completed .task-text {
text-decoration: line-through;
color: #9ca3af;
}
.task-checkbox {
width: 24px;
height: 24px;
cursor: pointer;
border: 2px solid #d1d5db;
border-radius: 6px;
position: relative;
transition: all 0.2s ease;
background-color: white;
}
.task-checkbox:hover {
border-color: #3b82f6;
}
.task-checkbox.checked {
background-color: #10b981;
border-color: #10b981;
}
.task-checkbox.checked::after {
content: '✓';
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
color: white;
font-weight: bold;
font-size: 14px;
}
.action-btn {
padding: 8px;
border-radius: 8px;
transition: all 0.2s ease;
cursor: pointer;
}
.action-btn:hover {
background-color: #f3f4f6;
}
.action-btn.delete:hover {
background-color: #fee2e2;
color: #dc2626;
}
.reminder-btn {
position: relative;
}
.reminder-btn.active {
color: #3b82f6;
}
.reminder-pulse {
position: absolute;
top: 0;
right: 0;
width: 10px;
height: 10px;
background-color: #10b981;
border-radius: 50%;
animation: pulse 2s infinite;
}
@keyframes pulse {
0% {
box-shadow: 0 0 0 0 rgba(16, 185, 129, 0.7);
}
70% {
box-shadow: 0 0 0 10px rgba(16, 185, 129, 0);
}
100% {
box-shadow: 0 0 0 0 rgba(16, 185, 129, 0);
}
}
.badge {
display: inline-block;
padding: 2px 8px;
border-radius: 12px;
font-size: 0.75rem;
font-weight: 500;
}
.badge-reminder {
background-color: #dbeafe;
color: #1e40af;
}
.badge-stopped {
background-color: #fef3c7;
color: #92400e;
}
</style>
<div class="task-card ${completed ? 'completed' : ''}">
<div class="flex items-start gap-3">
<div class="task-checkbox ${completed ? 'checked' : ''}" data-action="toggle"></div>
<div class="flex-1">
<h3 class="task-text font-semibold text-gray-800 mb-2">${text}</h3>
<div class="flex flex-wrap items-center gap-2 mb-3">
<div class="flex items-center gap-1 text-xs text-gray-500">
<i data-feather="mail" class="w-3 h-3"></i>
<span class="truncate max-w-[150px]">${email}</span>
</div>
<div class="flex items-center gap-1 text-xs text-gray-500">
<i data-feather="calendar" class="w-3 h-3"></i>
<span>${timeAgo}</span>
</div>
</div>
<div class="flex items-center justify-between">
<div class="flex gap-2">
${hasReminder && !reminderStopped ?
`<span class="badge badge-reminder">Active (${reminderFrequency || 'daily'})</span>` : ''}
${reminderStopped ?
'<span class="badge badge-stopped">Reminder Stopped</span>' : ''}
</div>
<div class="flex items-center gap-1">
${!completed ? `
<button class="action-btn reminder-btn ${hasReminder && !reminderStopped ? 'active' : ''}"
data-action="reminder"
title="${hasReminder && !reminderStopped ? 'Stop Reminder' : 'Set Reminder'}"
type="button">
<i data-feather="bell" class="w-4 h-4"></i>
${hasReminder && !reminderStopped ? '<div class="reminder-pulse"></div>' : ''}
</button>
` : ''}
<button class="action-btn delete" data-action="delete" title="Delete Task" type="button">
<i data-feather="trash-2" class="w-4 h-4"></i>
</button>
</div>
</div>
</div>
</div>
</div>
`;
}
getTimeAgo(dateString) {
const date = new Date(dateString);
const seconds = Math.floor((new Date() - date) / 1000);
let interval = seconds / 31536000;
if (interval > 1) return Math.floor(interval) + 'y ago';
interval = seconds / 2592000;
if (interval > 1) return Math.floor(interval) + 'mo ago';
interval = seconds / 86400;
if (interval > 1) return Math.floor(interval) + 'd ago';
interval = seconds / 3600;
if (interval > 1) return Math.floor(interval) + 'h ago';
interval = seconds / 60;
if (interval > 1) return Math.floor(interval) + 'm ago';
return 'Just now';
}
}
customElements.define('task-card', TaskCard); |