Spaces:
Running
Running
File size: 17,766 Bytes
a2085ce 000c282 a2085ce cecc383 a2085ce 02e5bb9 b37da4d 71b5770 73d7323 02e5bb9 cecc383 a2085ce f5b9300 0fc7363 71b5770 cecc383 71b5770 f5b9300 02e5bb9 cecc383 02e5bb9 cecc383 f5b9300 71b5770 73d7323 71b5770 a2085ce 49c9b4d b37da4d 49c9b4d 71b5770 a541d63 71b5770 49c9b4d b37da4d 71b5770 b37da4d 71b5770 f5b9300 49c9b4d 71b5770 49c9b4d ade630a f5b9300 49c9b4d 71b5770 49c9b4d f5b9300 49c9b4d b37da4d 71b5770 b37da4d 49c9b4d 71b5770 49c9b4d a541d63 b37da4d 7033dcf 73d7323 ba77d93 02e5bb9 cecc383 02e5bb9 a2085ce d763431 a2085ce 02e5bb9 4c0dc25 f5b9300 000c282 a2085ce f5b9300 000c282 f5b9300 0fc7363 f5b9300 a2085ce 000c282 cecc383 02e5bb9 cecc383 02e5bb9 cecc383 02e5bb9 cecc383 02e5bb9 cecc383 02e5bb9 cecc383 02e5bb9 cecc383 f5b9300 02e5bb9 0fc7363 02e5bb9 0fc7363 f5b9300 0fc7363 f5b9300 ade630a a2085ce 000c282 71b5770 73d7323 71b5770 000c282 a2085ce 5cf64f4 02e5bb9 5cf64f4 a2085ce 5841bd7 02e5bb9 5841bd7 cf8d3cb 000c282 f102e36 cf8d3cb 05520a3 bf7d92d cf8d3cb bf7d92d cf8d3cb a2085ce | 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 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 | import {
Dialog,
DialogContent,
DialogHeader,
DialogTitle,
DialogDescription,
} from "@/components/ui/dialog";
import { CalendarDays, Globe, Tag, Clock, AlarmClock, CalendarPlus, CheckCircle2 } from "lucide-react";
import { Conference } from "@/types/conference";
import { parseISO, isValid, format, parse } from "date-fns";
import { Button } from "@/components/ui/button";
import {
DropdownMenu,
DropdownMenuContent,
DropdownMenuItem,
DropdownMenuTrigger,
} from "@/components/ui/dropdown-menu";
import { useState, useEffect } from "react";
import { getDeadlineInLocalTime } from '@/utils/dateUtils';
import { getAllDeadlines, getNextUpcomingDeadline, getUpcomingDeadlines } from '@/utils/deadlineUtils';
import { Checkbox } from "@/components/ui/checkbox";
import { ConferenceProgress, getProgress, setProgress } from "@/utils/progressUtils";
interface ConferenceDialogProps {
conference: Conference;
open: boolean;
onOpenChange: (open: boolean) => void;
}
const ConferenceDialog = ({ conference, open, onOpenChange }: ConferenceDialogProps) => {
console.log('Conference object:', conference);
// Get upcoming deadlines and the next upcoming one
const upcomingDeadlines = getUpcomingDeadlines(conference);
const nextDeadline = getNextUpcomingDeadline(conference);
const deadlineDate = nextDeadline ? getDeadlineInLocalTime(nextDeadline.date, nextDeadline.timezone || conference.timezone) : null;
const [countdown, setCountdown] = useState<string>('');
const confKey = `${conference.id}:${conference.year}`;
const [progress, setProgressState] = useState<ConferenceProgress>(() => getProgress(confKey));
// Replace the current location string creation with this more verbose version
const getLocationString = () => {
console.log('Venue:', conference.venue);
console.log('City:', conference.city);
console.log('Country:', conference.country);
if (conference.venue) {
return conference.venue;
}
const cityCountryArray = [conference.city, conference.country].filter(Boolean);
console.log('City/Country array after filter:', cityCountryArray);
const cityCountryString = cityCountryArray.join(", ");
console.log('Final location string:', cityCountryString);
return cityCountryString || "Location TBD"; // Fallback if everything is empty
};
// Use the function result
const location = getLocationString();
const hasUpcomingDeadlines = upcomingDeadlines.length > 0;
const conferenceEnd = conference.end || conference.start;
const conferenceEndDate = conferenceEnd ? new Date(conferenceEnd) : null;
const conferenceOver = !hasUpcomingDeadlines
? true
: conferenceEndDate && isValid(conferenceEndDate)
? new Date().getTime() > conferenceEndDate.getTime()
: false;
const updateProgress = (key: keyof ConferenceProgress) => {
const nextProgress = { ...progress, [key]: !progress[key] };
setProgressState(nextProgress);
setProgress(confKey, nextProgress);
};
useEffect(() => {
setProgressState(getProgress(confKey));
}, [confKey]);
useEffect(() => {
const calculateTimeLeft = () => {
if (!deadlineDate || !isValid(deadlineDate)) {
setCountdown('TBD');
return;
}
const now = new Date();
const difference = deadlineDate.getTime() - now.getTime();
if (difference <= 0) {
setCountdown('Deadline passed');
return;
}
const days = Math.floor(difference / (1000 * 60 * 60 * 24));
const hours = Math.floor((difference % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
const minutes = Math.floor((difference % (1000 * 60 * 60)) / (1000 * 60));
const seconds = Math.floor((difference % (1000 * 60)) / 1000);
setCountdown(`${days}d ${hours}h ${minutes}m ${seconds}s`);
};
calculateTimeLeft();
const timer = setInterval(calculateTimeLeft, 1000);
return () => clearInterval(timer);
}, [deadlineDate]);
const getCountdownColor = () => {
if (!deadlineDate || !isValid(deadlineDate)) return "text-neutral-600";
const daysRemaining = Math.ceil((deadlineDate.getTime() - new Date().getTime()) / (1000 * 60 * 60 * 24));
if (daysRemaining <= 7) return "text-red-600";
if (daysRemaining <= 30) return "text-orange-600";
return "text-green-600";
};
const parseDateFromString = (dateStr: string) => {
try {
// Handle formats like "October 19-25, 2025" or "Sept 9-12, 2025"
const [monthDay, year] = dateStr.split(", ");
const [month, dayRange] = monthDay.split(" ");
const [startDay] = dayRange.split("-");
// Construct a date string in a format that can be parsed
const dateString = `${month} ${startDay} ${year}`;
const date = parse(dateString, 'MMMM d yyyy', new Date());
if (!isValid(date)) {
// Try alternative format for abbreviated months
return parse(dateString, 'MMM d yyyy', new Date());
}
return date;
} catch (error) {
console.error("Error parsing date:", error);
return new Date();
}
};
const createCalendarEvent = (type: 'google' | 'apple') => {
try {
if (!conference.deadline || conference.deadline === 'TBD') {
throw new Error('No valid deadline found');
}
// Parse the deadline date
const deadlineDate = parseISO(conference.deadline);
if (!isValid(deadlineDate)) {
throw new Error('Invalid deadline date');
}
// Create an end date 1 hour after the deadline
const endDate = new Date(deadlineDate.getTime() + (60 * 60 * 1000));
const formatDateForGoogle = (date: Date) => format(date, "yyyyMMdd'T'HHmmss'Z'");
const formatDateForApple = (date: Date) => format(date, "yyyyMMdd'T'HHmmss'Z'");
const title = encodeURIComponent(`${conference.title} deadline`);
const locationStr = encodeURIComponent(location);
const description = encodeURIComponent(
`Paper Submission Deadline for ${conference.full_name || conference.title}\n` +
(conference.abstract_deadline ? `Abstract Deadline: ${conference.abstract_deadline}\n` : '') +
`Dates: ${conference.date}\n` +
`Location: ${location}\n` +
(conference.link ? `Website: ${conference.link}` : '')
);
if (type === 'google') {
const url = `https://calendar.google.com/calendar/render?action=TEMPLATE` +
`&text=${title}` +
`&dates=${formatDateForGoogle(deadlineDate)}/${formatDateForGoogle(endDate)}` +
`&details=${description}` +
`&location=${locationStr}` +
`&sprop=website:${encodeURIComponent(conference.link || '')}`;
window.open(url, '_blank');
} else {
const url = `data:text/calendar;charset=utf8,BEGIN:VCALENDAR
VERSION:2.0
BEGIN:VEVENT
URL:${conference.link || ''}
DTSTART:${formatDateForApple(deadlineDate)}
DTEND:${formatDateForApple(endDate)}
SUMMARY:${title}
DESCRIPTION:${description}
LOCATION:${location}
END:VEVENT
END:VCALENDAR`;
const link = document.createElement('a');
link.href = url;
link.download = `${conference.title.toLowerCase().replace(/\s+/g, '-')}-deadline.ics`;
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
}
} catch (error) {
console.error("Error creating calendar event:", error);
alert("Sorry, there was an error creating the calendar event. Please try again.");
}
};
const generateGoogleMapsUrl = (venue: string | undefined, place: string): string => {
return `https://www.google.com/maps/search/?api=1&query=${encodeURIComponent(venue || place)}`;
};
const formatDeadlineDisplay = () => {
if (!deadlineDate || !isValid(deadlineDate)) return null;
const localTZ = Intl.DateTimeFormat().resolvedOptions().timeZone;
return (
<div className="text-sm text-neutral-500">
<div>{format(deadlineDate, "MMMM d, yyyy 'at' HH:mm:ss")} ({localTZ})</div>
{conference.timezone && conference.timezone !== localTZ && (
<div className="text-xs">
Conference timezone: {conference.timezone}
</div>
)}
</div>
);
};
// Add these new functions to handle consistent date conversion
const getLocalDeadline = (dateString: string | undefined) => {
if (!dateString || dateString === 'TBD') return null;
return getDeadlineInLocalTime(dateString, conference.timezone);
};
// Format any deadline date consistently
const formatDeadlineDate = (dateString: string | undefined) => {
if (!dateString || dateString === 'TBD') return dateString || 'TBD';
const localDate = getLocalDeadline(dateString);
if (!localDate || !isValid(localDate)) return dateString;
const localTZ = Intl.DateTimeFormat().resolvedOptions().timeZone;
return `${format(localDate, "MMMM d, yyyy")} (${localTZ})`;
};
const allDeadlines = getAllDeadlines(conference);
const isDeadlinePassed = (types: string[]) => {
const matching = allDeadlines.filter((deadlineItem) => types.includes(deadlineItem.type));
if (matching.length === 0) return false;
const latest = matching.reduce<Date | null>((acc, deadlineItem) => {
const deadlineDate = getDeadlineInLocalTime(
deadlineItem.date,
deadlineItem.timezone || conference.timezone
);
if (!deadlineDate || !isValid(deadlineDate)) return acc;
if (!acc || deadlineDate.getTime() > acc.getTime()) return deadlineDate;
return acc;
}, null);
return latest ? latest.getTime() <= Date.now() : false;
};
const paperDeadlinePassed = isDeadlinePassed(["paper", "submission", "paper_submission"]);
const posterDeadlinePassed = isDeadlinePassed(["poster", "poster_submission"]);
const notificationDeadlinePassed = isDeadlinePassed([
"notification",
"decision",
"acceptance_notification",
]);
return (
<Dialog open={open} onOpenChange={onOpenChange}>
<DialogContent
className="max-w-md w-full"
>
<DialogHeader>
<DialogTitle className="text-2xl font-bold text-foreground">
{conference.title} {conference.year}
</DialogTitle>
<DialogDescription className="text-base text-gray-700">
{conference.full_name}
</DialogDescription>
</DialogHeader>
<div className="space-y-6 mt-4">
<div className="space-y-4">
<div className="flex items-start gap-2">
<CalendarDays className="h-5 w-5 mt-0.5 text-gray-500" />
<div>
<p className="font-medium">Dates</p>
<p className="text-sm text-gray-500">{conference.date}</p>
</div>
</div>
<div className="flex items-start gap-2">
<Globe className="h-5 w-5 mt-0.5 text-gray-500" />
<div>
<p className="font-medium">Venue</p>
<p className="text-sm text-gray-500">
{conference.venue || [conference.city, conference.country].filter(Boolean).join(", ")}
</p>
</div>
</div>
<div className="flex items-start gap-2">
<CheckCircle2 className="h-5 w-5 mt-0.5 text-gray-500" />
<div className="space-y-2 flex-1">
<p className="font-medium">Status</p>
<div className="flex flex-wrap gap-3 text-sm text-gray-600">
<label className="flex items-center gap-2">
<Checkbox
checked={!hasUpcomingDeadlines || progress.paper || paperDeadlinePassed}
onCheckedChange={() => updateProgress("paper")}
disabled={!hasUpcomingDeadlines || paperDeadlinePassed}
/>
Papers submitted
</label>
<label className="flex items-center gap-2">
<Checkbox
checked={!hasUpcomingDeadlines || progress.poster || posterDeadlinePassed}
onCheckedChange={() => updateProgress("poster")}
disabled={!hasUpcomingDeadlines || posterDeadlinePassed}
/>
Posters sent
</label>
<label className="flex items-center gap-2">
<Checkbox
checked={!hasUpcomingDeadlines || progress.notification || notificationDeadlinePassed}
onCheckedChange={() => updateProgress("notification")}
disabled={!hasUpcomingDeadlines || notificationDeadlinePassed}
/>
Notification
</label>
<label className="flex items-center gap-2 text-gray-500">
<Checkbox checked={conferenceOver} disabled />
Conference over
</label>
</div>
</div>
</div>
<div className="flex items-start gap-2">
<Clock className="h-5 w-5 mt-0.5 text-gray-500" />
<div className="space-y-2 flex-1">
<p className="font-medium">Important Deadlines</p>
<div className="text-xs text-gray-500 space-y-2">
{upcomingDeadlines.length > 0 ? (
<ul className="list-disc pl-4 space-y-2">
{upcomingDeadlines.map((deadline, index) => {
const isNext =
nextDeadline &&
deadline.date === nextDeadline.date &&
deadline.type === nextDeadline.type;
return (
<li key={`${deadline.type}-${index}`}>
<div
className={`rounded-md p-2 ${
isNext ? 'bg-violet/15 border border-violet/30' : 'bg-gray-100'
}`}
>
<p className={isNext ? 'font-medium text-violet' : ''}>
{formatDeadlineDate(deadline.date)} — {deadline.label}
{isNext && <span className="ml-2 text-xs">(Next)</span>}
</p>
</div>
</li>
);
})}
</ul>
) : (
<div className="bg-gray-100 rounded-md p-2">
<p>No upcoming deadlines</p>
</div>
)}
</div>
</div>
</div>
</div>
<div className="flex items-center">
<AlarmClock className={`h-5 w-5 mr-3 flex-shrink-0 ${getCountdownColor()}`} />
<div>
<span className={`font-medium ${getCountdownColor()}`}>
{countdown}
</span>
{formatDeadlineDisplay()}
</div>
</div>
{Array.isArray(conference.tags) && conference.tags.length > 0 && (
<div className="flex flex-wrap gap-2">
{conference.tags.map((tag) => (
<span key={tag} className="tag">
<Tag className="h-3 w-3 mr-1" />
{tag}
</span>
))}
</div>
)}
{conference.note && (
<div
className="text-sm text-neutral-600 mt-2 p-3 bg-neutral-50 rounded-lg"
dangerouslySetInnerHTML={{
__html: conference.note.replace(
/<a(.*?)>/g,
'<a$1 style="color: hsl(255 30% 70%); font-weight: 500; text-decoration: underline; text-underline-offset: 2px;">'
)
}}
/>
)}
<div className="flex items-center justify-between pt-2">
{conference.link && (
<Button
variant="ghost"
size="sm"
className="text-base text-violet hover:underline p-0"
asChild
>
<a
href={conference.link}
target="_blank"
rel="noopener noreferrer"
>
Visit website
</a>
</Button>
)}
<DropdownMenu>
<DropdownMenuTrigger asChild>
<Button
variant="ghost"
size="sm"
className="text-sm focus-visible:ring-0 focus:outline-none"
>
<CalendarPlus className="h-4 w-4 mr-2" />
Add to Calendar
</Button>
</DropdownMenuTrigger>
<DropdownMenuContent className="bg-white" align="end">
<DropdownMenuItem
className="text-neutral-800 hover:bg-neutral-100"
onClick={() => createCalendarEvent('google')}
>
Add to Google Calendar
</DropdownMenuItem>
<DropdownMenuItem
className="text-neutral-800 hover:bg-neutral-100"
onClick={() => createCalendarEvent('apple')}
>
Add to Apple Calendar
</DropdownMenuItem>
</DropdownMenuContent>
</DropdownMenu>
</div>
</div>
</DialogContent>
</Dialog>
);
};
export default ConferenceDialog;
|