Skip to content

Commit 42197bc

Browse files
committed
Calendar now responsive to todo list items
1 parent bcf0e1c commit 42197bc

File tree

4 files changed

+173
-106
lines changed

4 files changed

+173
-106
lines changed

src/components/CalendarComponents/DailyCalendar.vue

Lines changed: 85 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -3,26 +3,16 @@
33
<div class="calendar-container" ref="calendarContainer">
44
<div class="time-slots">
55
<!-- Generate time slots (24 hours) -->
6-
<div
7-
v-for="hour in 24"
8-
:key="hour"
9-
class="time-slot"
10-
:style="{ top: calculateTopPosition(hour) }"
11-
>
6+
<div v-for="hour in 24" :key="hour" class="time-slot" :style="{ top: calculateTopPosition(hour) }">
127
{{ formatHour(hour) }}
138
</div>
149
</div>
1510

1611
<div class="events">
17-
<!-- Render pending and completed tasks dynamically from different lists -->
18-
<div
19-
v-for="(task, index) in combinedEvents"
20-
:key="task.id"
21-
class="event"
22-
:style="getEventStyle(task)"
23-
@click="handleEventClick(task, index)"
24-
>
25-
<span :class="{ completed: task.completed }">{{ task.title }}</span>
12+
<!-- Render events dynamically -->
13+
<div v-for="(event, index) in combinedEvents" :key="`${event.listType}-${index}`" class="event"
14+
:style="getEventStyle(event)" @click="handleEventClick(event, index)">
15+
<span>{{ event.textString }}</span>
2616
</div>
2717
</div>
2818
</div>
@@ -31,98 +21,130 @@
3121

3222
<script>
3323
export default {
34-
name: 'DailyCalendar',
24+
name: "DailyCalendar",
3525
props: {
36-
completedAllTasks: {
26+
list1: {
3727
type: Array,
38-
required: true
28+
required: true,
29+
default: () => [],
3930
},
40-
pendingAllTasks: {
31+
list2: {
4132
type: Array,
42-
required: true
33+
required: true,
34+
default: () => [],
4335
},
44-
completedDailyList: {
45-
type: Array,
46-
required: true
47-
},
48-
pendingDailyList: {
49-
type: Array,
50-
required: true
51-
}
5236
},
37+
emits: ["update:list1", "update:list2", "event-clicked"],
38+
5339
computed: {
5440
combinedEvents() {
55-
// Combine all task arrays and filter by today's date
5641
const today = this.getTodayDate();
57-
return [
58-
...this.pendingAllTasks.filter(task => task.scheduledDate === today),
59-
...this.completedAllTasks.filter(task => task.scheduledDate === today),
60-
...this.pendingDailyList.filter(task => task.scheduledDate === today),
61-
...this.completedDailyList.filter(task => task.scheduledDate === today)
42+
const events = [
43+
...this.list1.map((event) => ({ ...event, listType: "list1" })),
44+
...this.list2.map((event) => ({ ...event, listType: "list2" })),
6245
];
63-
}
46+
47+
console.log('Computed Combined Events:', events.filter((event) => event.scheduledDate === today));
48+
49+
return events.filter((event) => event.scheduledDate === today);
50+
},
51+
},
52+
53+
watch: {
54+
list1(newVal) {
55+
//console.log('List1 (Backburner) updated:', newVal);
56+
},
57+
list2(newVal) {
58+
//console.log('List2 (Daily List) updated:', newVal);
59+
},
6460
},
61+
6562
methods: {
6663
calculateTopPosition(hour) {
67-
// Ensure this function works to calculate the top position based on the hour
6864
return `${hour * 60}px`;
6965
},
7066
formatHour(hour) {
71-
const ampm = hour >= 12 ? 'PM' : 'AM';
67+
const ampm = hour >= 12 ? "PM" : "AM";
7268
const formattedHour = hour % 12 || 12;
7369
return `${formattedHour} ${ampm}`;
7470
},
75-
getEventStyle(task) {
76-
const startHour = this.parseTime(task.startTime);
77-
const endHour = this.parseTime(task.endTime);
71+
72+
getEventStyle(event) {
73+
const startHour = this.parseTime(event.scheduledTime);
74+
let endHour = startHour + event.taskTimeEstimate / 60;
75+
76+
// Ensure the event doesn't go beyond the last hour of the day (24 hours) and a little less so that it wraps nicely
77+
if (endHour > 24.75) {
78+
endHour = 24.75;
79+
}
80+
7881
const topPosition = startHour * 60; // Top position in px
79-
const height = (endHour - startHour) * 60; // Event height in px
82+
let height = (endHour - startHour) * 60; // Event height in px
83+
84+
const minHeight = 25;
85+
if (height < minHeight) {
86+
height = minHeight;
87+
}
8088
8189
return {
8290
top: `${topPosition}px`,
8391
height: `${height}px`,
84-
backgroundColor: task.completed ? '#888888' : '#4caf50' // Gray if completed
92+
backgroundColor: "#4caf50", // Default color
8593
};
94+
8695
},
87-
handleEventClick(task, index) {
88-
// Emit the task's index and its list type to the parent (Dashboard)
89-
const listType = this.getListType(task);
90-
this.$emit('task-clicked', { taskIndex: index, listType });
91-
},
92-
getListType(task) {
93-
if (this.pendingAllTasks.includes(task)) return 'pendingAllTasks';
94-
if (this.completedAllTasks.includes(task)) return 'completedAllTasks';
95-
if (this.pendingDailyList.includes(task)) return 'pendingDailyList';
96-
if (this.completedDailyList.includes(task)) return 'completedDailyList';
97-
return '';
96+
97+
handleEventClick(event, index) {
98+
this.$emit("event-clicked", { event, listType: event.listType, index });
9899
},
100+
99101
getTodayDate() {
100102
const today = new Date();
101103
const year = today.getFullYear();
102-
const month = (today.getMonth() + 1).toString().padStart(2, '0');
103-
const day = today.getDate().toString().padStart(2, '0');
104+
const month = (today.getMonth() + 1).toString().padStart(2, "0");
105+
const day = today.getDate().toString().padStart(2, "0");
104106
return `${year}-${month}-${day}`; // Format: YYYY-MM-DD
105107
},
108+
109+
// Updated parseTime method to handle various formats like '2:00pm', '09:59am', '9:59am'
106110
parseTime(time) {
107-
const [hours, minutes] = time.split(':').map(Number);
111+
const regex = /(\d{1,2}):(\d{2})(am|pm)/i;
112+
const match = time.trim().match(regex);
113+
if (!match) return 0; // Default if time format is invalid
114+
115+
let [_, hours, minutes, period] = match;
116+
hours = parseInt(hours, 10);
117+
minutes = parseInt(minutes, 10);
118+
119+
// Convert to 24-hour time format
120+
if (period.toLowerCase() === 'pm' && hours !== 12) {
121+
hours += 12;
122+
} else if (period.toLowerCase() === 'am' && hours === 12) {
123+
hours = 0;
124+
}
125+
126+
// Return the time in hours (decimal format)
108127
return hours + minutes / 60;
109128
},
129+
110130
scrollToDefaultTime() {
111131
const currentTime = new Date();
112132
const defaultScrollTime = currentTime.getHours() - 1; // 1 hour before current time
113133
const scrollPosition = defaultScrollTime * 60; // Scroll to this position (in px)
114134
115135
// Scroll the container to the desired position
116136
this.$refs.calendarContainer.scrollTop = scrollPosition;
117-
}
137+
},
118138
},
139+
119140
mounted() {
120141
this.scrollToDefaultTime();
121-
}
142+
},
122143
};
123144
</script>
124145

125146
<style scoped>
147+
/* Styles remain the same */
126148
.daily-calendar {
127149
position: relative;
128150
height: 100%;
@@ -163,22 +185,19 @@ export default {
163185
position: absolute;
164186
left: 20%;
165187
width: 60%;
166-
background-color: #4caf50;
188+
background-color: blue;
167189
color: white;
168190
border-radius: 4px;
169-
padding: 10px;
191+
padding-left: 10px;
192+
padding-top:5px;
170193
box-sizing: border-box;
171194
cursor: pointer;
172195
overflow: hidden;
173196
white-space: nowrap;
174197
text-overflow: ellipsis;
175198
}
176199
177-
.event:hover {
178-
background-color: #388e3c;
179-
}
180-
181-
.completed {
182-
text-decoration: line-through;
200+
.event:hover {
201+
background-color: blue;
183202
}
184203
</style>

0 commit comments

Comments
 (0)