Skip to content

Commit ae1db91

Browse files
author
Alan Smith
committed
Display local time on event if city selected
1 parent e9c3f80 commit ae1db91

File tree

9 files changed

+57
-25
lines changed

9 files changed

+57
-25
lines changed

package-lock.json

Lines changed: 14 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
"directory-named-webpack-plugin": "^4.0.1",
1616
"lodash": "^4.17.15",
1717
"luxon": "^1.16.0",
18+
"moment-timezone": "^0.5.27",
1819
"v-click-outside": "^2.1.3",
1920
"vue": "^2.6.10",
2021
"vue-datetime": "^1.0.0-beta.10",

src/components/sections/EventWeather/EventWeather.js renamed to src/components/sections/CityData/CityData.js

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@
22
/* eslint-disable object-shorthand */
33

44
import axios from 'axios';
5+
import moment from 'moment-timezone';
56
import WeatherIcon from './WeatherIcon';
67

78
export default {
8-
name: 'EventWeather',
9+
name: 'CityData',
910

1011
props: {
1112
eventCountry: {
@@ -24,6 +25,8 @@ export default {
2425
data() {
2526
return {
2627
weather: null,
28+
triggerInt: true,
29+
localTime: '',
2730
};
2831
},
2932

@@ -32,6 +35,14 @@ export default {
3235
const { data } = await axios.get(`http://eventcountdownapi.mralansmith.com/api/weather/${this.eventCity.id}`);
3336
this.weather = data;
3437
},
38+
39+
triggerTimeUpdate() {
40+
this.localTime = moment().tz(this.eventCity.timezoneName).format('h:mma');
41+
42+
setTimeout(() => {
43+
window.requestAnimationFrame(() => this.triggerTimeUpdate());
44+
}, 10000);
45+
},
3546
},
3647

3748
watch: {
@@ -47,6 +58,10 @@ export default {
4758
mounted() {
4859
if (this.eventCity) {
4960
this.getCurrentWeather();
61+
62+
if (this.eventCity.timezoneName) {
63+
this.triggerTimeUpdate();
64+
}
5065
}
5166
},
5267
};

src/components/sections/EventWeather/EventWeather.scss renamed to src/components/sections/CityData/CityData.scss

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
.c-event-weather {
1+
.c-city-data {
22
display: flex;
33
flex-direction: column;
44
align-items: center;
@@ -12,7 +12,7 @@
1212
border-bottom-right-radius: 45%;
1313
}
1414

15-
.c-event-weather__icon {
15+
.c-city-data__icon {
1616
margin-bottom: 20px;
1717
max-width: 100px;
1818
max-height: 80px;
@@ -22,13 +22,13 @@
2222
}
2323
}
2424

25-
.c-event-weather__text {
25+
.c-city-data__text {
2626
padding: 2px 10px;
2727
text-align: center;
2828
font-size: 16px;
2929
}
3030

31-
.c-event-weather__city {
31+
.c-city-data__city {
3232
font-weight: bold;
3333
padding: 2px 12px;
3434
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<template>
2+
<div
3+
class="c-city-data"
4+
v-if="weather">
5+
<weather-icon
6+
class="c-city-data__icon"
7+
:icon="weather.icon"/>
8+
<span
9+
class="c-city-data__text"
10+
v-if="localTime">{{ localTime }}</span>
11+
<span class="c-city-data__text">{{ weather.summary }}</span>
12+
<span class="c-city-data__text">{{ weather.temp }}</span>
13+
<span class="c-city-data__city c-city-data__text">
14+
in {{ eventCity.name }}, {{ eventCountry.name }}
15+
</span>
16+
</div>
17+
</template>
18+
<script src="./CityData.js"></script>
19+
<style src="./CityData.scss" lang="scss"></style>

src/components/sections/Event/Event.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import Countdown from '@chenfengyuan/vue-countdown';
22
import format from 'date-fns/format';
3-
import EventWeather from '@sections/EventWeather/EventWeather.vue';
3+
import CityData from '@sections/CityData/CityData.vue';
44
import TrashIcon from '@/assets/icons/trash.svg';
55
import EditIcon from '@/assets/icons/edit.svg';
66
import CheckIcon from '@/assets/icons/check.svg';
@@ -45,7 +45,7 @@ export default {
4545

4646
components: {
4747
Countdown,
48-
EventWeather,
48+
CityData,
4949
TrashIcon,
5050
EditIcon,
5151
CheckIcon,

src/components/sections/Event/Event.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
</div>
2020
</div>
2121
<span class="c-event__title" v-if="isReady">{{ eventName }}</span>
22-
<event-weather
22+
<city-data
2323
:event-city="eventCity"
2424
:event-country="eventCountry"/>
2525
<countdown

src/components/sections/EventWeather/EventWeather.vue

Lines changed: 0 additions & 16 deletions
This file was deleted.

0 commit comments

Comments
 (0)