Skip to content

Commit

Permalink
Merge pull request #66 from Carifio24/calendar-picker
Browse files Browse the repository at this point in the history
Use calendar picker for date selection
  • Loading branch information
patudom authored Oct 23, 2024
2 parents 38dddc2 + 4aa4867 commit 2e86ebd
Show file tree
Hide file tree
Showing 4 changed files with 5,691 additions and 8,346 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"@fortawesome/fontawesome-svg-core": "^6.5.1",
"@fortawesome/free-solid-svg-icons": "^6.5.1",
"@fortawesome/vue-fontawesome": "^3.0.5",
"@vuepic/vue-datepicker": "^9.0.3",
"@wwtelescope/engine-pinia": "^0.9.0",
"date-fns": "^3.6.0",
"date-fns-tz": "^3.1.3",
Expand Down
70 changes: 42 additions & 28 deletions src/TempoLite.vue
Original file line number Diff line number Diff line change
Expand Up @@ -234,19 +234,19 @@
:value="0"
@keyup.enter="radio = 0"
>
<template #label>
<v-select
:modelValue="singleDateSelected"
:disabled="radio !== 0"
:items="uniqueDays"
item-title="title"
item-value="value"
label="Select a Date"
@update:model-value="(e) => { singleDateSelected = e;}"
hide-details
></v-select>
</template>
</v-radio>
<date-picker
v-model="singleDateSelected"
:allowed-dates="uniqueDays"
:disabled="radio != 0"
:clearable="false"
:enable-time-picker="false"
:multi-dates="false"
:transitions="false"
:format="(date: Date | null) => date?.toDateString()"
:preview-format="(date: Date | null) => date?.toDateString()"
dark
></date-picker>
</v-radio-group>
</div>
<!-- create a list of the uniqueDays -->
Expand All @@ -268,9 +268,9 @@
<v-btn
v-bind="props"
class="rounded-icon-wrapper"
@click="singleDateSelected = uniqueDays[uniqueDays.findIndex(day => day.value === singleDateSelected) - 1]?.value"
@keyup.enter="singleDateSelected = uniqueDays[uniqueDays.findIndex(day => day.value === singleDateSelected) - 1]?.value"
:disabled="radio !== 0 || singleDateSelected === uniqueDays[0].value"
@click="moveBackwardOneDay"
@keyup.enter="moveBackwardOneDay"
:disabled="radio !== 0 || singleDateSelected === uniqueDays[0]"
color="#009ade"
variant="outlined"
elevation="0"
Expand All @@ -286,9 +286,9 @@
<v-btn
v-bind="props"
class="rounded-icon-wrapper"
@click="singleDateSelected = uniqueDays[uniqueDays.findIndex(day => day.value === singleDateSelected) + 1]?.value"
@keyup.enter="singleDateSelected = uniqueDays[uniqueDays.findIndex(day => day.value === singleDateSelected) + 1]?.value"
:disabled="radio !== 0 || singleDateSelected === uniqueDays[uniqueDays.length - 1].value"
@click="moveForwardOneDay"
@keyup.enter="moveForwardOneDay"
:disabled="radio !== 0 || singleDateSelected === uniqueDays[uniqueDays.length - 1]"
color="#009ade"
variant="outlined"
elevation="0"
Expand Down Expand Up @@ -780,7 +780,7 @@ export default defineComponent({
fosterTimestamps,
preload: true,
singleDateSelected: Date.now() as number | null,
singleDateSelected: new Date(),
searchOpen: true,
searchErrorMessage: null as string | null,
Expand Down Expand Up @@ -839,7 +839,7 @@ export default defineComponent({
pane: 'labels'
}).addTo(this.map as Map);
this.singleDateSelected = this.uniqueDays[this.uniqueDays.length-1].value;
this.singleDateSelected = this.uniqueDays[this.uniqueDays.length-1];
this.imageOverlay.setUrl(this.imageUrl).addTo(this.map as Map);
this.cloudOverlay.setUrl(this.cloudUrl).addTo(this.map as Map);
Expand Down Expand Up @@ -1004,15 +1004,13 @@ export default defineComponent({
}
},
uniqueDays() {
uniqueDays(): Date[] {
// eastern time
const offset = (date: Date) => getTimezoneOffset("US/Eastern", date);
const easternDates = this.timestamps.map(ts => new Date(ts + offset(new Date(ts))));
const days = easternDates.map(date => new Date(date.getUTCFullYear(), date.getUTCMonth(), date.getUTCDate())).map(date => date.getTime());
const unique = Array.from(new Set(days));
const stamps = unique.map(day => new Date(day)).map(date => date.toDateString());
// create an object with keys for timestamp and value
return stamps.map((stamp, index) => ({ value: unique[index], title: stamp }));
const days = easternDates.map(date => (new Date(date.getUTCFullYear(), date.getUTCMonth(), date.getUTCDate())).getTime());
const unique = Array.from(new Set(days));
return unique.map(ts => new Date(ts));
},
highresAvailable() {
Expand Down Expand Up @@ -1192,6 +1190,18 @@ export default defineComponent({
});
});
},
getUniqueDayIndex(date: Date): number {
return this.uniqueDays.findIndex(day => day.getTime() === date.getTime());
},
moveBackwardOneDay() {
this.singleDateSelected = this.uniqueDays[this.getUniqueDayIndex(this.singleDateSelected) - 1];
},
moveForwardOneDay() {
this.singleDateSelected = this.uniqueDays[this.getUniqueDayIndex(this.singleDateSelected) + 1];
}
},
Expand Down Expand Up @@ -1257,7 +1267,7 @@ export default defineComponent({
},
timestamps() {
this.singleDateSelected = this.uniqueDays[this.uniqueDays.length-1].value;
this.singleDateSelected = this.uniqueDays[this.uniqueDays.length-1];
},
radio(value: number) {
Expand All @@ -1267,7 +1277,7 @@ export default defineComponent({
if (value == 0) {
// this.minIndex = 0;
// this.maxIndex = this.timestamps.length - 1;
this.setNearestDate(this.singleDateSelected);
this.setNearestDate(this.singleDateSelected.getTime());
this.sublocationRadio = null;
return;
}
Expand Down Expand Up @@ -1317,6 +1327,10 @@ export default defineComponent({
--map-height: 500px;
}
.dp__theme_dark {
--dp-primary-color: var(--accent-color) !important;
}
html {
height: 100%;
margin: 0;
Expand Down
5 changes: 4 additions & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import InfoButton from "./InfoButton.vue";
import vuetify from "../plugins/vuetify";

import { FontAwesomeIcon } from "@fortawesome/vue-fontawesome";

import { library } from "@fortawesome/fontawesome-svg-core";
import {
faBookOpen,
Expand All @@ -23,6 +22,9 @@ import {
faHome,
} from "@fortawesome/free-solid-svg-icons";

import VueDatePicker from "@vuepic/vue-datepicker";
import '@vuepic/vue-datepicker/dist/main.css';

library.add(faBookOpen);
library.add(faPlay);
library.add(faPause);
Expand Down Expand Up @@ -68,6 +70,7 @@ createApp(TempoLite, {})
.component('location-search', LocationSearch)
.component('info-button', InfoButton)
.component('colorbar-horizontal', ColorBarHorizontal)
.component('date-picker', VueDatePicker)

// Mount
.mount("#app");
Loading

0 comments on commit 2e86ebd

Please sign in to comment.