A mobile app for listening to radio stations from around the globe
git clone git://soophie.de/verbal
blob: 94f13e0aa067f4533f065bde25531b795c92e1cd (6151 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
recommended: [],23
popular: [24
45761,25
44366,26
37156,27
33977,28
56254,29
3061530
]31
};32
},33
components: {34
VIcon,35
VTab,36
VStation37
},38
methods: {39
$lang,40
async doSearch() {41
this.results = [];42
this.loading = true;43
this.more = true;44
this.searching = true;45
this.query.page = 0;46
const result = await http`get::/api/search`(this.query);47
this.loading = false;48
this.results = result;49
},50
async doSearchMore() {51
if(this.loading) return;52
if(!this.more) return;53
this.query.page++;54
this.loading = true;55
const result = await http`get::/api/search`(this.query);56
this.loading = false;57
if(result.length == 0) {58
this.more = false;59
}60
this.results.push(...result);61
},62
async loadRecommended() {63
for(const id of this.popular) {64
this.recommended.push(await http`get::/api/station`({ id }));65
}66
},67
async loadFilters() {68
const countries = await http`get::/api/countries`();69
for(const {country} of countries) {70
this.countries.push(country);71
}72
const languages = await http`get::/api/languages`();73
for(const {language} of languages) {74
this.languages.push(language.toUpperCase());75
}76
},77
reset() {78
this.query = {79
name : '',80
page: 081
};82
this.searching = false;83
this.results = [];84
this.loadRecommended();85
}86
},87
mounted() {88
this.loadRecommended();89
this.loadFilters();90
},91
template: `92
<v-tab id="search" :tab="state.tab">93
<div class="flex flex-wrap gap-4">94
<input95
v-model="query.name"96
@change="doSearch"97
type="text"98
:placeholder="$lang('search.input.placeholder')"99
class="flex-1 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"100
spellcheck="false"101
autocomplete="off"102
>103
<div class="flex gap-4 w-full md:w-[300px]">104
<select105
v-model="query.country"106
@change="doSearch"107
class="w-6/12 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 appearance-none"108
>109
<option value="" selected>All</option>110
<option v-for="country in countries" :value="country">{{country}}</option>111
</select>112
<select113
v-model="query.language"114
@change="doSearch"115
class="w-6/12 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 appearance-none"116
>117
<option value="">All</option>118
<option v-for="language in languages" :value="language">{{language}}</option>119
</select>120
</div>121
</div>122
<ul v-if="searching" class="flex flex-col">123
<li124
:key="station.id"125
v-for="station in results"126
class="border-t sm:border-t-2 first:border-none border-zinc-900 py-5 first:pt-0"127
>128
<v-station :station="station"></v-station>129
</li>130
</ul>131
<div v-else>132
<h3 class="text-white text-[24px] font-bold pb-8 pt-4 sm:pt-0">{{$lang('search.recommended')}}</h3>133
<ul class="flex flex-col">134
<li135
:key="station.id"136
v-for="station in recommended"137
class="border-t sm:border-t-2 first:border-none border-zinc-900 py-4 first:pt-0"138
>139
<v-station :station="station"></v-station>140
</li>141
</ul>142
</div>143
<div144
v-show="loading"145
class="w-[60px] h-[60px] select-none pointer-events-none mx-auto"146
>147
<v-icon148
id="loader"149
class="text-gray-400 animate-spin"150
style="animation-duration: 2s;"151
size="44px"152
></v-icon>153
</div>154
<div155
v-if="searching && !more && results.length > 0"156
class="text-zinc-400 text-md mx-auto pb-6"157
>158
{{$lang('search.list.end')}}159
</div>160
<div161
v-if="searching && !loading && results.length == 0"162
class="text-zinc-400 text-md mx-auto pb-6"163
>164
{{$lang('search.list.empty')}}165
</div>166
</v-tab>167
`168
}