so://phie

verbal

A mobile app for listening to radio stations from around the globe
git clone git://soophie.de/verbal

blob: 2bdf1b495332b5c76ccd5fc2cd80443cbdd8a0d1 (7369 bytes)[doc][blame][raw]

1import {$lang, http} from '../utils.js';

2import VIcon from '../element/icon.js';

3import VTab from '../component/tab.js';

4import VStation from '../component/station.js';

5

6export default {

7 props: ['state'],

8 data() {

9 return {

10 query: {

11 name: '',

12 country: '',

13 language: '',

14 page: 0

15 },

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 30615

30 ]

31 };

32 },

33 components: {

34 VIcon,

35 VTab,

36 VStation

37 },

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: 0

81 };

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 rounded-md overflow-hidden bg-zinc-900">

94 <div class="relative before:absolute before:w-full before:bottom-0 before:border-b md:before:border-none before:border-zinc-800 flex-1">

95 <input

96 v-model="query.name"

97 @change="doSearch"

98 type="text"

99 :placeholder="$lang('search.input.placeholder')"

100 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"

101 spellcheck="false"

102 autocomplete="off"

103 >

104 </div>

105 <div class="flex w-full md:w-[300px]">

106 <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">

107 <v-icon

108 id="map-pin"

109 size="20px"

110 class="text-gray-400 select-none pointer-events-none before:left-[24px] min-w-[0px]"

111 >

112 </v-icon>

113 <select

114 v-model="query.country"

115 @change="doSearch"

116 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"

117 >

118 <option value="" selected>All</option>

119 <option v-for="country in countries" :value="country">{{country}}</option>

120 </select>

121 </div>

122 <div class="flex relative before:absolute before:h-[36px] before:top-[10px] before:border-l before:border-zinc-800 w-6/12">

123 <v-icon

124 id="world"

125 size="20px"

126 class="text-gray-400 select-none pointer-events-none before:left-[24px] min-w-[0px]"

127 >

128 </v-icon>

129 <select

130 v-model="query.language"

131 @change="doSearch"

132 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"

133 >

134 <option value="">All</option>

135 <option v-for="language in languages" :value="language">{{language}}</option>

136 </select>

137 </div>

138 </div>

139 </div>

140 <ul v-if="searching" class="flex flex-col">

141 <li

142 :key="station.id"

143 v-for="station in results"

144 class="border-t sm:border-t-2 first:border-none border-zinc-900 py-5 first:pt-0"

145 >

146 <v-station :station="station"></v-station>

147 </li>

148 </ul>

149 <div v-else>

150 <h3 class="text-white text-[24px] font-bold pb-8 pt-4 sm:pt-0">{{$lang('search.recommended')}}</h3>

151 <ul class="flex flex-col">

152 <li

153 :key="station.id"

154 v-for="station in recommended"

155 class="border-t sm:border-t-2 first:border-none border-zinc-900 py-4 first:pt-0"

156 >

157 <v-station :station="station"></v-station>

158 </li>

159 </ul>

160 </div>

161 <div

162 v-show="loading"

163 class="w-[60px] h-[60px] select-none pointer-events-none mx-auto"

164 >

165 <v-icon

166 id="loader"

167 class="text-gray-400 animate-spin"

168 style="animation-duration: 2s;"

169 size="44px"

170 ></v-icon>

171 </div>

172 <div

173 v-if="searching && !more && results.length > 0"

174 class="text-zinc-400 text-md mx-auto pb-6"

175 >

176 {{$lang('search.list.end')}}

177 </div>

178 <div

179 v-if="searching && !loading && results.length == 0"

180 class="text-zinc-400 text-md mx-auto pb-6"

181 >

182 {{$lang('search.list.empty')}}

183 </div>

184 </v-tab>

185 `

186}