A mobile app for listening to radio stations from around the globe
git clone git://soophie.de/verbal
blob: 18c6588d22990212661fdd6950d56dea2fd81c45 (5858 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.loadRecommended();86
}87
},88
mounted() {89
this.loadRecommended();90
},91
template: `92
<v-tab id="search" :tab="state.tab">93
<input94
v-model="query.name"95
@keyup.enter="doSearch"96
type="text"97
:placeholder="$lang('search.input.placeholder')"98
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"99
spellcheck="false"100
autocomplete="off"101
>102
<div class="flex gap-5">103
<select104
v-model="query.country"105
@change="doSearch"106
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"107
>108
<option v-for="country in countries" :value="country.value">{{country.name}}</option>109
</select>110
<select111
v-model="query.language"112
@change="doSearch"113
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"114
>115
<option v-for="language in languages" :value="language.value">{{language.name}}</option>116
</select>117
</div>118
<ul v-if="searching" class="flex flex-col">119
<li120
:key="station.id"121
v-for="station in results"122
class="border-t sm:border-t-2 first:border-none border-zinc-900 py-5 first:pt-0"123
>124
<v-station :station="station"></v-station>125
</li>126
</ul>127
<div v-else>128
<h3 class="text-white text-[24px] font-bold pb-8 pt-4 sm:pt-0">{{$lang('search.recommended')}}</h3>129
<ul class="flex flex-col">130
<li131
:key="station.id"132
v-for="station in recommended"133
class="border-t sm:border-t-2 first:border-none border-zinc-900 py-5 first:pt-0"134
>135
<v-station :station="station"></v-station>136
</li>137
</ul>138
</div>139
<div140
v-show="loading"141
class="w-[60px] h-[60px] select-none pointer-events-none mx-auto"142
>143
<v-icon144
id="loader"145
class="text-gray-400 animate-spin"146
style="animation-duration: 2s;"147
size="44px"148
></v-icon>149
</div>150
<div151
v-if="searching && !more && results.length > 0"152
class="text-zinc-400 text-md mx-auto pb-6"153
>154
{{$lang('search.list.end')}}155
</div>156
<div157
v-if="searching && results.length == 0"158
class="text-zinc-400 text-md mx-auto pb-6"159
>160
{{$lang('search.list.empty')}}161
</div>162
</v-tab>163
`164
}