so://phie

verbal

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

blob: e38055fc90b82e9bfdc890057bf78aaf28e02f5c (10778 bytes)[doc][blame][raw]

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

2import {http, $lang, $route, duration} 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 async show(station) {

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

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

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

35 return;

36 }

37 this.group = null;

38 if(this.station.group_id) {

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

40 }

41 this.open = true;

42 },

43 async setLike(is_favorite) {

44 try {

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

46 this.station.is_favorite = is_favorite;

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

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

49 }

50 catch(error) {

51 console.log(error);

52 }

53 },

54 gradient(color) {

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

56 },

57 hasGroup() {

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

59 return false;

60 }

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

62 },

63 getDescription() {

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

65 },

66 share() {

67 if('share' in navigator) {

68 navigator.share({

69 url: window.location.href,

70 title: this.station.name

71 });

72 }

73 }

74 },

75 mounted() {

76 const path = window.location.pathname;

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

78 if(match) {

79 const id = match[1];

80 this.show({ id });

81 }

82 },

83 template: `

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

85 <div class="z-40">

86 <div

87 ref="modal"

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

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

90 >

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

92 <div

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

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

95 >

96 </div>

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

98 <v-button

99 icon="chevron-left"

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

101 ></v-button>

102 <v-button

103 icon="share"

104 @click="share()"

105 ></v-button>

106 </div>

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

108 <v-image

109 v-if="station"

110 :station="station"

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

112 ></v-image>

113 <div

114 v-if="station"

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

116 >

117 <p

118 :title="station.name"

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

120 >

121 {{station.name}}

122 </p>

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

124 <span

125 v-if="group?.group"

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

127 >

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

129 </span>

130 <span

131 v-if="station.country"

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

133 >

134 <v-icon

135 id="map-pin"

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

137 size="100%"

138 ></v-icon>

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

140 </span>

141 <span

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

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

144 >

145 <v-icon

146 id="clock"

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

148 size="100%"

149 ></v-icon>

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

151 </span>

152 </span>

153 </div>

154 </div>

155 <div

156 v-if="station"

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

158 >

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

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

161 <v-button

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

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

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

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

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

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

168 :disabled="!state.authenticated"

169 ></v-button>

170 </div>

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

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

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

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

175 </div>

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 v-if="hasGroup()" class="mt-[32px]">

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

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

199 <li

200 :key="station.id"

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

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

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

204 >

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

206 </li>

207 </ul>

208 </div>

209 </div>

210 </div>

211 </div>

212 </div>

213 </v-tab>

214 `

215}