so://phie

verbal

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

blob: 90f47ed89d589741749f4b155625344a36232699 (15795 bytes)[doc][blame][raw]

1import {state} from '../main.js';

2import {http, $lang, $route, duration, utc} from '../utils.js';

3import VButton from '../element/button.js';

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

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

6import VImage from '../element/image.js';

7import VPlayButton from '../element/play-button.js';

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

9

10export default {

11 data() {

12 return {

13 station: null,

14 group: null,

15 open: true,

16 state

17 };

18 },

19 components: {

20 VTab,

21 VButton,

22 VIcon,

23 VImage,

24 VStation,

25 VPlayButton

26 },

27 methods: {

28 $lang,

29 $route,

30 duration,

31 utc,

32 async show(station) {

33 this.open = false;

34 this.station = await http`get::/api/station/${station.id}`();

35 if(this.station === null) {

36 $route('@not-found', { update: false });

37 return;

38 }

39 this.group = null;

40 if(this.station.group_id) {

41 this.group = await http`get::/api/group/${this.station.group_id}`();

42 }

43 this.open = true;

44 },

45 async setLike(is_favorite) {

46 try {

47 await http`${is_favorite ? 'post' : 'delete'}::/api/favorite`(this.station.id);

48 this.station.is_favorite = is_favorite;

49 this.station.likes += is_favorite ? 1 : -1;

50 state.app.$refs.favorites.doFetch();

51 }

52 catch(error) {

53 console.log(error);

54 }

55 },

56 gradient(color) {

57 return `linear-gradient(to bottom, ${color ?? 'transparent'}, transparent)`;

58 },

59 hasGroup() {

60 if(this.group === null) {

61 return false;

62 }

63 return this.group.stations.filter((station) => this.station.id !== station.id).length > 0;

64 },

65 getDescription() {

66 return this.station.description ?? this.group?.group.description;

67 },

68 share() {

69 if('share' in navigator) {

70 navigator.share({

71 url: window.location.href,

72 title: this.station.name

73 });

74 }

75 }

76 },

77 mounted() {

78 const path = window.location.pathname;

79 const match = /^\/station\/(\d+)$/.exec(path);

80 if(match) {

81 const id = match[1];

82 this.show({ id });

83 }

84 },

85 template: `

86 <v-tab id="detail" :tab="state.tab">

87 <div class="z-40">

88 <div

89 ref="modal"

90 class="w-full mx-auto flex flex-col bg-black fixed left-[100vw] top-0 h-[100vh] overflow-y-auto pb-12 sm:pb-[100px] transition-detail detail-active"

91 >

92 <div v-if="open" class="w-full flex flex-col px-4 sm:px-10 max-w-[1200px] mx-auto">

93 <div

94 class="w-full absolute top-0 left-0 h-[40vh] z-[-1]"

95 :style="{'background': gradient(station?.color)}"

96 >

97 </div>

98 <div class="w-full h-[98px] py-6 flex gap-4 justify-between">

99 <v-button

100 icon="chevron-left"

101 @click="$route('/')"

102 ></v-button>

103 <v-button

104 icon="share"

105 @click="share()"

106 ></v-button>

107 </div>

108 <div class="flex flex-col gap-5 md:mt-8">

109 <v-image

110 v-if="station"

111 :station="station"

112 class="w-[96px] h-[96px] min-w-[96px]"

113 ></v-image>

114 <div

115 v-if="station"

116 class="flex flex-col flex-1 min-w-0"

117 >

118 <p

119 :title="station.name"

120 class="text-[24px] md:text-[36px] font-[600] text-gray-100 pb-0 overflow-hidden text-ellipsis whitespace-nowrap"

121 >

122 {{station.name}}

123 </p>

124 <span class="text-md text-gray-400 overflow-hidden flex flex-wrap gap-x-3 gap-y-1 pt-1">

125 <span

126 v-if="group?.group"

127 class="text-gray-400 inline-flex items-center gap-[5px] w-full sm:w-auto"

128 >

129 <p>{{$lang('detail.hosted-by')}} {{group.group.name}}</p>

130 </span>

131 <span

132 v-if="station.country"

133 class="text-gray-400 inline-flex items-center gap-[5px]"

134 >

135 <v-icon

136 id="map-pin"

137 class="w-[18px] h-[18px] !min-w-[18px] inline-flex text-gray-400"

138 size="100%"

139 ></v-icon>

140 <p>{{station.city ? station.city + ', ' : ''}}{{station.state ? station.state + ', ' : ''}}{{station.country}}</p>

141 </span>

142 <span

143 v-if="station.utc !== null && station.utc !== undefined"

144 class="text-gray-400 inline-flex items-center gap-[5px] w-full sm:w-auto"

145 >

146 <v-icon

147 id="clock"

148 class="w-[18px] h-[18px] !min-w-[18px] inline-flex text-gray-400"

149 size="100%"

150 ></v-icon>

151 <p>{{utc(station.utc)}}</p>

152 </span>

153 <span

154 v-if="state.authenticated && station?.playtime && duration(station.playtime ?? 0).length > 0"

155 class="text-gray-400 inline-flex items-center gap-[5px]"

156 >

157 <v-icon

158 id="headphones"

159 class="w-[18px] h-[18px] !min-w-[18px] inline-flex text-gray-400"

160 size="100%"

161 ></v-icon>

162 <p>{{duration(station.playtime ?? 0)}}</p>

163 </span>

164 </span>

165 </div>

166 </div>

167 <div

168 v-if="station"

169 class="flex flex-col gap-6 mt-8"

170 >

171 <div class="flex gap-3">

172 <v-play-button :station="station"></v-play-button>

173 <v-button

174 :icon="station.is_favorite ? 'bookmark-off' : 'bookmark'"

175 :title="$lang(state.authenticated ? (station.is_favorite ? 'global.unlike' : 'global.like') : 'global.requires-auth')"

176 @click="() => setLike(!station.is_favorite)"

177 class="bg-zinc-900 hover:bg-white px-1"

178 :class="{ '!bg-zinc-900': !state.authenticated }"

179 :text="station.likes.toString()"

180 :disabled="!state.authenticated"

181 ></v-button>

182 </div>

183 <p v-if="getDescription()" class="text-md text-gray-400 mt-2" v-html="getDescription()"></p>

184 <p v-else class="text-md text-gray-400">{{$lang('detail.no-description')}}</p>

185 <div v-if="station.tags && station.tags.length > 0" class="flex gap-3 flex-wrap">

186 <span v-for="tag in station.tags" class="cursor-pointer text-md text-white/90 font-medium items-center gap-[5px] bg-zinc-900 hover:bg-zinc-800 rounded-[4px] text-[14px] px-[14px] inline-flex h-[34px] leading-[34px]">{{tag}}</span>

187 </div>

188 <div v-if="station.is_restricted || station.is_broken || station.is_no_track_info" class="flex gap-2 flex-wrap">

189 <span

190 v-if="station.is_restricted"

191 class="text-white/90 items-center gap-[5px] bg-blue-600/70 rounded-[4px] text-[14px] px-[7px] inline-flex h-[24px] leading-[24px]"

192 >

193 <p class="-mt-[1px]">Restricted</p>

194 </span>

195 <span

196 v-if="station.is_broken"

197 class="text-white/90 items-center gap-[5px] bg-red-600/70 rounded-[4px] text-[14px] px-[7px] inline-flex h-[24px] leading-[24px]"

198 >

199 <p class="-mt-[1px]">Broken</p>

200 </span>

201 <span

202 v-if="station.is_no_track_info"

203 class="text-white/90 items-center gap-[5px] bg-green-600/70 rounded-[4px] text-[14px] px-[7px] inline-flex h-[24px] leading-[24px]"

204 >

205 <p class="-mt-[1px]">No track info</p>

206 </span>

207 </div>

208 <div v-if="hasGroup()" class="mt-[32px]">

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

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

211 <li

212 :key="station.id"

213 v-for="group_station in group.stations"

214 v-if="station.id !== group_station.id"

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

216 >

217 <v-station :station="group_station"></v-station>

218 </li>

219 </ul>

220 </div>

221 </div>

222 </div>

223 <div v-else class="w-full flex flex-col px-4 sm:px-10 max-w-[1200px] mx-auto">

224 <div

225 class="w-full absolute top-0 left-0 h-[40vh] z-[-1]"

226 >

227 </div>

228 <div class="w-full h-[98px] py-6 flex gap-4 justify-between">

229 <v-button

230 icon="chevron-left"

231 @click="$route('/')"

232 ></v-button>

233 <v-button

234 icon="share"

235 @click="share()"

236 ></v-button>

237 </div>

238 <div class="flex flex-col gap-5 md:mt-8">

239 <v-image

240 :station="null"

241 class="w-[96px] h-[96px] min-w-[96px]"

242 ></v-image>

243 <div

244 class="flex flex-col flex-1 min-w-0 items-start"

245 >

246 <p

247 class="inline-block text-[24px] md:text-[36px] font-[600] bg-gray-100/30 text-transparent pb-0 overflow-hidden text-ellipsis whitespace-nowrap rounded-[4px] animate-pulse leading-[36px] my-[9px] break-all max-w-full"

248 >

249 012345678901234567890123456789

250 </p>

251 <span class="text-md text-gray-400 overflow-hidden flex flex-wrap gap-x-3 gap-y-1 pt-1">

252 <span

253 class="bg-gray-400/30 text-transparent inline-flex items-center gap-[5px] w-full sm:w-auto rounded-[4px] animate-pulse leading-[16px] my-[4px]"

254 >

255 <p>01234567890123456789</p>

256 </span>

257 <span

258 class="bg-gray-400/30 text-transparent inline-flex items-center gap-[5px] rounded-[4px] animate-pulse leading-[16px] my-[4px]"

259 >

260 <p>012345678901234567890123456789</p>

261 </span>

262 <span

263 class="bg-gray-400/30 text-transparent inline-flex items-center gap-[5px] rounded-[4px] animate-pulse leading-[16px] my-[4px]"

264 >

265 <p>0123456789</p>

266 </span>

267 </span>

268 </div>

269 </div>

270 <div

271 class="flex flex-col gap-6 mt-8"

272 >

273 <div class="flex gap-3">

274 <v-play-button :station="null" class="pointer-events-none"></v-play-button>

275 <v-button

276 icon="bookmark"

277 class="bg-zinc-900 hover:bg-white px-1"

278 :class="{ '!bg-zinc-900': true }"

279 text="0"

280 :disabled="true"

281 ></v-button>

282 </div>

283 <p class="text-md bg-gray-400/30 text-transparent mt-2 break-all rounded-[4px] animate-pulse leading-[16px] my-[4px]">

284 01234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789

285 </p>

286 </div>

287 </div>

288 </div>

289 </div>

290 </v-tab>

291 `

292}