A mobile app for listening to radio stations from around the globe
git clone git://soophie.de/verbal
blob: 65f5e4b7edc570c6ab2536c1518c2addd08692b5 (10726 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.stations.filter((station) => this.station.id !== station.id).length > 0;76
},77
getDescription() {78
return this.station.description ?? this.group?.group.description;79
}80
},81
created() {82
document.body.addEventListener('touchstart', this.onTouchStart);83
document.body.addEventListener('touchend', this.onTouchEnd);84
},85
onUnmounted() {86
document.body.removeEventListener('touchstart', this.onTouchStart);87
document.body.removeEventListener('touchend', this.onTouchEnd);88
},89
computed: {90
opacity() {91
return {92
'opacity': `${this.open === true ? 1 : 0}`,93
'pointer-events': `${this.open === true ? 'all' : 'none'}`94
};95
}96
},97
template: `98
<div class="z-40">99
<div100
@click="open = false"101
class="fixed top-0 bottom-0 left-0 right-0 bg-black/60 transition-detail"102
:style="opacity"103
>104
</div>105
<div106
ref="modal"107
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"108
:class="{ 'detail-active': open }"109
>110
<div class="w-full flex flex-col max-w-[1200px] mx-auto">111
<div112
class="w-full absolute top-0 left-0 h-[40vh] z-[-1]"113
:style="{'background': gradient(station?.color)}"114
>115
</div>116
<div class="w-full h-[98px] py-6 flex gap-4 justify-between sticky top-0">117
<v-button118
icon="chevron-left"119
@click="open = false"120
></v-button>121
<v-button122
icon="share"123
></v-button>124
</div>125
<div class="flex flex-col gap-5">126
<v-image127
v-if="station"128
:station="station"129
class="w-[96px] h-[96px] min-w-[96px]"130
></v-image>131
<div132
v-if="station"133
class="flex flex-col flex-1 min-w-0"134
>135
<p136
:title="station.name"137
class="text-[24px] md:text-[36px] font-[600] text-gray-100 pb-0 overflow-hidden text-ellipsis whitespace-nowrap"138
>139
{{station.name}}140
</p>141
<span class="text-md text-gray-400 overflow-hidden flex gap-3 pt-1">142
<span143
v-if="station.country"144
class="text-gray-400 inline-flex items-center gap-[5px]"145
:title="$lang('global.country')"146
>147
<v-icon148
id="map-pin"149
class="w-[18px] h-[18px] !min-w-[18px] inline-flex text-gray-400"150
size="100%"151
></v-icon>152
<p>{{station.state ? station.state + ', ' : ''}}{{station.country}}</p>153
</span>154
<span155
v-if="station?.playtime && duration(station.playtime ?? 0).length > 0"156
class="text-gray-400 inline-flex items-center gap-[5px]"157
:title="$lang('detail.playtime')"158
>159
<v-icon160
id="clock"161
class="w-[18px] h-[18px] !min-w-[18px] inline-flex text-gray-400"162
size="100%"163
></v-icon>164
<p>{{duration(station.playtime ?? 0)}}</p>165
</span>166
</span>167
</div>168
</div>169
<div170
v-if="station"171
class="flex flex-col gap-6 mt-8"172
>173
<div v-if="station.tags && station.tags.length > 0" class="flex gap-3 flex-wrap">174
<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>175
</div>176
<div class="flex gap-3">177
<v-button178
icon="player-play"179
@click="() => setStation(station)"180
class="bg-zinc-900 hover:bg-white"181
></v-button>182
<v-button183
:icon="[ station.is_favorite ? 'heart-off' : 'heart' ]"184
:title="[ $lang(station.is_favorite ? 'global.unlike' : 'global.like') ]"185
@click="() => setLike(!station.is_favorite)"186
class="bg-zinc-900 hover:bg-white"187
:text="$lang(station.is_favorite ? 'global.unlike' : 'global.like')"188
></v-button>189
</div>190
<p v-if="getDescription()" class="text-md text-gray-400" v-html="getDescription()"></p>191
<p v-else class="text-md text-gray-400">{{$lang('detail.no-description')}}</p>192
<div v-if="station.is_restricted || station.is_broken || station.is_no_track_info" class="flex gap-2 flex-wrap">193
<span194
v-if="station.is_restricted"195
class="text-white/90 items-center gap-[5px] bg-blue-600/70 rounded-[4px] text-[14px] px-[7px] inline-flex h-[24px] leading-[24px]"196
>197
<p class="-mt-[1px]">Restricted</p>198
</span>199
<span200
v-if="station.is_broken"201
class="text-white/90 items-center gap-[5px] bg-red-600/70 rounded-[4px] text-[14px] px-[7px] inline-flex h-[24px] leading-[24px]"202
>203
<p class="-mt-[1px]">Broken</p>204
</span>205
<span206
v-if="station.is_no_track_info"207
class="text-white/90 items-center gap-[5px] bg-green-600/70 rounded-[4px] text-[14px] px-[7px] inline-flex h-[24px] leading-[24px]"208
>209
<p class="-mt-[1px]">No track info</p>210
</span>211
</div>212
<div v-if="hasGroup()" class="pt-6">213
<h4 class="text-white text-xl pb-5">{{$lang('detail.related')}}</h4>214
<ul class="flex flex-col">215
<li216
:key="station.id"217
v-for="group_station in group.stations"218
v-if="station.id !== group_station.id"219
class="border-t sm:border-t-2 first:border-none border-zinc-900 py-4 first:pt-0"220
>221
<v-station :station="group_station"></v-station>222
</li>223
</ul>224
</div>225
</div>226
</div>227
</div>228
</div>229
`230
}