so://phie

verbal

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

blob: 10461e7d412e84dcc8f225c82cf735c307508f28 (8032 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';

5import VCarousel from '../component/carousel.js';

6

7export default {

8 props: ['state'],

9 data() {

10 return {

11 query: {

12 name: '',

13 country: '',

14 language: '',

15 page: 0

16 },

17 results: [],

18 loading: false,

19 searching: false,

20 more: true,

21 countries: [],

22 languages: [],

23 playtime: null,

24 latest: null,

25 favorites: null

26 };

27 },

28 components: {

29 VIcon,

30 VTab,

31 VStation,

32 VCarousel

33 },

34 methods: {

35 $lang,

36 async doSearch() {

37 this.results = [];

38 if(this.isQueryEmpty()) {

39 this.reset();

40 return;

41 }

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 loadCategories() {

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

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

65 let favorites = await http`get::/api/favorite`();

66 favorites = favorites.sort(() => Math.random() - 0.5);

67 favorites.length = 10;

68 this.favorites = favorites;

69 },

70 async loadFilters() {

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

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

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

74 },

75 isQueryEmpty() {

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

77 },

78 reset() {

79 this.query = {

80 name : '',

81 country: '',

82 language: '',

83 page: 0

84 };

85 this.searching = false;

86 this.results = [];

87 this.loadCategories();

88 }

89 },

90 mounted() {

91 this.loadCategories();

92 this.loadFilters();

93 },

94 template: `

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

96 <div class="flex flex-col flex-1 gap-4 md:gap-14 pb-8 sm:pb-[100px] pt-2">

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

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

99 <input

100 v-model="query.name"

101 @change="doSearch"

102 type="text"

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

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

105 spellcheck="false"

106 autocomplete="off"

107 >

108 </div>

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

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

111 <v-icon

112 id="map-pin"

113 size="20px"

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

115 >

116 </v-icon>

117 <select

118 v-model="query.country"

119 @change="doSearch"

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

121 >

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

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

124 </select>

125 </div>

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

127 <v-icon

128 id="world"

129 size="20px"

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

131 >

132 </v-icon>

133 <select

134 v-model="query.language"

135 @change="doSearch"

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

137 >

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

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

140 </select>

141 </div>

142 </div>

143 </div>

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

145 <li

146 :key="station.id"

147 v-for="station in results"

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

149 >

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

151 </li>

152 </ul>

153 <div v-else class="flex flex-col gap-3 md:gap-10">

154 <v-carousel v-if="state.authenticated" :title="$lang('search.latest')" :items="latest"></v-carousel>

155 <v-carousel v-if="state.authenticated" :title="$lang('search.playtime')" :items="playtime"></v-carousel>

156 <v-carousel v-if="state.authenticated" :title="$lang('search.favorites')" :items="favorites"></v-carousel>

157 </div>

158 <div

159 v-show="loading"

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

161 >

162 <v-icon

163 id="loader"

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

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

166 size="44px"

167 ></v-icon>

168 </div>

169 <div

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

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

172 >

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

174 </div>

175 <div

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

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

178 >

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

180 </div>

181 </div>

182 </v-tab>

183 `

184}