A mobile app for listening to radio stations from around the globe
git clone git://soophie.de/verbal
blob: 245b6278975180c7ae3a300b6a4fa7b8f48d249b (5935 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
page: 013
},14
results: [],15
loading: false,16
searching: false,17
more: true,18
countries: [19
{ name: 'All', value: '' },20
{ name: 'US', value: 'US' },21
{ name: 'GB', value: 'GB' },22
{ name: 'DE', value: 'DE' },23
{ name: 'CA', value: 'CA' },24
{ name: 'JP', value: 'JP' }25
],26
languages: [27
{ name: 'All', value: '' },28
{ name: 'EN', value: 'EN' },29
{ name: 'DE', value: 'DE' },30
{ name: 'FR', value: 'FR' },31
{ name: 'ES', value: 'ES' }32
],33
recommended: [],34
popular: [35
45761,36
44366,37
37156,38
33977,39
56254,40
3061541
]42
};43
},44
components: {45
VIcon,46
VTab,47
VStation48
},49
methods: {50
$lang,51
async doSearch() {52
this.results = [];53
this.loading = true;54
this.more = true;55
this.searching = true;56
this.query.page = 0;57
const result = await http`get::/api/search`(this.query);58
this.loading = false;59
this.results = result;60
},61
async doSearchMore() {62
if(this.loading) return;63
if(!this.more) return;64
this.query.page++;65
this.loading = true;66
const result = await http`get::/api/search`(this.query);67
this.loading = false;68
if(result.length == 0) {69
this.more = false;70
}71
this.results.push(...result);72
},73
async loadRecommended() {74
for(const id of this.popular) {75
this.recommended.push(await http`get::/api/station`({ id }));76
}77
},78
reset() {79
this.query = {80
name : '',81
page: 082
};83
this.searching = false;84
this.results = [];85
// this.doSearch();86
this.loadRecommended();87
}88
},89
mounted() {90
// this.doSearch();91
this.loadRecommended();92
},93
template: `94
<v-tab id="search" :tab="state.tab" @show="doSearch">95
<input96
v-model="query.name"97
@keyup.enter="doSearch"98
type="text"99
:placeholder="$lang('search.input.placeholder')"100
class="w-full h-[56px] px-5 text-lg rounded-lg bg-zinc-900 text-white font-medium placeholder:font-normal placeholder:text-gray-500 focus:placeholder:text-gray-600 outline-none"101
spellcheck="false"102
autocomplete="off"103
>104
<div class="flex gap-5">105
<select106
v-model="query.country"107
@change="doSearch"108
class="w-full h-[56px] px-5 text-lg rounded-lg bg-zinc-900 text-white font-medium placeholder:font-normal placeholder:text-gray-500 focus:placeholder:text-gray-600 outline-none cursor-pointer"109
>110
<option v-for="country in countries" :value="country.value">{{country.name}}</option>111
</select>112
<select113
v-model="query.language"114
@change="doSearch"115
class="w-full h-[56px] px-5 text-lg rounded-lg bg-zinc-900 text-white font-medium placeholder:font-normal placeholder:text-gray-500 focus:placeholder:text-gray-600 outline-none cursor-pointer"116
>117
<option v-for="language in languages" :value="language.value">{{language.name}}</option>118
</select>119
</div>120
<ul v-if="searching" class="flex flex-col">121
<li122
:key="station.id"123
v-for="station in results"124
class="border-t sm:border-t-2 first:border-none border-zinc-900 py-5 first:pt-0"125
>126
<v-station :station="station"></v-station>127
</li>128
</ul>129
<div v-else>130
<h3 class="text-white text-[24px] font-bold pb-8 pt-4 sm:pt-0">{{$lang('search.recommended')}}</h3>131
<ul class="flex flex-col">132
<li133
:key="station.id"134
v-for="station in recommended"135
class="border-t sm:border-t-2 first:border-none border-zinc-900 py-5 first:pt-0"136
>137
<v-station :station="station"></v-station>138
</li>139
</ul>140
</div>141
<div142
v-show="loading"143
class="w-[60px] h-[60px] select-none pointer-events-none mx-auto"144
>145
<v-icon146
id="loader"147
class="text-gray-400 animate-spin"148
style="animation-duration: 2s;"149
size="44px"150
></v-icon>151
</div>152
<div153
v-if="searching && !more && results.length > 0"154
class="text-zinc-400 text-md mx-auto pb-6"155
>156
{{$lang('search.list.end')}}157
</div>158
<div159
v-if="searching && results.length == 0"160
class="text-zinc-400 text-md mx-auto pb-6"161
>162
{{$lang('search.list.empty')}}163
</div>164
</v-tab>165
`166
}