A mobile app for listening to radio stations from around the globe
git clone git://soophie.de/verbal
blob: a44fe5ec733960fe42d3646e18ab2cf99a32cf82 (4690 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
more: true,17
countries: [18
{ name: 'All', value: '' },19
{ name: 'US', value: 'US' },20
{ name: 'GB', value: 'GB' },21
{ name: 'DE', value: 'DE' },22
{ name: 'CA', value: 'CA' }23
],24
languages: [25
{ name: 'All', value: '' },26
{ name: 'EN', value: 'EN' },27
{ name: 'DE', value: 'DE' },28
{ name: 'FR', value: 'FR' },29
{ name: 'ES', value: 'ES' }30
]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.query.page = 0;45
const result = await http`get::/api/search`(this.query);46
this.loading = false;47
this.results = result;48
},49
async doSearchMore() {50
if(this.loading) return;51
if(!this.more) return;52
this.query.page++;53
this.loading = true;54
const result = await http`get::/api/search`(this.query);55
this.loading = false;56
if(result.length == 0) {57
this.more = false;58
}59
this.results.push(...result);60
},61
reset() {62
this.query = {63
name : '',64
page: 065
};66
this.doSearch();67
}68
},69
mounted() {70
this.doSearch();71
},72
template: `73
<v-tab id="search" :tab="state.tab" @show="doSearch">74
<input75
v-model="query.name"76
@keyup.enter="doSearch"77
type="text"78
:placeholder="$lang('search.input.placeholder')"79
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"80
spellcheck="false"81
autocomplete="off"82
>83
<div class="flex gap-5">84
<select85
v-model="query.country"86
@change="doSearch"87
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"88
>89
<option v-for="country in countries" :value="country.value">{{country.name}}</option>90
</select>91
<select92
v-model="query.language"93
@change="doSearch"94
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"95
>96
<option v-for="language in languages" :value="language.value">{{language.name}}</option>97
</select>98
</div>99
<ul class="flex flex-col">100
<li101
:key="station.id"102
v-for="station in results"103
class="border-t sm:border-t-2 first:border-none border-zinc-900 py-5 first:pt-0"104
>105
<v-station :station="station"></v-station>106
</li>107
</ul>108
<div109
v-show="loading"110
class="w-[60px] h-[60px] select-none pointer-events-none mx-auto"111
>112
<v-icon113
id="loader"114
class="text-gray-400 animate-spin"115
style="animation-duration: 2s;"116
size="44px"117
></v-icon>118
</div>119
<div120
v-if="!more && results.length > 0"121
class="text-zinc-400 text-md mx-auto pb-6"122
>123
{{$lang('search.list.end')}}124
</div>125
<div126
v-if="results.length == 0"127
class="text-zinc-400 text-md mx-auto pb-6"128
>129
{{$lang('search.list.empty')}}130
</div>131
</v-tab>132
`133
}