A mobile app for listening to radio stations from around the globe
git clone git://soophie.de/verbal
blob: d8bab3b75faa7960e9ae218ffdf72bbb2543c830 (8840 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';7
export default {8
data() {9
return {10
station: null,11
open: false12
};13
},14
components: {15
VButton,16
VIcon,17
VImage18
},19
methods: {20
$lang,21
duration,22
async load(stationId) {23
this.station = await http`get::/api/station/${stationId}`();24
this.open = true;25
},26
async setLike(is_favorite) {27
try {28
await http`${is_favorite ? 'post' : 'delete'}::/api/favorite`(this.station.id);29
this.station.is_favorite = is_favorite;30
state.app.$refs.favorites.doFetch();31
}32
catch(error) {33
console.log(error);34
}35
},36
setStation(station) {37
state.station = station;38
state.app.$refs.player.open = true;39
},40
onTouchStart(event) {41
this.touch = event.changedTouches[0];42
this.target = event.target;43
},44
onTouchEnd(event) {45
const touch = event.changedTouches[0];46
const diff = {47
x: touch.pageX - this.touch.pageX,48
y: touch.pageY - this.touch.pageY49
};50
const angle = Math.atan(diff.x / diff.y) * (180 / Math.PI);51
const index = state.tabs.indexOf(state.tab);52
if(state.app.$refs.player.open) {53
return;54
}55
if(Math.abs(diff.x) >= SWIPE_THRESHOLD) {56
if(this.open && diff.x > 0 && (angle <= -60 || angle >= 60)) {57
this.open = false;58
}59
}60
},61
gradient(color) {62
return `linear-gradient(to bottom, ${color ?? 'transparent'}, transparent)`;63
}64
},65
created() {66
document.body.addEventListener('touchstart', this.onTouchStart);67
document.body.addEventListener('touchend', this.onTouchEnd);68
},69
onUnmounted() {70
document.body.removeEventListener('touchstart', this.onTouchStart);71
document.body.removeEventListener('touchend', this.onTouchEnd);72
},73
computed: {74
opacity() {75
return {76
'opacity': `${this.open === true ? 1 : 0}`,77
'pointer-events': `${this.open === true ? 'all' : 'none'}`78
};79
}80
},81
template: `82
<div class="z-40">83
<div84
@click="open = false"85
class="fixed top-0 bottom-0 left-0 right-0 bg-black/60 transition-detail"86
:style="opacity"87
>88
</div>89
<div90
ref="modal"91
class="w-full max-w-[1200px] mx-auto flex flex-col bg-black fixed left-[100vh] top-0 h-[100vh] overflow-y-auto px-4 pb-12 sm:pb-[100px] sm:px-10 transition-detail"92
:class="{ 'detail-active': open }"93
>94
<div95
class="w-full absolute top-0 left-0 h-[40vh] z-[-1]"96
:style="{'background': gradient(station?.color)}"97
>98
</div>99
<div class="w-full h-[98px] py-6 flex gap-4 justify-between sticky top-0">100
<v-button101
icon="chevron-left"102
@click="open = false"103
></v-button>104
<v-button105
icon="share"106
></v-button>107
</div>108
<div class="flex flex-col gap-5">109
<v-image110
v-if="station"111
:station="station"112
class="w-[96px] h-[96px] min-w-[96px]"113
></v-image>114
<div115
v-if="station"116
class="flex flex-col flex-1 min-w-0"117
>118
<p119
:title="station.name"120
class="text-[24px] font-[600] text-gray-100 pb-0 overflow-hidden text-ellipsis whitespace-nowrap"121
>122
{{station.name}}123
</p>124
<span class="text-md text-gray-400 overflow-hidden flex gap-3 pt-1">125
<span126
v-if="station.country"127
class="text-gray-400 inline-flex items-center gap-[5px]"128
:title="$lang('global.country')"129
>130
<v-icon131
id="map-pin"132
class="w-[18px] h-[18px] !min-w-[18px] inline-flex text-gray-400"133
size="100%"134
></v-icon>135
<p>{{station.state ? station.state + ', ' : ''}}{{station.country}}</p>136
</span>137
<span138
v-if="station?.playtime && duration(station.playtime ?? 0).length > 0"139
class="text-gray-400 inline-flex items-center gap-[5px]"140
:title="$lang('detail.playtime')"141
>142
<v-icon143
id="clock"144
class="w-[18px] h-[18px] !min-w-[18px] inline-flex text-gray-400"145
size="100%"146
></v-icon>147
<p>{{duration(station.playtime ?? 0)}}</p>148
</span>149
</span>150
</div>151
</div>152
<div153
v-if="station"154
class="flex flex-col gap-6 mt-8"155
>156
<div v-if="station.tags && station.tags.length > 0" class="flex gap-3 flex-wrap">157
<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>158
</div>159
<div class="flex gap-3">160
<v-button161
icon="player-play"162
@click="() => setStation(station)"163
class="bg-zinc-900 hover:bg-white"164
></v-button>165
<v-button166
:icon="[ station.is_favorite ? 'heart-off' : 'heart' ]"167
:title="[ $lang(station.is_favorite ? 'global.unlike' : 'global.like') ]"168
@click="() => setLike(!station.is_favorite)"169
class="bg-zinc-900 hover:bg-white"170
:text="$lang(station.is_favorite ? 'global.unlike' : 'global.like')"171
></v-button>172
</div>173
<p v-if="station.description" class="text-md text-gray-400" v-html="station.description"></p>174
<p v-else class="text-md text-gray-400">{{$lang('detail.no-description')}}</p>175
<div v-if="station.is_restricted || station.is_broken || station.is_no_track_info" class="flex gap-2 flex-wrap">176
<span177
v-if="station.is_restricted"178
class="text-white/90 items-center gap-[5px] bg-blue-600/70 rounded-[4px] text-[14px] px-[7px] inline-flex h-[24px] leading-[24px]"179
>180
<p class="-mt-[1px]">Restricted</p>181
</span>182
<span183
v-if="station.is_broken"184
class="text-white/90 items-center gap-[5px] bg-red-600/70 rounded-[4px] text-[14px] px-[7px] inline-flex h-[24px] leading-[24px]"185
>186
<p class="-mt-[1px]">Broken</p>187
</span>188
<span189
v-if="station.is_no_track_info"190
class="text-white/90 items-center gap-[5px] bg-green-600/70 rounded-[4px] text-[14px] px-[7px] inline-flex h-[24px] leading-[24px]"191
>192
<p class="-mt-[1px]">No track info</p>193
</span>194
</div>195
</div>196
</div>197
</div>198
`199
}