A mobile app for listening to radio stations from around the globe
git clone git://soophie.de/verbal
blob: 40c1d2778e0f35ca2948e5a012324094d6475a7f (10583 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';6
import VStation from '../component/station.js';8
export default {9
data() {10
return {11
station: null,12
group: null,13
open: false14
};15
},16
components: {17
VButton,18
VIcon,19
VImage,20
VStation21
},22
methods: {23
$lang,24
duration,25
async load(stationId) {26
this.station = await http`get::/api/station/${stationId}`();27
this.group = null;28
if(this.station.group_id) {29
this.group = await http`get::/api/group/${this.station.group_id}`();30
}31
this.open = true;32
},33
async setLike(is_favorite) {34
try {35
await http`${is_favorite ? 'post' : 'delete'}::/api/favorite`(this.station.id);36
this.station.is_favorite = is_favorite;37
state.app.$refs.favorites.doFetch();38
}39
catch(error) {40
console.log(error);41
}42
},43
setStation(station) {44
state.station = station;45
state.app.$refs.player.open = true;46
},47
onTouchStart(event) {48
this.touch = event.changedTouches[0];49
this.target = event.target;50
},51
onTouchEnd(event) {52
const touch = event.changedTouches[0];53
const diff = {54
x: touch.pageX - this.touch.pageX,55
y: touch.pageY - this.touch.pageY56
};57
const angle = Math.atan(diff.x / diff.y) * (180 / Math.PI);58
const index = state.tabs.indexOf(state.tab);59
if(state.app.$refs.player.open) {60
return;61
}62
if(Math.abs(diff.x) >= SWIPE_THRESHOLD) {63
if(this.open && diff.x > 0 && (angle <= -60 || angle >= 60)) {64
this.open = false;65
}66
}67
},68
gradient(color) {69
return `linear-gradient(to bottom, ${color ?? 'transparent'}, transparent)`;70
},71
hasGroup() {72
if(this.group === null) {73
return false;74
}75
return this.group.filter((station) => this.station.id !== station.id).length > 0;76
}77
},78
created() {79
document.body.addEventListener('touchstart', this.onTouchStart);80
document.body.addEventListener('touchend', this.onTouchEnd);81
},82
onUnmounted() {83
document.body.removeEventListener('touchstart', this.onTouchStart);84
document.body.removeEventListener('touchend', this.onTouchEnd);85
},86
computed: {87
opacity() {88
return {89
'opacity': `${this.open === true ? 1 : 0}`,90
'pointer-events': `${this.open === true ? 'all' : 'none'}`91
};92
}93
},94
template: `95
<div class="z-40">96
<div97
@click="open = false"98
class="fixed top-0 bottom-0 left-0 right-0 bg-black/60 transition-detail"99
:style="opacity"100
>101
</div>102
<div103
ref="modal"104
class="w-full mx-auto flex flex-col bg-black fixed left-[100vw] top-0 h-[100vh] overflow-y-auto px-4 pb-12 sm:pb-[100px] sm:px-10 transition-detail"105
:class="{ 'detail-active': open }"106
>107
<div class="w-full flex flex-col max-w-[1200px] mx-auto">108
<div109
class="w-full absolute top-0 left-0 h-[40vh] z-[-1]"110
:style="{'background': gradient(station?.color)}"111
>112
</div>113
<div class="w-full h-[98px] py-6 flex gap-4 justify-between sticky top-0">114
<v-button115
icon="chevron-left"116
@click="open = false"117
></v-button>118
<v-button119
icon="share"120
></v-button>121
</div>122
<div class="flex flex-col gap-5">123
<v-image124
v-if="station"125
:station="station"126
class="w-[96px] h-[96px] min-w-[96px]"127
></v-image>128
<div129
v-if="station"130
class="flex flex-col flex-1 min-w-0"131
>132
<p133
:title="station.name"134
class="text-[24px] font-[600] text-gray-100 pb-0 overflow-hidden text-ellipsis whitespace-nowrap"135
>136
{{station.name}}137
</p>138
<span class="text-md text-gray-400 overflow-hidden flex gap-3 pt-1">139
<span140
v-if="station.country"141
class="text-gray-400 inline-flex items-center gap-[5px]"142
:title="$lang('global.country')"143
>144
<v-icon145
id="map-pin"146
class="w-[18px] h-[18px] !min-w-[18px] inline-flex text-gray-400"147
size="100%"148
></v-icon>149
<p>{{station.state ? station.state + ', ' : ''}}{{station.country}}</p>150
</span>151
<span152
v-if="station?.playtime && duration(station.playtime ?? 0).length > 0"153
class="text-gray-400 inline-flex items-center gap-[5px]"154
:title="$lang('detail.playtime')"155
>156
<v-icon157
id="clock"158
class="w-[18px] h-[18px] !min-w-[18px] inline-flex text-gray-400"159
size="100%"160
></v-icon>161
<p>{{duration(station.playtime ?? 0)}}</p>162
</span>163
</span>164
</div>165
</div>166
<div167
v-if="station"168
class="flex flex-col gap-6 mt-8"169
>170
<div v-if="station.tags && station.tags.length > 0" class="flex gap-3 flex-wrap">171
<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>172
</div>173
<div class="flex gap-3">174
<v-button175
icon="player-play"176
@click="() => setStation(station)"177
class="bg-zinc-900 hover:bg-white"178
></v-button>179
<v-button180
:icon="[ station.is_favorite ? 'heart-off' : 'heart' ]"181
:title="[ $lang(station.is_favorite ? 'global.unlike' : 'global.like') ]"182
@click="() => setLike(!station.is_favorite)"183
class="bg-zinc-900 hover:bg-white"184
:text="$lang(station.is_favorite ? 'global.unlike' : 'global.like')"185
></v-button>186
</div>187
<p v-if="station.description" class="text-md text-gray-400" v-html="station.description"></p>188
<p v-else class="text-md text-gray-400">{{$lang('detail.no-description')}}</p>189
<div v-if="station.is_restricted || station.is_broken || station.is_no_track_info" class="flex gap-2 flex-wrap">190
<span191
v-if="station.is_restricted"192
class="text-white/90 items-center gap-[5px] bg-blue-600/70 rounded-[4px] text-[14px] px-[7px] inline-flex h-[24px] leading-[24px]"193
>194
<p class="-mt-[1px]">Restricted</p>195
</span>196
<span197
v-if="station.is_broken"198
class="text-white/90 items-center gap-[5px] bg-red-600/70 rounded-[4px] text-[14px] px-[7px] inline-flex h-[24px] leading-[24px]"199
>200
<p class="-mt-[1px]">Broken</p>201
</span>202
<span203
v-if="station.is_no_track_info"204
class="text-white/90 items-center gap-[5px] bg-green-600/70 rounded-[4px] text-[14px] px-[7px] inline-flex h-[24px] leading-[24px]"205
>206
<p class="-mt-[1px]">No track info</p>207
</span>208
</div>209
<div v-if="hasGroup()" class="pt-6">210
<h4 class="text-white text-xl pb-5">{{$lang('detail.related')}}</h4>211
<ul class="flex flex-col">212
<li213
:key="station.id"214
v-for="group_station in group"215
v-if="station.id !== group_station.id"216
class="border-t sm:border-t-2 first:border-none border-zinc-900 py-4 first:pt-0"217
>218
<v-station :station="group_station"></v-station>219
</li>220
</ul>221
</div>222
</div>223
</div>224
</div>225
</div>226
`227
}