so://phie

verbal

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

blob: ec96ea361c99d2486d6e5b2bbe24f750cc4713c7 (7619 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 };

26 },

27 components: {

28 VIcon,

29 VTab,

30 VStation,

31 VCarousel

32 },

33 methods: {

34 $lang,

35 async doSearch() {

36 this.results = [];

37 if(this.isQueryEmpty()) {

38 this.reset();

39 return;

40 }

41 this.loading = true;

42 this.more = true;

43 this.searching = 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 async loadCategories() {

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

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

64 },

65 async loadFilters() {

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

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

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

69 },

70 isQueryEmpty() {

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

72 },

73 reset() {

74 this.query = {

75 name : '',

76 country: '',

77 language: '',

78 page: 0

79 };

80 this.searching = false;

81 this.results = [];

82 this.loadCategories();

83 }

84 },

85 mounted() {

86 this.loadCategories();

87 this.loadFilters();

88 },

89 template: `

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

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

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

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

94 <input

95 v-model="query.name"

96 @change="doSearch"

97 type="text"

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

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

100 spellcheck="false"

101 autocomplete="off"

102 >

103 </div>

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

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

106 <v-icon

107 id="map-pin"

108 size="20px"

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

110 >

111 </v-icon>

112 <select

113 v-model="query.country"

114 @change="doSearch"

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

116 >

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

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

119 </select>

120 </div>

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

122 <v-icon

123 id="world"

124 size="20px"

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

126 >

127 </v-icon>

128 <select

129 v-model="query.language"

130 @change="doSearch"

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

132 >

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

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

135 </select>

136 </div>

137 </div>

138 </div>

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

140 <li

141 :key="station.id"

142 v-for="station in results"

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

144 >

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

146 </li>

147 </ul>

148 <div v-else class="flex flex-col gap-4 md:gap-14">

149 <v-carousel :title="$lang('search.latest')" :items="latest"></v-carousel>

150 <v-carousel :title="$lang('search.playtime')" :items="playtime"></v-carousel>

151 </div>

152 <div

153 v-show="loading"

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

155 >

156 <v-icon

157 id="loader"

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

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

160 size="44px"

161 ></v-icon>

162 </div>

163 <div

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

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

166 >

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

168 </div>

169 <div

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

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

172 >

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

174 </div>

175 </div>

176 </v-tab>

177 `

178}