mirror of
https://github.com/Spythere/pojazdownik.git
synced 2026-05-03 19:48:11 +00:00
chore(preview): adjustments in image loading & fallback
This commit is contained in:
Binary file not shown.
|
Before Width: | Height: | Size: 5.2 KiB After Width: | Height: | Size: 2.1 KiB |
@@ -1,64 +1,65 @@
|
|||||||
<template>
|
<template>
|
||||||
<section class="train-image-section">
|
<section class="train-image-section">
|
||||||
<div class="image-wrapper">
|
<div v-if="store.chosenVehicle">
|
||||||
<img
|
<img
|
||||||
:src="
|
:src="getThumbnailURL(store.chosenVehicle.type, 'small')"
|
||||||
store.chosenVehicle
|
:data-preview-active="store.chosenVehicle !== null"
|
||||||
? getThumbnailURL(store.chosenVehicle.type, 'small')
|
|
||||||
: '/images/placeholder.jpg'
|
|
||||||
"
|
|
||||||
tabindex="0"
|
|
||||||
:data-sponsor-only="store.chosenVehicle?.restrictions.sponsorOnly"
|
:data-sponsor-only="store.chosenVehicle?.restrictions.sponsorOnly"
|
||||||
:data-team-only="store.chosenVehicle?.restrictions.teamOnly"
|
:data-team-only="store.chosenVehicle?.restrictions.teamOnly"
|
||||||
@click="onImageClick"
|
@click="onImageClick"
|
||||||
@keydown.enter="onImageClick"
|
@keydown.enter="onImageClick"
|
||||||
@error="onImageError"
|
@error="onImageError"
|
||||||
|
tabindex="0"
|
||||||
/>
|
/>
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="image-info" v-if="store.chosenVehicle">
|
<div class="image-info">
|
||||||
<b class="text--accent">{{ store.chosenVehicle.type }}</b> •
|
<b class="text--accent">{{ store.chosenVehicle.type }}</b> •
|
||||||
<b style="color: #ccc">
|
<b style="color: #ccc">
|
||||||
{{
|
|
||||||
$t(
|
|
||||||
`preview.${isLocomotive(store.chosenVehicle) ? store.chosenVehicle.group : store.chosenVehicle.group}`
|
|
||||||
)
|
|
||||||
}}
|
|
||||||
</b>
|
|
||||||
|
|
||||||
<div style="color: #ccc">
|
|
||||||
<div>
|
|
||||||
{{ store.chosenVehicle.length }}m | {{ (store.chosenVehicle.weight / 1000).toFixed(1) }}t
|
|
||||||
| {{ store.chosenVehicle.maxSpeed }} km/h
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div v-if="isLocomotive(store.chosenVehicle)">
|
|
||||||
{{ $t('preview.cabin') }} {{ store.chosenVehicle.cabinType }}
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div v-else>
|
|
||||||
{{
|
{{
|
||||||
store.chosenVehicle.group == 'wagon-freight'
|
$t(
|
||||||
? $t(`usage.${store.chosenVehicle.constructionType}`)
|
`preview.${isTractionUnit(store.chosenVehicle) ? store.chosenVehicle.group : store.chosenVehicle.group}`
|
||||||
: `${$t('preview.construction')} ${store.chosenVehicle.constructionType}`
|
)
|
||||||
}}
|
}}
|
||||||
|
</b>
|
||||||
|
|
||||||
|
<div style="color: #ccc">
|
||||||
|
<div>
|
||||||
|
{{ store.chosenVehicle.length }}m |
|
||||||
|
{{ (store.chosenVehicle.weight / 1000).toFixed(1) }}t |
|
||||||
|
{{ store.chosenVehicle.maxSpeed }} km/h
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div v-if="isTractionUnit(store.chosenVehicle)">
|
||||||
|
{{ $t('preview.cabin') }} {{ store.chosenVehicle.cabinType }}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div v-else>
|
||||||
|
{{
|
||||||
|
store.chosenVehicle.group == 'wagon-freight'
|
||||||
|
? $t(`usage.${store.chosenVehicle.constructionType}`)
|
||||||
|
: `${$t('preview.construction')} ${store.chosenVehicle.constructionType}`
|
||||||
|
}}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<b v-if="store.chosenVehicle.restrictions.sponsorOnly > 0" class="sponsor-only">{{
|
||||||
|
$t('preview.sponsor-only', [
|
||||||
|
new Date(store.chosenVehicle.restrictions['sponsorOnly']).toLocaleDateString(
|
||||||
|
$i18n.locale == 'pl' ? 'pl-PL' : 'en-GB'
|
||||||
|
),
|
||||||
|
])
|
||||||
|
}}</b>
|
||||||
|
|
||||||
|
<b v-if="store.chosenVehicle.restrictions['teamOnly']" class="team-only">{{
|
||||||
|
$t('preview.team-only')
|
||||||
|
}}</b>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<b v-if="store.chosenVehicle.restrictions.sponsorOnly > 0" class="sponsor-only">{{
|
|
||||||
$t('preview.sponsor-only', [
|
|
||||||
new Date(store.chosenVehicle.restrictions['sponsorOnly']).toLocaleDateString(
|
|
||||||
$i18n.locale == 'pl' ? 'pl-PL' : 'en-GB'
|
|
||||||
),
|
|
||||||
])
|
|
||||||
}}</b>
|
|
||||||
|
|
||||||
<b v-if="store.chosenVehicle.restrictions['teamOnly']" class="team-only">{{
|
|
||||||
$t('preview.team-only')
|
|
||||||
}}</b>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="image-info" v-else>{{ $t('preview.desc') }}</div>
|
<div v-else>
|
||||||
|
<img src="/images/placeholder.jpg" alt="placeholder image" />
|
||||||
|
<div class="image-info">{{ $t('preview.desc') }}</div>
|
||||||
|
</div>
|
||||||
</section>
|
</section>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
@@ -66,7 +67,7 @@
|
|||||||
import { computed, defineComponent } from 'vue';
|
import { computed, defineComponent } from 'vue';
|
||||||
import { useStore } from '../../store';
|
import { useStore } from '../../store';
|
||||||
import { isTractionUnit } from '../../utils/vehicleUtils';
|
import { isTractionUnit } from '../../utils/vehicleUtils';
|
||||||
import { ILocomotive, IVehicle } from '../../types';
|
import { IVehicle } from '../../types';
|
||||||
import imageMixin from '../../mixins/imageMixin';
|
import imageMixin from '../../mixins/imageMixin';
|
||||||
|
|
||||||
export default defineComponent({
|
export default defineComponent({
|
||||||
@@ -87,18 +88,8 @@ export default defineComponent({
|
|||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
|
||||||
watch: {
|
|
||||||
chosenVehicle(vehicle: IVehicle, prevVehicle: IVehicle) {
|
|
||||||
if (vehicle && vehicle.type != prevVehicle?.type) {
|
|
||||||
this.store.imageLoading = true;
|
|
||||||
}
|
|
||||||
},
|
|
||||||
},
|
|
||||||
|
|
||||||
methods: {
|
methods: {
|
||||||
onImageLoad() {
|
isTractionUnit,
|
||||||
this.store.imageLoading = false;
|
|
||||||
},
|
|
||||||
|
|
||||||
onImageError(e: Event) {
|
onImageError(e: Event) {
|
||||||
const el = e.target as HTMLImageElement;
|
const el = e.target as HTMLImageElement;
|
||||||
@@ -107,10 +98,6 @@ export default defineComponent({
|
|||||||
el.src = '/images/placeholder.jpg';
|
el.src = '/images/placeholder.jpg';
|
||||||
},
|
},
|
||||||
|
|
||||||
isLocomotive(vehicle: IVehicle): vehicle is ILocomotive {
|
|
||||||
return isTractionUnit(vehicle);
|
|
||||||
},
|
|
||||||
|
|
||||||
onImageClick(e: Event) {
|
onImageClick(e: Event) {
|
||||||
const target = e.target as HTMLElement;
|
const target = e.target as HTMLElement;
|
||||||
|
|
||||||
@@ -131,22 +118,25 @@ export default defineComponent({
|
|||||||
.train-image-section {
|
.train-image-section {
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
|
align-items: center;
|
||||||
text-align: center;
|
text-align: center;
|
||||||
|
|
||||||
grid-row: 3;
|
|
||||||
grid-column: 1;
|
|
||||||
|
|
||||||
margin-top: 1em;
|
margin-top: 1em;
|
||||||
height: 22em;
|
height: 250px;
|
||||||
|
|
||||||
|
& > div {
|
||||||
|
max-width: 100%;
|
||||||
|
width: 380px;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
img {
|
img {
|
||||||
max-width: 380px;
|
|
||||||
width: 100%;
|
width: 100%;
|
||||||
height: 100%;
|
|
||||||
border: 1px solid white;
|
|
||||||
|
|
||||||
cursor: zoom-in;
|
&[data-preview-active='true'] {
|
||||||
|
border: 1px solid white;
|
||||||
|
cursor: zoom-in;
|
||||||
|
}
|
||||||
|
|
||||||
&[data-sponsor-only='true'] {
|
&[data-sponsor-only='true'] {
|
||||||
border: 1px solid $sponsorColor;
|
border: 1px solid $sponsorColor;
|
||||||
@@ -157,18 +147,16 @@ img {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.sponsor-only {
|
.placeholder {
|
||||||
color: $sponsorColor;
|
height: 250px;
|
||||||
}
|
|
||||||
|
|
||||||
.team-only {
|
background-color: $bgColor;
|
||||||
color: $teamColor;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.image-info {
|
.image-info {
|
||||||
font-size: 1.1em;
|
font-size: 1.1em;
|
||||||
padding: 0.5em;
|
padding: 0.5em;
|
||||||
margin: 0.5em auto;
|
// margin: 0.5em auto;
|
||||||
line-height: 1.35;
|
line-height: 1.35;
|
||||||
|
|
||||||
width: 100%;
|
width: 100%;
|
||||||
|
|||||||
@@ -14,8 +14,6 @@ export default defineComponent({
|
|||||||
|
|
||||||
methods: {
|
methods: {
|
||||||
previewStock(stock: IStock) {
|
previewStock(stock: IStock) {
|
||||||
// if (this.store.chosenVehicle?.imageSrc != stock.imgSrc) this.store.imageLoading = true;
|
|
||||||
|
|
||||||
if (stock.isLoco) {
|
if (stock.isLoco) {
|
||||||
const chosenLoco = this.store.locoDataList.find((v) => v.type == stock.type) || null;
|
const chosenLoco = this.store.locoDataList.find((v) => v.type == stock.type) || null;
|
||||||
this.store.chosenVehicle = chosenLoco;
|
this.store.chosenVehicle = chosenLoco;
|
||||||
|
|||||||
@@ -34,8 +34,6 @@ export const useStore = defineStore({
|
|||||||
isColdStart: false,
|
isColdStart: false,
|
||||||
isDoubleManned: false,
|
isDoubleManned: false,
|
||||||
|
|
||||||
imageLoading: false,
|
|
||||||
|
|
||||||
chosenLocoGroup: 'loco-electric' as LocoGroupType,
|
chosenLocoGroup: 'loco-electric' as LocoGroupType,
|
||||||
chosenCarGroup: 'wagon-passenger' as WagonGroupType,
|
chosenCarGroup: 'wagon-passenger' as WagonGroupType,
|
||||||
|
|
||||||
@@ -126,7 +124,6 @@ export const useStore = defineStore({
|
|||||||
try {
|
try {
|
||||||
const vehiclesData = (await http.get<IVehiclesData>('/vehicles')).data;
|
const vehiclesData = (await http.get<IVehiclesData>('/vehicles')).data;
|
||||||
this.vehiclesData = vehiclesData;
|
this.vehiclesData = vehiclesData;
|
||||||
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user