so://phie

verbal

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

blob: 3da226d0b96b31875baa0e2dbe8119307292a46d (11003 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 VPlayButton from '../element/play-button.js';

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

8

9export default {

10 data() {

11 return {

12 station: null,

13 group: null,

14 open: false

15 };

16 },

17 components: {

18 VButton,

19 VIcon,

20 VImage,

21 VStation,

22 VPlayButton

23 },

24 methods: {

25 $lang,

26 duration,

27 async show(station) {

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

29 this.group = null;

30 if(this.station.group_id) {

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

32 }

33 this.open = true;

34 },

35 async setLike(is_favorite) {

36 try {

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

38 this.station.is_favorite = is_favorite;

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

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

41 }

42 catch(error) {

43 console.log(error);

44 }

45 },

46 onTouchStart(event) {

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

48 this.target = event.target;

49 },

50 onTouchEnd(event) {

51 const touch = event.changedTouches[0];

52 const diff = {

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

54 y: touch.pageY - this.touch.pageY

55 };

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

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

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

59 return;

60 }

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

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

63 this.open = false;

64 }

65 }

66 },

67 gradient(color) {

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

69 },

70 hasGroup() {

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

72 return false;

73 }

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

75 },

76 getDescription() {

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

78 }

79 },

80 created() {

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

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

83 },

84 onUnmounted() {

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

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

87 },

88 computed: {

89 opacity() {

90 return {

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

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

93 };

94 }

95 },

96 template: `

97 <div class="z-40">

98 <div

99 @click="open = false"

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

101 :style="opacity"

102 >

103 </div>

104 <div

105 ref="modal"

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

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

108 >

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

110 <div

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

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

113 >

114 </div>

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

116 <v-button

117 icon="chevron-left"

118 @click="open = false"

119 ></v-button>

120 <v-button

121 icon="share"

122 ></v-button>

123 </div>

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

125 <v-image

126 v-if="station"

127 :station="station"

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

129 ></v-image>

130 <div

131 v-if="station"

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

133 >

134 <p

135 :title="station.name"

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

137 >

138 {{station.name}}

139 </p>

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

141 <span

142 v-if="group?.group"

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

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

145 >

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

147 </span>

148 <span

149 v-if="station.country"

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

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

152 >

153 <v-icon

154 id="map-pin"

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

156 size="100%"

157 ></v-icon>

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

159 </span>

160 <span

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

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

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

164 >

165 <v-icon

166 id="clock"

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

168 size="100%"

169 ></v-icon>

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

171 </span>

172 </span>

173 </div>

174 </div>

175 <div

176 v-if="station"

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

178 >

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

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

181 </div>

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

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

184 <v-button

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

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

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

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

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

190 ></v-button>

191 </div>

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

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

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

195 <span

196 v-if="station.is_restricted"

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

198 >

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

200 </span>

201 <span

202 v-if="station.is_broken"

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

204 >

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

206 </span>

207 <span

208 v-if="station.is_no_track_info"

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

210 >

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

212 </span>

213 </div>

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

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

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

217 <li

218 :key="station.id"

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

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

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

222 >

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

224 </li>

225 </ul>

226 </div>

227 </div>

228 </div>

229 </div>

230 </div>

231 `

232}