A mobile app for listening to radio stations from around the globe
git clone git://soophie.de/verbal
1
import VStation from './station.js';2
import VButton from '../element/button.js';4
export default {5
props: ['title', 'items'],6
data() {7
return {8
index: 0,9
length: null,10
size: null,11
count: null12
};13
},14
components: {15
VStation,16
VButton17
},18
methods: {19
calc() {20
const items = this.$refs.list.querySelectorAll('li');21
this.length = items.length;22
this.size = items[1].offsetLeft;23
this.count = Math.ceil(this.$refs.list.clientWidth / this.size);24
},25
prev() {26
this.calc();27
if(this.index === 0) {28
return;29
}30
if(this.index - this.count < 0) {31
this.index = 0;32
return;33
}34
this.index -= this.count;35
},36
next() {37
this.calc();38
if(this.index === this.length - this.count - 1) {39
return;40
}41
if(this.index + this.count > this.length - this.count) {42
this.index = this.length - this.count;43
return;44
}45
this.index += this.count;46
},47
onResize() {48
this.calc();49
this.index = 0;50
}51
},52
created() {53
window.addEventListener('resize', this.onResize);54
},55
destroyed() {56
window.removeEventListener('resize', this.onResize);57
},58
computed: {59
transform() {60
return {61
'transform': `translate(${this.index * -this.size}px, 0)`,62
'transition': `transform ease-in-out 300ms`63
};64
},65
hasPrev() {66
if(this.length === null) {67
return false;68
}69
return this.index > 0;70
},71
hasNext() {72
if(this.length === null) {73
return true;74
}75
return this.index < this.length - this.count - 1;76
}77
},78
template: `79
<div>80
<div class="flex items-center pt-4 sm:pt-0 pb-5">81
<h3 class="flex-1 text-white text-[24px] font-bold">{{title}}</h3>82
<v-button83
icon="chevron-left"84
class="hidden sm:block w-[44px] min-w-[44px] h-[44px]"85
@click="prev()"86
:disabled="!hasPrev"87
></v-button>88
<v-button89
icon="chevron-right"90
class="hidden sm:block w-[44px] min-w-[44px] h-[44px]"91
@click="next()"92
:disabled="!hasNext"93
></v-button>94
</div>95
<div class="relative sm:overflow-x-hidden">96
<ul97
ref="list"98
class="flex overflow-x-auto sm:overflow-x-visible max-w-full snap-x snap-mandatory gap-4 lg:gap-6 scroll-hidden transition-transform"99
:style="transform"100
>101
<li102
:key="item.id"103
v-for="item in items"104
class="snap-start min-w-[calc(33.333%-(1rem/3*2))] sm:min-w-[calc(25%-(1rem/4*3))] md:min-w-[calc(20%-(1rem/5*4))] lg:min-w-[calc(16.666%-(1.5rem/6*5))]"105
>106
<v-station :station="item" type="grid"></v-station>107
</li>108
</ul>109
</div>110
</div>111
`112
}
55
</span>56
</div>57
</div>58
<div v-if="type === 'grid'" class="flex flex-col gap-3 group w-[160px] min-w-[160px]">58
<div v-if="type === 'grid'" class="flex flex-col gap-3 group w-full min-w-full">59
<v-image60
:station="station"61
@click="() => openDetail(station)"
3
export default {4
props: ['id', 'tab'],5
data() {6
return {7
state8
};9
},10
watch: {11
tab: function(value) {12
this.$emit(value === this.id ? 'show' : 'hide');13
}14
},15
template: `11
<div class="flex flex-col gap-6 sm:gap-12 min-w-full overflow-y-auto">16
<div v-if="state.tab === id" class="flex flex-col gap-6 sm:gap-12 min-w-full">17
<slot></slot>18
</div>19
`
3
const TYPES = {};5
export default {6
props: ['text', 'icon', 'title', 'active', 'animation', 'size'],6
props: ['text', 'icon', 'title', 'active', 'animation', 'size', 'disabled'],7
emits: ['click'],8
components: {9
VIcon
12
<button13
@click="$emit('click')"14
:title="title"15
:class="{ 'bg-zinc-900': active }"15
:class="{ 'bg-zinc-900': active, '!bg-inherit pointer-events-none': disabled }"16
class="group min-w-[50px] h-[50px] hover:bg-white rounded-full inline-flex justify-center items-center cursor-pointer transition-colors outline-none"17
>18
<v-icon19
v-if="icon"20
:id="icon"21
:size="size"22
:class="[ active ? 'text-gray-100' : 'text-gray-400', text ? 'group-hover:text-gray-700' : '', animation, text ? '' : 'w-full' ]"22
:class="[ active ? 'text-gray-100' : 'text-gray-400', text ? 'group-hover:text-gray-700' : '', animation, text ? 'min-w-[50px]' : 'w-full', disabled ? '!text-gray-700' : '' ]"23
class="hover:text-gray-800"24
></v-icon>25
<slot v-else></slot>
14
},15
template: `16
<div17
class="ti min-w-[50px] h-full transition-colors relative before:absolute before:top-[50%] before:left-[50%] before:-translate-x-1/2 before:-translate-y-[55%]"17
class="ti h-full transition-colors relative before:absolute before:top-[50%] before:left-[50%] before:-translate-x-1/2 before:-translate-y-[55%]"18
:class="classes"19
:style="styles"20
></div>
115
}116
}117
}118
},119
onTouchStart(event) {120
this.touch = event.changedTouches[0];121
this.target = event.target;122
},123
onTouchEnd(event) {124
const touch = event.changedTouches[0];125
const diff = {126
x: touch.pageX - this.touch.pageX,127
y: touch.pageY - this.touch.pageY128
};129
const angle = Math.atan(diff.x / diff.y) * (180 / Math.PI);130
const index = state.tabs.indexOf(state.tab);131
if(this.$refs.player.open === true || this.$refs.detail.open === true) {132
return;133
}134
if(Math.abs(diff.x) >= SWIPE_THRESHOLD) {135
if(diff.x > 0 && index > 0 && (angle <= -60 || angle >= 60)) {136
state.tab = state.tabs[index - 1];137
}138
if(diff.x < 0 && index < state.tabs.length - 1 && (angle <= -60 || angle >= 60)) {139
state.tab = state.tabs[index + 1];140
}141
}142
}143
},144
computed: {145
styles() {146
const index = state.tabs.indexOf(state.tab);147
const offset = window.innerWidth < 1200148
? `${index * -100}vw`149
: `${index * -1200}px`;150
return {151
'transform': `translate(${offset}, 0)`152
};118
}119
},120
template: `121
<div122
v-if="state.authenticated !== null"158
@touchstart="onTouchStart"159
@touchend="onTouchEnd"160
class="px-4 sm:px-10 max-w-[1200px] mx-auto flex flex-col min-h-[100vh] max-h-[100vh] overflow-hidden"123
class="px-4 sm:px-10 max-w-[1200px] mx-auto flex flex-col min-h-[100vh]"124
>125
<v-auth v-if="!state.authenticated" :state="state"></v-auth>126
<v-menu v-if="state.authenticated" :state="state"></v-menu>164
<div class="flex flex-1 gap-[32px] sm:gap-[5rem] overflow-y-clip transition-transform md:transition-none" :style="styles">127
<div>128
<v-search v-if="state.authenticated" ref="search" :state="state"></v-search>129
<v-favorites v-if="state.authenticated" ref="favorites" :state="state"></v-favorites>130
<v-account v-if="state.authenticated" :state="state"></v-account>
2
import VIcon from '../element/icon.js';3
import VTab from '../component/tab.js';4
import VStation from '../component/station.js';5
import VCarousel from '../component/carousel.js';7
export default {8
props: ['state'],
27
components: {28
VIcon,29
VTab,29
VStation30
VStation,31
VCarousel32
},33
methods: {34
$lang,
88
},89
template: `90
<v-tab id="search" :tab="state.tab">89
<div class="flex flex-col flex-1 gap-6 md:gap-16 pb-8 sm:pb-[100px] pt-2">91
<div class="flex flex-col flex-1 gap-4 md:gap-14 pb-8 sm:pb-[100px] pt-2">92
<div class="flex flex-wrap rounded-md overflow-hidden bg-zinc-900">93
<div class="relative before:absolute before:w-full before:bottom-0 before:border-b md:before:border-none before:border-zinc-800 flex-1">94
<input
145
<v-station :station="station"></v-station>146
</li>147
</ul>146
<div v-else>147
<h3 class="text-white text-[24px] font-bold pb-6 pt-4 sm:pt-0">{{$lang('search.latest')}}</h3>148
<div class="relative">149
<ul class="flex overflow-y-auto max-w-full snap-x snap-mandatory gap-4 pr-3 scroll-hidden">150
<li151
:key="station.id"152
v-for="station in latest"153
class="snap-start"154
>155
<v-station :station="station" type="grid"></v-station>156
</li>157
</ul>158
<div class="absolute right-0 top-0 h-full w-3 bg-gradient-to-l from-black to-transparent"></div>159
</div>160
<h3 class="mt-6 md:mt-16 text-white text-[24px] font-bold pb-6 pt-4 sm:pt-0">{{$lang('search.playtime')}}</h3>161
<div class="relative">162
<ul class="flex overflow-y-auto max-w-full snap-x snap-mandatory gap-4 pr-3 scroll-hidden">163
<li164
:key="station.id"165
v-for="station in playtime"166
class="snap-start"167
>168
<v-station :station="station" type="grid"></v-station>169
</li>170
</ul>171
<div class="absolute right-0 top-0 h-full w-3 bg-gradient-to-l from-black to-transparent"></div>172
</div>148
<div v-else class="flex flex-col gap-4 md:gap-14">149
<v-carousel :title="$lang('search.latest')" :items="latest"></v-carousel>150
<v-carousel :title="$lang('search.playtime')" :items="playtime"></v-carousel>151
</div>152
<div153
v-show="loading"
374
AND station_stats.account_id = {account_id}375
WHERE station_status.is_hidden IS NOT true376
{category}377
LIMIT 8377
LIMIT 10378
"#,379
account_id = account.id,380
category = unwrap_result_or_throw!(category.to_sql(), "cannot parse sql statement!"),