so://phie

verbal

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

blob: 357f9b00966911300a0430e1323cacf6140bb989 (9330 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';

6

7export default {

8 data() {

9 return {

10 station: null,

11 open: false

12 };

13 },

14 components: {

15 VButton,

16 VIcon,

17 VImage

18 },

19 methods: {

20 $lang,

21 duration,

22 async load(stationId) {

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

24 this.open = true;

25 },

26 async setLike(is_favorite) {

27 try {

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

29 this.station.is_favorite = is_favorite;

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

31 }

32 catch(error) {

33 console.log(error);

34 }

35 },

36 setStation(station) {

37 state.station = station;

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

39 },

40 onTouchStart(event) {

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

42 this.target = event.target;

43 },

44 onTouchEnd(event) {

45 const touch = event.changedTouches[0];

46 const diff = {

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

48 y: touch.pageY - this.touch.pageY

49 };

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

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

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

53 return;

54 }

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

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

57 this.open = false;

58 }

59 }

60 },

61 gradient(color) {

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

63 }

64 },

65 created() {

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

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

68 },

69 onUnmounted() {

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

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

72 },

73 computed: {

74 opacity() {

75 return {

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

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

78 };

79 }

80 },

81 template: `

82 <div class="z-40">

83 <div

84 @click="open = false"

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

86 :style="opacity"

87 >

88 </div>

89 <div

90 ref="modal"

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

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

93 >

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

95 <div

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

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

98 >

99 </div>

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

101 <v-button

102 icon="chevron-left"

103 @click="open = false"

104 ></v-button>

105 <v-button

106 icon="share"

107 ></v-button>

108 </div>

109 <div class="flex flex-col gap-5">

110 <v-image

111 v-if="station"

112 :station="station"

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

114 ></v-image>

115 <div

116 v-if="station"

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

118 >

119 <p

120 :title="station.name"

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

122 >

123 {{station.name}}

124 </p>

125 <span class="text-md text-gray-400 overflow-hidden flex gap-3 pt-1">

126 <span

127 v-if="station.country"

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

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

130 >

131 <v-icon

132 id="map-pin"

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

134 size="100%"

135 ></v-icon>

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

137 </span>

138 <span

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

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

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

142 >

143 <v-icon

144 id="clock"

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

146 size="100%"

147 ></v-icon>

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

149 </span>

150 </span>

151 </div>

152 </div>

153 <div

154 v-if="station"

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

156 >

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

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

159 </div>

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

161 <v-button

162 icon="player-play"

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

164 class="bg-zinc-900 hover:bg-white"

165 ></v-button>

166 <v-button

167 :icon="[ station.is_favorite ? 'heart-off' : 'heart' ]"

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

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

170 class="bg-zinc-900 hover:bg-white"

171 :text="$lang(station.is_favorite ? 'global.unlike' : 'global.like')"

172 ></v-button>

173 </div>

174 <p v-if="station.description" class="text-md text-gray-400" v-html="station.description"></p>

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

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

177 <span

178 v-if="station.is_restricted"

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

180 >

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

182 </span>

183 <span

184 v-if="station.is_broken"

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

186 >

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

188 </span>

189 <span

190 v-if="station.is_no_track_info"

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

192 >

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

194 </span>

195 </div>

196 </div>

197 </div>

198 </div>

199 </div>

200 `

201}