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