A mobile app for listening to radio stations from around the globe
git clone git://soophie.de/verbal
blob: 47e81e93144eb563e7efbe69e69d3e20611fbd1c (10370 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
},72
created() {73
document.body.addEventListener('touchstart', this.onTouchStart);74
document.body.addEventListener('touchend', this.onTouchEnd);75
},76
onUnmounted() {77
document.body.removeEventListener('touchstart', this.onTouchStart);78
document.body.removeEventListener('touchend', this.onTouchEnd);79
},80
computed: {81
opacity() {82
return {83
'opacity': `${this.open === true ? 1 : 0}`,84
'pointer-events': `${this.open === true ? 'all' : 'none'}`85
};86
}87
},88
template: `89
<div class="z-40">90
<div91
@click="open = false"92
class="fixed top-0 bottom-0 left-0 right-0 bg-black/60 transition-detail"93
:style="opacity"94
>95
</div>96
<div97
ref="modal"98
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"99
:class="{ 'detail-active': open }"100
>101
<div class="w-full flex flex-col max-w-[1200px] mx-auto">102
<div103
class="w-full absolute top-0 left-0 h-[40vh] z-[-1]"104
:style="{'background': gradient(station?.color)}"105
>106
</div>107
<div class="w-full h-[98px] py-6 flex gap-4 justify-between sticky top-0">108
<v-button109
icon="chevron-left"110
@click="open = false"111
></v-button>112
<v-button113
icon="share"114
></v-button>115
</div>116
<div class="flex flex-col gap-5">117
<v-image118
v-if="station"119
:station="station"120
class="w-[96px] h-[96px] min-w-[96px]"121
></v-image>122
<div123
v-if="station"124
class="flex flex-col flex-1 min-w-0"125
>126
<p127
:title="station.name"128
class="text-[24px] font-[600] text-gray-100 pb-0 overflow-hidden text-ellipsis whitespace-nowrap"129
>130
{{station.name}}131
</p>132
<span class="text-md text-gray-400 overflow-hidden flex gap-3 pt-1">133
<span134
v-if="station.country"135
class="text-gray-400 inline-flex items-center gap-[5px]"136
:title="$lang('global.country')"137
>138
<v-icon139
id="map-pin"140
class="w-[18px] h-[18px] !min-w-[18px] inline-flex text-gray-400"141
size="100%"142
></v-icon>143
<p>{{station.state ? station.state + ', ' : ''}}{{station.country}}</p>144
</span>145
<span146
v-if="station?.playtime && duration(station.playtime ?? 0).length > 0"147
class="text-gray-400 inline-flex items-center gap-[5px]"148
:title="$lang('detail.playtime')"149
>150
<v-icon151
id="clock"152
class="w-[18px] h-[18px] !min-w-[18px] inline-flex text-gray-400"153
size="100%"154
></v-icon>155
<p>{{duration(station.playtime ?? 0)}}</p>156
</span>157
</span>158
</div>159
</div>160
<div161
v-if="station"162
class="flex flex-col gap-6 mt-8"163
>164
<div v-if="station.tags && station.tags.length > 0" class="flex gap-3 flex-wrap">165
<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>166
</div>167
<div class="flex gap-3">168
<v-button169
icon="player-play"170
@click="() => setStation(station)"171
class="bg-zinc-900 hover:bg-white"172
></v-button>173
<v-button174
:icon="[ station.is_favorite ? 'heart-off' : 'heart' ]"175
:title="[ $lang(station.is_favorite ? 'global.unlike' : 'global.like') ]"176
@click="() => setLike(!station.is_favorite)"177
class="bg-zinc-900 hover:bg-white"178
:text="$lang(station.is_favorite ? 'global.unlike' : 'global.like')"179
></v-button>180
</div>181
<p v-if="station.description" class="text-md text-gray-400" v-html="station.description"></p>182
<p v-else class="text-md text-gray-400">{{$lang('detail.no-description')}}</p>183
<div v-if="station.is_restricted || station.is_broken || station.is_no_track_info" class="flex gap-2 flex-wrap">184
<span185
v-if="station.is_restricted"186
class="text-white/90 items-center gap-[5px] bg-blue-600/70 rounded-[4px] text-[14px] px-[7px] inline-flex h-[24px] leading-[24px]"187
>188
<p class="-mt-[1px]">Restricted</p>189
</span>190
<span191
v-if="station.is_broken"192
class="text-white/90 items-center gap-[5px] bg-red-600/70 rounded-[4px] text-[14px] px-[7px] inline-flex h-[24px] leading-[24px]"193
>194
<p class="-mt-[1px]">Broken</p>195
</span>196
<span197
v-if="station.is_no_track_info"198
class="text-white/90 items-center gap-[5px] bg-green-600/70 rounded-[4px] text-[14px] px-[7px] inline-flex h-[24px] leading-[24px]"199
>200
<p class="-mt-[1px]">No track info</p>201
</span>202
</div>203
<div v-if="group" class="pt-6">204
<h4 class="text-white text-xl pb-5">{{$lang('detail.related')}}</h4>205
<ul class="flex flex-col">206
<li207
:key="station.id"208
v-for="group_station in group"209
v-if="station.id !== group_station.id"210
class="border-t sm:border-t-2 first:border-none border-zinc-900 py-4 first:pt-0"211
>212
<v-station :station="group_station"></v-station>213
</li>214
</ul>215
</div>216
</div>217
</div>218
</div>219
</div>220
`221
}