A mobile app for listening to radio stations from around the globe
git clone git://soophie.de/verbal
blob: de982ca73392aad32543d7ccce32cfd48047863f (5998 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
this.countries = await http`get::/api/countries`();69
const languages = await http`get::/api/languages`();70
this.languages = languages.map(language => language.toUpperCase());71
},72
reset() {73
this.query = {74
name : '',75
page: 076
};77
this.searching = false;78
this.results = [];79
this.loadRecommended();80
}81
},82
mounted() {83
this.loadRecommended();84
this.loadFilters();85
},86
template: `87
<v-tab id="search" :tab="state.tab">88
<div class="flex flex-wrap gap-4">89
<input90
v-model="query.name"91
@change="doSearch"92
type="text"93
:placeholder="$lang('search.input.placeholder')"94
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"95
spellcheck="false"96
autocomplete="off"97
>98
<div class="flex gap-4 w-full md:w-[300px]">99
<select100
v-model="query.country"101
@change="doSearch"102
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"103
>104
<option value="" selected>All</option>105
<option v-for="country in countries" :value="country">{{country}}</option>106
</select>107
<select108
v-model="query.language"109
@change="doSearch"110
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"111
>112
<option value="">All</option>113
<option v-for="language in languages" :value="language">{{language}}</option>114
</select>115
</div>116
</div>117
<ul v-if="searching" class="flex flex-col">118
<li119
:key="station.id"120
v-for="station in results"121
class="border-t sm:border-t-2 first:border-none border-zinc-900 py-5 first:pt-0"122
>123
<v-station :station="station"></v-station>124
</li>125
</ul>126
<div v-else>127
<h3 class="text-white text-[24px] font-bold pb-8 pt-4 sm:pt-0">{{$lang('search.recommended')}}</h3>128
<ul class="flex flex-col">129
<li130
:key="station.id"131
v-for="station in recommended"132
class="border-t sm:border-t-2 first:border-none border-zinc-900 py-4 first:pt-0"133
>134
<v-station :station="station"></v-station>135
</li>136
</ul>137
</div>138
<div139
v-show="loading"140
class="w-[60px] h-[60px] select-none pointer-events-none mx-auto"141
>142
<v-icon143
id="loader"144
class="text-gray-400 animate-spin"145
style="animation-duration: 2s;"146
size="44px"147
></v-icon>148
</div>149
<div150
v-if="searching && !more && results.length > 0"151
class="text-zinc-400 text-md mx-auto pb-6"152
>153
{{$lang('search.list.end')}}154
</div>155
<div156
v-if="searching && !loading && results.length == 0"157
class="text-zinc-400 text-md mx-auto pb-6"158
>159
{{$lang('search.list.empty')}}160
</div>161
</v-tab>162
`163
}