A mobile app for listening to radio stations from around the globe
git clone git://soophie.de/verbal
blob: fd6be8e5c844f4eaf60969ecf81094b7a1c083e8 (7383 bytes)[doc][blame][raw]
1
import {state, SWIPE_THRESHOLD} from '../main.js';2
import {http, $lang, duration} from '../utils.js';3
import VButton from '../element/button.js';4
import VIcon from '../element/icon.js';5
import VImage from '../element/image.js';7
export default {8
data() {9
return {10
station: null,11
open: false12
};13
},14
components: {15
VButton,16
VIcon,17
VImage18
},19
watch: {20
open(value) {21
state.open = value;22
}23
},24
methods: {25
$lang,26
duration,27
async load(stationId) {28
this.station = await http`get::/api/station/${stationId}`();29
this.open = true;30
},31
onTouchStart(event) {32
this.touch = event.changedTouches[0];33
this.target = event.target;34
},35
onTouchEnd(event) {36
const touch = event.changedTouches[0];37
const diff = {38
x: touch.pageX - this.touch.pageX,39
y: touch.pageY - this.touch.pageY40
};41
const angle = Math.atan(diff.x / diff.y) * (180 / Math.PI);42
const index = state.tabs.indexOf(state.tab);43
if(this.open) {44
if(Math.abs(diff.y) >= SWIPE_THRESHOLD) {45
if(diff.y > 0 && angle >= -30 && angle <= 30) {46
this.open = false;47
}48
}49
return;50
}51
if(Math.abs(diff.y) >= SWIPE_THRESHOLD) {52
if(Math.abs(diff.y) >= SWIPE_THRESHOLD) {53
if(!this.open && this.target === this.$refs.button?.$refs.image) {54
if(diff.y < 0 && angle >= -30 && angle <= 30) {55
this.open = true;56
}57
}58
}59
}60
},61
gradient(color) {62
return `linear-gradient(to bottom, ${color ?? 'transparent'}, transparent)`;63
}64
},65
created() {66
document.body.addEventListener('touchstart', this.onTouchStart);67
document.body.addEventListener('touchend', this.onTouchEnd);68
},69
onUnmounted() {70
document.body.removeEventListener('touchstart', this.onTouchStart);71
document.body.removeEventListener('touchend', this.onTouchEnd);72
},73
computed: {74
opacity() {75
return {76
'opacity': `${this.open === true ? 1 : 0}`,77
'pointer-events': `${this.open === true ? 'all' : 'none'}`78
};79
}80
},81
template: `82
<div class="z-40">83
<div84
@click="open = false"85
class="fixed top-0 bottom-0 left-0 right-0 bg-black/60 transition-modal"86
:style="opacity"87
>88
</div>89
<div90
ref="modal"91
class="w-full max-w-[1200px] mx-auto flex flex-col bg-black fixed left-0 right-0 top-[100vh] h-[100vh] px-4 sm:px-10 transition-modal"92
:class="{ 'modal-active': open }"93
>94
<div95
class="w-full absolute top-0 left-0 h-[40vh] z-[-1]"96
:style="{'background': gradient(station?.color)}"97
>98
</div>99
<div class="w-full h-[98px] py-6 flex gap-4 justify-between">100
<v-button101
icon="chevron-down"102
@click="open = false"103
></v-button>104
<v-button105
icon="share"106
></v-button>107
</div>108
<div class="flex flex-col gap-4">109
<v-image110
v-if="station"111
:station="station"112
class="w-[96px] h-[96px] min-w-[96px]"113
></v-image>114
<div115
v-if="station"116
class="flex flex-col flex-1 min-w-0"117
>118
<p119
:title="station.name"120
class="text-[24px] font-[600] text-gray-100 pb-0 overflow-hidden text-ellipsis whitespace-nowrap"121
>122
{{station.name}}123
</p>124
<span class="text-md text-gray-400 overflow-hidden flex gap-2 sm:gap-3">125
<span126
v-if="station.country"127
class="text-gray-400 inline-flex items-center gap-[5px]"128
:title="$lang('global.country')"129
>130
<v-icon131
id="map-pin"132
class="w-[18px] h-[18px] !min-w-[18px] inline-flex text-gray-400"133
size="100%"134
></v-icon>135
<p>{{station.state ? station.state + ', ' : ''}}{{station.country}}</p>136
</span>137
</span>138
</div>139
</div>140
<div141
v-if="station"142
class="flex flex-col gap-6 mt-8"143
>144
<div v-if="station.tags && station.tags.length > 0" class="flex gap-3 flex-wrap">145
<span v-for="tag in station.tags" class="cursor-pointer text-md text-white/90 font-medium items-center gap-[5px] bg-zinc-900 hover:bg-zinc-800 rounded-[4px] text-[14px] px-[14px] inline-flex h-[34px] leading-[34px]">{{tag}}</span>146
</div>147
<p class="text-md text-gray-400">{{$lang('detail.playtime')}}: {{duration(station.playtime ?? 0)}}</p>148
<p v-if="station.description" class="text-md text-gray-400" v-html="station.description"></p>149
<p v-else class="text-md text-gray-400">{{$lang('detail.no-description')}}</p>150
<div v-if="station.is_restricted || station.is_broken || station.is_no_track_info" class="flex gap-2 flex-wrap">151
<span152
v-if="station.is_restricted"153
class="text-white/90 items-center gap-[5px] bg-blue-600/70 rounded-[4px] text-[14px] px-[7px] inline-flex h-[24px] leading-[24px]"154
>155
<p class="-mt-[1px]">Restricted</p>156
</span>157
<span158
v-if="station.is_broken"159
class="text-white/90 items-center gap-[5px] bg-red-600/70 rounded-[4px] text-[14px] px-[7px] inline-flex h-[24px] leading-[24px]"160
>161
<p class="-mt-[1px]">Broken</p>162
</span>163
<span164
v-if="station.is_no_track_info"165
class="text-white/90 items-center gap-[5px] bg-green-600/70 rounded-[4px] text-[14px] px-[7px] inline-flex h-[24px] leading-[24px]"166
>167
<p class="-mt-[1px]">No track info</p>168
</span>169
</div>170
</div>171
</div>172
</div>173
`174
}