so://phie

verbal

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

blob: cd9cf0a608f0c5c96d36885510ffca92837bbac7 (8433 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 playtime: null,

23 latest: null,

24 };

25 },

26 components: {

27 VIcon,

28 VTab,

29 VStation

30 },

31 methods: {

32 $lang,

33 async doSearch() {

34 this.results = [];

35 if(this.isQueryEmpty()) {

36 this.reset();

37 return;

38 }

39 this.loading = true;

40 this.more = true;

41 this.searching = true;

42 this.query.page = 0;

43 const result = await http`get::/api/search`(this.query);

44 this.loading = false;

45 this.results = result;

46 },

47 async doSearchMore() {

48 if(this.loading) return;

49 if(!this.more) return;

50 this.query.page++;

51 this.loading = true;

52 const result = await http`get::/api/search`(this.query);

53 this.loading = false;

54 if(result.length == 0) {

55 this.more = false;

56 }

57 this.results.push(...result);

58 },

59 async loadCategories() {

60 this.playtime = await http`get::/api/category/playtime`();

61 this.latest = await http`get::/api/category/latest`();

62 },

63 async loadFilters() {

64 this.countries = await http`get::/api/countries`();

65 const languages = await http`get::/api/languages`();

66 this.languages = languages.map(language => language.toUpperCase());

67 },

68 isQueryEmpty() {

69 return this.query.name === '' && this.query.country === '' && this.query.language === '';

70 },

71 reset() {

72 this.query = {

73 name : '',

74 country: '',

75 language: '',

76 page: 0

77 };

78 this.searching = false;

79 this.results = [];

80 this.loadCategories();

81 }

82 },

83 mounted() {

84 this.loadCategories();

85 this.loadFilters();

86 },

87 template: `

88 <v-tab id="search" :tab="state.tab">

89 <div class="flex flex-col flex-1 gap-[32px] pb-8 sm:pb-[100px] pt-2">

90 <div class="flex flex-wrap rounded-md overflow-hidden bg-zinc-900">

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

92 <input

93 v-model="query.name"

94 @change="doSearch"

95 type="text"

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

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

98 spellcheck="false"

99 autocomplete="off"

100 >

101 </div>

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

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

104 <v-icon

105 id="map-pin"

106 size="20px"

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

108 >

109 </v-icon>

110 <select

111 v-model="query.country"

112 @change="doSearch"

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

114 >

115 <option value="">{{$lang('search.input.all')}}</option>

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

117 </select>

118 </div>

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

120 <v-icon

121 id="world"

122 size="20px"

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

124 >

125 </v-icon>

126 <select

127 v-model="query.language"

128 @change="doSearch"

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

130 >

131 <option value="">{{$lang('search.input.all')}}</option>

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

133 </select>

134 </div>

135 </div>

136 </div>

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

138 <li

139 :key="station.id"

140 v-for="station in results"

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

142 >

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

144 </li>

145 </ul>

146 <div v-else>

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

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

149 <li

150 :key="station.id"

151 v-for="station in latest"

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

153 >

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

155 </li>

156 </ul>

157 <h3 class="mt-[32px] text-white text-[24px] font-bold pb-6 pt-4 sm:pt-0">{{$lang('search.playtime')}}</h3>

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

159 <li

160 :key="station.id"

161 v-for="station in playtime"

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

163 >

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

165 </li>

166 </ul>

167 </div>

168 <div

169 v-show="loading"

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

171 >

172 <v-icon

173 id="loader"

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

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

176 size="44px"

177 ></v-icon>

178 </div>

179 <div

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

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

182 >

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

184 </div>

185 <div

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

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

188 >

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

190 </div>

191 </div>

192 </v-tab>

193 `

194}