A mobile app for listening to radio stations from around the globe
git clone git://soophie.de/verbal
blob: 089c79abdc194eb07b8d3318283485ad81911d6b (7216 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 rounded-md overflow-hidden bg-zinc-900">89
<div class="relative before:absolute before:w-full before:bottom-0 before:border-b md:before:border-none before:border-zinc-800 flex-1">90
<input91
v-model="query.name"92
@change="doSearch"93
type="text"94
:placeholder="$lang('search.input.placeholder')"95
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"96
spellcheck="false"97
autocomplete="off"98
>99
</div>100
<div class="flex w-full md:w-[300px]">101
<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">102
<v-icon103
id="map-pin"104
size="20px"105
class="text-gray-400 select-none pointer-events-none before:left-[24px] min-w-[0px]"106
>107
</v-icon>108
<select109
v-model="query.country"110
@change="doSearch"111
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"112
>113
<option value="" selected>All</option>114
<option v-for="country in countries" :value="country">{{country}}</option>115
</select>116
</div>117
<div class="flex relative before:absolute before:h-[36px] before:top-[10px] before:border-l before:border-zinc-800 w-6/12">118
<v-icon119
id="world"120
size="20px"121
class="text-gray-400 select-none pointer-events-none before:left-[24px] min-w-[0px]"122
>123
</v-icon>124
<select125
v-model="query.language"126
@change="doSearch"127
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"128
>129
<option value="">All</option>130
<option v-for="language in languages" :value="language">{{language}}</option>131
</select>132
</div>133
</div>134
</div>135
<ul v-if="searching" class="flex flex-col">136
<li137
:key="station.id"138
v-for="station in results"139
class="border-t sm:border-t-2 first:border-none border-zinc-900 py-5 first:pt-0"140
>141
<v-station :station="station"></v-station>142
</li>143
</ul>144
<div v-else>145
<h3 class="text-white text-[24px] font-bold pb-8 pt-4 sm:pt-0">{{$lang('search.recommended')}}</h3>146
<ul class="flex flex-col">147
<li148
:key="station.id"149
v-for="station in recommended"150
class="border-t sm:border-t-2 first:border-none border-zinc-900 py-4 first:pt-0"151
>152
<v-station :station="station"></v-station>153
</li>154
</ul>155
</div>156
<div157
v-show="loading"158
class="w-[60px] h-[60px] select-none pointer-events-none mx-auto"159
>160
<v-icon161
id="loader"162
class="text-gray-400 animate-spin"163
style="animation-duration: 2s;"164
size="44px"165
></v-icon>166
</div>167
<div168
v-if="searching && !more && results.length > 0"169
class="text-zinc-400 text-md mx-auto pb-6"170
>171
{{$lang('search.list.end')}}172
</div>173
<div174
v-if="searching && !loading && results.length == 0"175
class="text-zinc-400 text-md mx-auto pb-6"176
>177
{{$lang('search.list.empty')}}178
</div>179
</v-tab>180
`181
}