A mobile app for listening to radio stations from around the globe
git clone git://soophie.de/verbal
blob: 8e4a0615e5e1085daff05969418730dae2acc6b9 (12325 bytes)[doc][blame][raw]
1
import {state, SWIPE_THRESHOLD} from '../main.js';2
import {http, $lang, $route, duration} from '../utils.js';3
import VButton from '../element/button.js';4
import VTab from '../component/tab.js';5
import VIcon from '../element/icon.js';6
import VImage from '../element/image.js';7
import VPlayButton from '../element/play-button.js';8
import VStation from '../component/station.js';10
export default {11
data() {12
return {13
station: null,14
group: null,15
open: true,16
state17
};18
},19
components: {20
VTab,21
VButton,22
VIcon,23
VImage,24
VStation,25
VPlayButton26
},27
methods: {28
$lang,29
$route,30
duration,31
async show(station) {32
this.station = await http`get::/api/station/${station.id}`();33
if(this.station === null) {34
$route('@not-found', { update: false });35
return;36
}37
this.group = null;38
if(this.station.group_id) {39
this.group = await http`get::/api/group/${this.station.group_id}`();40
}41
this.open = true;42
},43
async setLike(is_favorite) {44
try {45
await http`${is_favorite ? 'post' : 'delete'}::/api/favorite`(this.station.id);46
this.station.is_favorite = is_favorite;47
this.station.likes += is_favorite ? 1 : -1;48
state.app.$refs.favorites.doFetch();49
}50
catch(error) {51
console.log(error);52
}53
},54
onTouchStart(event) {55
this.touch = event.changedTouches[0];56
this.target = event.target;57
},58
onTouchEnd(event) {59
const touch = event.changedTouches[0];60
const diff = {61
x: touch.pageX - this.touch.pageX,62
y: touch.pageY - this.touch.pageY63
};64
const angle = Math.atan(diff.x / diff.y) * (180 / Math.PI);65
const index = state.tabs.indexOf(state.tab);66
if(state.app.$refs.player.open) {67
return;68
}69
if(Math.abs(diff.x) >= SWIPE_THRESHOLD) {70
if(this.open && diff.x > 0 && (angle <= -60 || angle >= 60)) {71
this.open = false;72
}73
}74
},75
gradient(color) {76
return `linear-gradient(to bottom, ${color ?? 'transparent'}, transparent)`;77
},78
hasGroup() {79
if(this.group === null) {80
return false;81
}82
return this.group.stations.filter((station) => this.station.id !== station.id).length > 0;83
},84
getDescription() {85
return this.station.description ?? this.group?.group.description;86
},87
share() {88
if('share' in navigator) {89
navigator.share({90
url: window.location.href,91
title: this.station.name92
});93
}94
}95
},96
mounted() {97
const path = window.location.pathname;98
const match = /^\/station\/(\d+)$/.exec(path);99
if(match) {100
const id = match[1];101
this.show({ id });102
}103
},104
created() {105
document.body.addEventListener('touchstart', this.onTouchStart);106
document.body.addEventListener('touchend', this.onTouchEnd);107
},108
onUnmounted() {109
document.body.removeEventListener('touchstart', this.onTouchStart);110
document.body.removeEventListener('touchend', this.onTouchEnd);111
},112
computed: {113
opacity() {114
return {115
'opacity': `${this.open === true ? 1 : 0}`,116
'pointer-events': `${this.open === true ? 'all' : 'none'}`117
};118
}119
},120
template: `121
<v-tab id="detail" :tab="state.tab">122
<div class="z-40">123
<div124
@click="open = false"125
class="fixed top-0 bottom-0 left-0 right-0 bg-black/60 transition-detail"126
:style="opacity"127
>128
</div>129
<div130
ref="modal"131
class="w-full mx-auto flex flex-col bg-black fixed left-[100vw] top-0 h-[100vh] overflow-y-auto pb-12 sm:pb-[100px] transition-detail"132
:class="{ 'detail-active': open }"133
>134
<div class="w-full flex flex-col px-4 sm:px-10 max-w-[1200px] mx-auto">135
<div136
class="w-full absolute top-0 left-0 h-[40vh] z-[-1]"137
:style="{'background': gradient(station?.color)}"138
>139
</div>140
<div class="w-full h-[98px] py-6 flex gap-4 justify-between">141
<v-button142
icon="chevron-left"143
@click="$route('/')"144
></v-button>145
<v-button146
icon="share"147
@click="share()"148
></v-button>149
</div>150
<div class="flex flex-col gap-5 md:mt-8">151
<v-image152
v-if="station"153
:station="station"154
class="w-[96px] h-[96px] min-w-[96px]"155
></v-image>156
<div157
v-if="station"158
class="flex flex-col flex-1 min-w-0"159
>160
<p161
:title="station.name"162
class="text-[24px] md:text-[36px] font-[600] text-gray-100 pb-0 overflow-hidden text-ellipsis whitespace-nowrap"163
>164
{{station.name}}165
</p>166
<span class="text-md text-gray-400 overflow-hidden flex flex-wrap gap-x-3 gap-y-1 pt-1">167
<span168
v-if="group?.group"169
class="text-gray-400 inline-flex items-center gap-[5px] w-full sm:w-auto"170
:title="$lang('global.country')"171
>172
<p>{{$lang('detail.hosted-by')}} {{group.group.name}}</p>173
</span>174
<span175
v-if="station.country"176
class="text-gray-400 inline-flex items-center gap-[5px]"177
:title="$lang('global.country')"178
>179
<v-icon180
id="map-pin"181
class="w-[18px] h-[18px] !min-w-[18px] inline-flex text-gray-400"182
size="100%"183
></v-icon>184
<p>{{station.state ? station.state + ', ' : ''}}{{station.country}}</p>185
</span>186
<span187
v-if="station?.playtime && duration(station.playtime ?? 0).length > 0"188
class="text-gray-400 inline-flex items-center gap-[5px]"189
:title="$lang('detail.playtime')"190
>191
<v-icon192
id="clock"193
class="w-[18px] h-[18px] !min-w-[18px] inline-flex text-gray-400"194
size="100%"195
></v-icon>196
<p>{{duration(station.playtime ?? 0)}}</p>197
</span>198
</span>199
</div>200
</div>201
<div202
v-if="station"203
class="flex flex-col gap-6 mt-8"204
>205
<div v-if="station.tags && station.tags.length > 0" class="flex gap-3 flex-wrap">206
<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>207
</div>208
<div class="flex gap-3">209
<v-play-button :station="station"></v-play-button>210
<v-button211
:icon="station.is_favorite ? 'bookmark-off' : 'bookmark'"212
:title="$lang(station.is_favorite ? 'global.unlike' : 'global.like')"213
@click="() => setLike(!station.is_favorite)"214
class="bg-zinc-900 hover:bg-white px-1"215
:text="station.likes.toString()"216
></v-button>217
</div>218
<p v-if="getDescription()" class="text-md text-gray-400 mt-2" v-html="getDescription()"></p>219
<p v-else class="text-md text-gray-400">{{$lang('detail.no-description')}}</p>220
<div v-if="station.is_restricted || station.is_broken || station.is_no_track_info" class="flex gap-2 flex-wrap">221
<span222
v-if="station.is_restricted"223
class="text-white/90 items-center gap-[5px] bg-blue-600/70 rounded-[4px] text-[14px] px-[7px] inline-flex h-[24px] leading-[24px]"224
>225
<p class="-mt-[1px]">Restricted</p>226
</span>227
<span228
v-if="station.is_broken"229
class="text-white/90 items-center gap-[5px] bg-red-600/70 rounded-[4px] text-[14px] px-[7px] inline-flex h-[24px] leading-[24px]"230
>231
<p class="-mt-[1px]">Broken</p>232
</span>233
<span234
v-if="station.is_no_track_info"235
class="text-white/90 items-center gap-[5px] bg-green-600/70 rounded-[4px] text-[14px] px-[7px] inline-flex h-[24px] leading-[24px]"236
>237
<p class="-mt-[1px]">No track info</p>238
</span>239
</div>240
<div v-if="hasGroup()" class="mt-[32px]">241
<h3 class="text-white text-[24px] font-bold pb-6 sm:pt-0">{{$lang('detail.related')}}</h3>242
<ul class="flex flex-col">243
<li244
:key="station.id"245
v-for="group_station in group.stations"246
v-if="station.id !== group_station.id"247
class="border-t sm:border-t-2 first:border-none border-zinc-900 py-4 first:pt-0"248
>249
<v-station :station="group_station"></v-station>250
</li>251
</ul>252
</div>253
</div>254
</div>255
</div>256
</div>257
</v-tab>258
`259
}