so://phie

verbal

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

blob: 339927ca6f627e2c447a85b53efab2ec84f0b33e (11309 bytes)[doc][blame][raw]

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

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

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

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

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

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

7

8export default {

9 data() {

10 return {

11 station: null,

12 group: null,

13 open: false

14 };

15 },

16 components: {

17 VButton,

18 VIcon,

19 VImage,

20 VStation

21 },

22 methods: {

23 $lang,

24 duration,

25 async load(stationId) {

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

27 this.group = null;

28 if(this.station.group_id) {

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

30 }

31 this.open = true;

32 },

33 async setLike(is_favorite) {

34 try {

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

36 this.station.is_favorite = is_favorite;

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

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

39 }

40 catch(error) {

41 console.log(error);

42 }

43 },

44 setStation(station) {

45 state.station = station;

46 state.app.$refs.player.open = true;

47 },

48 onTouchStart(event) {

49 this.touch = event.changedTouches[0];

50 this.target = event.target;

51 },

52 onTouchEnd(event) {

53 const touch = event.changedTouches[0];

54 const diff = {

55 x: touch.pageX - this.touch.pageX,

56 y: touch.pageY - this.touch.pageY

57 };

58 const angle = Math.atan(diff.x / diff.y) * (180 / Math.PI);

59 const index = state.tabs.indexOf(state.tab);

60 if(state.app.$refs.player.open) {

61 return;

62 }

63 if(Math.abs(diff.x) >= SWIPE_THRESHOLD) {

64 if(this.open && diff.x > 0 && (angle <= -60 || angle >= 60)) {

65 this.open = false;

66 }

67 }

68 },

69 gradient(color) {

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

71 },

72 hasGroup() {

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

74 return false;

75 }

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

77 },

78 getDescription() {

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

80 }

81 },

82 created() {

83 document.body.addEventListener('touchstart', this.onTouchStart);

84 document.body.addEventListener('touchend', this.onTouchEnd);

85 },

86 onUnmounted() {

87 document.body.removeEventListener('touchstart', this.onTouchStart);

88 document.body.removeEventListener('touchend', this.onTouchEnd);

89 },

90 computed: {

91 opacity() {

92 return {

93 'opacity': `${this.open === true ? 1 : 0}`,

94 'pointer-events': `${this.open === true ? 'all' : 'none'}`

95 };

96 }

97 },

98 template: `

99 <div class="z-40">

100 <div

101 @click="open = false"

102 class="fixed top-0 bottom-0 left-0 right-0 bg-black/60 transition-detail"

103 :style="opacity"

104 >

105 </div>

106 <div

107 ref="modal"

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

109 :class="{ 'detail-active': open }"

110 >

111 <div class="w-full flex flex-col max-w-[1200px] mx-auto">

112 <div

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

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

115 >

116 </div>

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

118 <v-button

119 icon="chevron-left"

120 @click="open = false"

121 ></v-button>

122 <v-button

123 icon="share"

124 ></v-button>

125 </div>

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

127 <v-image

128 v-if="station"

129 :station="station"

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

131 ></v-image>

132 <div

133 v-if="station"

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

135 >

136 <p

137 :title="station.name"

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

139 >

140 {{station.name}}

141 </p>

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

143 <span

144 v-if="group?.group"

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

146 :title="$lang('global.country')"

147 >

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

149 </span>

150 <span

151 v-if="station.country"

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

153 :title="$lang('global.country')"

154 >

155 <v-icon

156 id="map-pin"

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

158 size="100%"

159 ></v-icon>

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

161 </span>

162 <span

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

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

165 :title="$lang('detail.playtime')"

166 >

167 <v-icon

168 id="clock"

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

170 size="100%"

171 ></v-icon>

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

173 </span>

174 </span>

175 </div>

176 </div>

177 <div

178 v-if="station"

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

180 >

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

182 <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>

183 </div>

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

185 <v-button

186 icon="player-play"

187 @click="() => setStation(station)"

188 :text="$lang('global.listen')"

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

190 ></v-button>

191 <v-button

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

193 :title="$lang(station.is_favorite ? 'global.unlike' : 'global.like')"

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

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

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

197 ></v-button>

198 </div>

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

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

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

202 <span

203 v-if="station.is_restricted"

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

205 >

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

207 </span>

208 <span

209 v-if="station.is_broken"

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

211 >

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

213 </span>

214 <span

215 v-if="station.is_no_track_info"

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

217 >

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

219 </span>

220 </div>

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

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

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

224 <li

225 :key="station.id"

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

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

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

229 >

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

231 </li>

232 </ul>

233 </div>

234 </div>

235 </div>

236 </div>

237 </div>

238 `

239}