so://phie

verbal

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

blob: 9f7b744e51cc11852efffb9f2b912ce7a9ff0153 (8130 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 this.loading = true;

36 this.more = true;

37 this.searching = true;

38 this.query.page = 0;

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

40 this.loading = false;

41 this.results = result;

42 },

43 async doSearchMore() {

44 if(this.loading) return;

45 if(!this.more) return;

46 this.query.page++;

47 this.loading = true;

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

49 this.loading = false;

50 if(result.length == 0) {

51 this.more = false;

52 }

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

54 },

55 async loadCategories() {

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

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

58 },

59 async loadFilters() {

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

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

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

63 },

64 reset() {

65 this.query = {

66 name : '',

67 page: 0

68 };

69 this.searching = false;

70 this.results = [];

71 this.loadCategories();

72 }

73 },

74 mounted() {

75 this.loadCategories();

76 this.loadFilters();

77 },

78 template: `

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

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

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

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

83 <input

84 v-model="query.name"

85 @change="doSearch"

86 type="text"

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

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

89 spellcheck="false"

90 autocomplete="off"

91 >

92 </div>

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

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

95 <v-icon

96 id="map-pin"

97 size="20px"

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

99 >

100 </v-icon>

101 <select

102 v-model="query.country"

103 @change="doSearch"

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

105 >

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

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

108 </select>

109 </div>

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

111 <v-icon

112 id="world"

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.language"

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="language in languages" :value="language">{{language}}</option>

124 </select>

125 </div>

126 </div>

127 </div>

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

129 <li

130 :key="station.id"

131 v-for="station in results"

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

133 >

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

135 </li>

136 </ul>

137 <div v-else>

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

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

140 <li

141 :key="station.id"

142 v-for="station in latest"

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

144 >

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

146 </li>

147 </ul>

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

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

150 <li

151 :key="station.id"

152 v-for="station in playtime"

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

154 >

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

156 </li>

157 </ul>

158 </div>

159 <div

160 v-show="loading"

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

162 >

163 <v-icon

164 id="loader"

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

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

167 size="44px"

168 ></v-icon>

169 </div>

170 <div

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

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

173 >

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

175 </div>

176 <div

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

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

179 >

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

181 </div>

182 </div>

183 </v-tab>

184 `

185}