A mobile app for listening to radio stations from around the globe
git clone git://soophie.de/verbal
blob: d77b903e1e822544ed23194ece0096b8c4378411 (10843 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
this.station.likes += is_favorite ? 1 : -1;38
state.app.$refs.favorites.doFetch();39
}40
catch(error) {41
console.log(error);42
}43
},44
setStation(station) {45
state.station = station;46
state.app.$refs.player.open = true;47
},48
onTouchStart(event) {49
this.touch = event.changedTouches[0];50
this.target = event.target;51
},52
onTouchEnd(event) {53
const touch = event.changedTouches[0];54
const diff = {55
x: touch.pageX - this.touch.pageX,56
y: touch.pageY - this.touch.pageY57
};58
const angle = Math.atan(diff.x / diff.y) * (180 / Math.PI);59
const index = state.tabs.indexOf(state.tab);60
if(state.app.$refs.player.open) {61
return;62
}63
if(Math.abs(diff.x) >= SWIPE_THRESHOLD) {64
if(this.open && diff.x > 0 && (angle <= -60 || angle >= 60)) {65
this.open = false;66
}67
}68
},69
gradient(color) {70
return `linear-gradient(to bottom, ${color ?? 'transparent'}, transparent)`;71
},72
hasGroup() {73
if(this.group === null) {74
return false;75
}76
return this.group.stations.filter((station) => this.station.id !== station.id).length > 0;77
},78
getDescription() {79
return this.station.description ?? this.group?.group.description;80
}81
},82
created() {83
document.body.addEventListener('touchstart', this.onTouchStart);84
document.body.addEventListener('touchend', this.onTouchEnd);85
},86
onUnmounted() {87
document.body.removeEventListener('touchstart', this.onTouchStart);88
document.body.removeEventListener('touchend', this.onTouchEnd);89
},90
computed: {91
opacity() {92
return {93
'opacity': `${this.open === true ? 1 : 0}`,94
'pointer-events': `${this.open === true ? 'all' : 'none'}`95
};96
}97
},98
template: `99
<div class="z-40">100
<div101
@click="open = false"102
class="fixed top-0 bottom-0 left-0 right-0 bg-black/60 transition-detail"103
:style="opacity"104
>105
</div>106
<div107
ref="modal"108
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"109
:class="{ 'detail-active': open }"110
>111
<div class="w-full flex flex-col max-w-[1200px] mx-auto">112
<div113
class="w-full absolute top-0 left-0 h-[40vh] z-[-1]"114
:style="{'background': gradient(station?.color)}"115
>116
</div>117
<div class="w-full h-[98px] py-6 flex gap-4 justify-between">118
<v-button119
icon="chevron-left"120
@click="open = false"121
></v-button>122
<v-button123
icon="share"124
></v-button>125
</div>126
<div class="flex flex-col gap-5 md:mt-8">127
<v-image128
v-if="station"129
:station="station"130
class="w-[96px] h-[96px] min-w-[96px]"131
></v-image>132
<div133
v-if="station"134
class="flex flex-col flex-1 min-w-0"135
>136
<p137
:title="station.name"138
class="text-[24px] md:text-[36px] font-[600] text-gray-100 pb-0 overflow-hidden text-ellipsis whitespace-nowrap"139
>140
{{station.name}}141
</p>142
<span class="text-md text-gray-400 overflow-hidden flex gap-3 pt-1">143
<span144
v-if="station.country"145
class="text-gray-400 inline-flex items-center gap-[5px]"146
:title="$lang('global.country')"147
>148
<v-icon149
id="map-pin"150
class="w-[18px] h-[18px] !min-w-[18px] inline-flex text-gray-400"151
size="100%"152
></v-icon>153
<p>{{station.state ? station.state + ', ' : ''}}{{station.country}}</p>154
</span>155
<span156
v-if="station?.playtime && duration(station.playtime ?? 0).length > 0"157
class="text-gray-400 inline-flex items-center gap-[5px]"158
:title="$lang('detail.playtime')"159
>160
<v-icon161
id="clock"162
class="w-[18px] h-[18px] !min-w-[18px] inline-flex text-gray-400"163
size="100%"164
></v-icon>165
<p>{{duration(station.playtime ?? 0)}}</p>166
</span>167
</span>168
</div>169
</div>170
<div171
v-if="station"172
class="flex flex-col gap-6 mt-8"173
>174
<div v-if="station.tags && station.tags.length > 0" class="flex gap-3 flex-wrap">175
<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>176
</div>177
<div class="flex gap-3">178
<v-button179
icon="player-play"180
@click="() => setStation(station)"181
:text="$lang('global.listen')"182
class="bg-zinc-900 hover:bg-white px-1"183
></v-button>184
<v-button185
:icon="station.is_favorite ? 'bookmark-off' : 'bookmark'"186
:title="$lang(station.is_favorite ? 'global.unlike' : 'global.like')"187
@click="() => setLike(!station.is_favorite)"188
class="bg-zinc-900 hover:bg-white px-1"189
:text="station.likes.toString()"190
></v-button>191
</div>192
<p v-if="getDescription()" class="text-md text-gray-400" v-html="getDescription()"></p>193
<p v-else class="text-md text-gray-400">{{$lang('detail.no-description')}}</p>194
<div v-if="station.is_restricted || station.is_broken || station.is_no_track_info" class="flex gap-2 flex-wrap">195
<span196
v-if="station.is_restricted"197
class="text-white/90 items-center gap-[5px] bg-blue-600/70 rounded-[4px] text-[14px] px-[7px] inline-flex h-[24px] leading-[24px]"198
>199
<p class="-mt-[1px]">Restricted</p>200
</span>201
<span202
v-if="station.is_broken"203
class="text-white/90 items-center gap-[5px] bg-red-600/70 rounded-[4px] text-[14px] px-[7px] inline-flex h-[24px] leading-[24px]"204
>205
<p class="-mt-[1px]">Broken</p>206
</span>207
<span208
v-if="station.is_no_track_info"209
class="text-white/90 items-center gap-[5px] bg-green-600/70 rounded-[4px] text-[14px] px-[7px] inline-flex h-[24px] leading-[24px]"210
>211
<p class="-mt-[1px]">No track info</p>212
</span>213
</div>214
<div v-if="hasGroup()" class="mt-[32px]">215
<h3 class="text-white text-[24px] font-bold pb-6 sm:pt-0">{{$lang('detail.related')}}</h3>216
<ul class="flex flex-col">217
<li218
:key="station.id"219
v-for="group_station in group.stations"220
v-if="station.id !== group_station.id"221
class="border-t sm:border-t-2 first:border-none border-zinc-900 py-4 first:pt-0"222
>223
<v-station :station="group_station"></v-station>224
</li>225
</ul>226
</div>227
</div>228
</div>229
</div>230
</div>231
`232
}