A mobile app for listening to radio stations from around the globe
git clone git://soophie.de/verbal
blob: ceb2b485ed0db3671f9f98983d09221f5028f81a (8926 bytes)[doc][blame][raw]
1
import {$lang, http} from '../utils.js';2
import VIcon from '../element/icon.js';3
import VTab from '../component/tab.js';4
import VStation from '../component/station.js';6
export default {7
props: ['state'],8
data() {9
return {10
query: {11
name: '',12
country: '',13
language: '',14
page: 015
},16
results: [],17
loading: false,18
searching: false,19
more: true,20
countries: [],21
languages: [],22
playtime: null,23
latest: null,24
};25
},26
components: {27
VIcon,28
VTab,29
VStation30
},31
methods: {32
$lang,33
async doSearch() {34
this.results = [];35
if(this.isQueryEmpty()) {36
this.reset();37
return;38
}39
this.loading = true;40
this.more = true;41
this.searching = true;42
this.query.page = 0;43
const result = await http`get::/api/search`(this.query);44
this.loading = false;45
this.results = result;46
},47
async doSearchMore() {48
if(this.loading) return;49
if(!this.more) return;50
this.query.page++;51
this.loading = true;52
const result = await http`get::/api/search`(this.query);53
this.loading = false;54
if(result.length == 0) {55
this.more = false;56
}57
this.results.push(...result);58
},59
async loadCategories() {60
this.playtime = await http`get::/api/category/playtime`();61
this.latest = await http`get::/api/category/latest`();62
},63
async loadFilters() {64
this.countries = await http`get::/api/countries`();65
const languages = await http`get::/api/languages`();66
this.languages = languages.map(language => language.toUpperCase());67
},68
isQueryEmpty() {69
return this.query.name === '' && this.query.country === '' && this.query.language === '';70
},71
reset() {72
this.query = {73
name : '',74
country: '',75
language: '',76
page: 077
};78
this.searching = false;79
this.results = [];80
this.loadCategories();81
}82
},83
mounted() {84
this.loadCategories();85
this.loadFilters();86
},87
template: `88
<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">90
<div class="flex flex-wrap rounded-md overflow-hidden bg-zinc-900">91
<div class="relative before:absolute before:w-full before:bottom-0 before:border-b md:before:border-none before:border-zinc-800 flex-1">92
<input93
v-model="query.name"94
@change="doSearch"95
type="text"96
:placeholder="$lang('search.input.placeholder')"97
class="w-full h-[56px] px-5 text-lg bg-zinc-900 text-white font-medium placeholder:font-normal placeholder:text-gray-500 focus:placeholder:text-gray-600 outline-none"98
spellcheck="false"99
autocomplete="off"100
>101
</div>102
<div class="flex w-full md:w-[300px]">103
<div class="flex relative before:absolute before:h-[36px] before:top-[10px] before:border-l-none md:before:border-l before:border-zinc-800 w-6/12">104
<v-icon105
id="map-pin"106
size="20px"107
class="text-gray-400 select-none pointer-events-none before:left-[24px] min-w-[0px]"108
>109
</v-icon>110
<select111
v-model="query.country"112
@change="doSearch"113
class="w-full h-[56px] px-5 pl-11 text-lg bg-zinc-900 text-white font-medium placeholder:font-normal placeholder:text-gray-500 focus:placeholder:text-gray-600 outline-none cursor-pointer appearance-none"114
>115
<option value="">{{$lang('search.input.all')}}</option>116
<option v-for="country in countries" :value="country">{{country}}</option>117
</select>118
</div>119
<div class="flex relative before:absolute before:h-[36px] before:top-[10px] before:border-l before:border-zinc-800 w-6/12">120
<v-icon121
id="world"122
size="20px"123
class="text-gray-400 select-none pointer-events-none before:left-[24px] min-w-[0px]"124
>125
</v-icon>126
<select127
v-model="query.language"128
@change="doSearch"129
class="w-full h-[56px] px-5 pl-11 text-lg bg-zinc-900 text-white font-medium placeholder:font-normal placeholder:text-gray-500 focus:placeholder:text-gray-600 outline-none cursor-pointer appearance-none"130
>131
<option value="">{{$lang('search.input.all')}}</option>132
<option v-for="language in languages" :value="language">{{language}}</option>133
</select>134
</div>135
</div>136
</div>137
<ul v-if="searching" class="flex flex-col">138
<li139
:key="station.id"140
v-for="station in results"141
class="border-t sm:border-t-2 first:border-none border-zinc-900 py-5 first:pt-0"142
>143
<v-station :station="station"></v-station>144
</li>145
</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>173
</div>174
<div175
v-show="loading"176
class="w-[60px] h-[60px] select-none pointer-events-none mx-auto"177
>178
<v-icon179
id="loader"180
class="text-gray-400 animate-spin"181
style="animation-duration: 2s;"182
size="44px"183
></v-icon>184
</div>185
<div186
v-if="searching && !more && results.length > 0"187
class="text-zinc-400 text-md mx-auto pb-6"188
>189
{{$lang('search.list.end')}}190
</div>191
<div192
v-if="searching && !loading && results.length == 0"193
class="text-zinc-400 text-md mx-auto pb-6"194
>195
{{$lang('search.list.empty')}}196
</div>197
</div>198
</v-tab>199
`200
}