A mobile app for listening to radio stations from around the globe
git clone git://soophie.de/verbal
19
calc() {20
const items = this.$refs.list.querySelectorAll('li');21
this.length = items.length;22
this.size = items[1].offsetLeft;23
this.count = Math.ceil(this.$refs.list.clientWidth / this.size);22
if(this.length > 0) {23
this.size = items[1].offsetLeft;24
this.count = Math.ceil(this.$refs.list.clientWidth / this.size);25
}26
},27
prev() {28
this.calc();
141
<p>{{station.state ? station.state + ', ' : ''}}{{station.country}}</p>142
</span>143
<span144
v-if="station?.playtime && duration(station.playtime ?? 0).length > 0"144
v-if="state.authenticated && station?.playtime && duration(station.playtime ?? 0).length > 0"145
class="text-gray-400 inline-flex items-center gap-[5px]"146
:title="$lang('detail.playtime')"147
>
166
<v-play-button :station="station"></v-play-button>167
<v-button168
:icon="station.is_favorite ? 'bookmark-off' : 'bookmark'"169
:title="$lang(station.is_favorite ? 'global.unlike' : 'global.like')"169
:title="$lang(state.authenticated ? (station.is_favorite ? 'global.unlike' : 'global.like') : 'global.requires-auth')"170
@click="() => setLike(!station.is_favorite)"171
class="bg-zinc-900 hover:bg-white px-1"172
:class="{ '!bg-zinc-900': !state.authenticated }"173
:text="station.likes.toString()"174
:disabled="!state.authenticated"175
></v-button>176
</div>177
<p v-if="getDescription()" class="text-md text-gray-400 mt-2" v-html="getDescription()"></p>
11
$route12
},13
template: `14
<div class="sticky top-0 z-30 -mb-2">14
<div v-if="state.tab !== 'auth'" class="sticky top-0 z-30 -mb-2">15
<div class="flex bg-black py-6 gap-4">16
<div class="flex flex-1 gap-4">17
<v-button
28
></v-button>29
</div>30
<v-button31
v-if="state.authenticated"32
:text="state.account?.name"33
icon="user"34
:title="$lang('global.account')"35
:active="state.tab === 'account'"36
@click="$route('/account')"37
></v-button>38
<v-button39
v-else40
:text="$lang('global.register')"41
icon="login"42
active="true"43
@click="$route('/auth')"44
class="btn-icon-rotate"45
></v-button>46
</div>47
<div class="w-full h-2 bg-gradient-to-b from-black to-transparent"></div>48
</div>
8
},9
template: `10
<button11
@click="$emit('click')"11
@click="() => disabled ? {} : $emit('click')"12
:title="title"13
:class="{ 'bg-zinc-900': active, '!bg-inherit pointer-events-none': disabled }"13
:class="{ 'bg-zinc-900': active, '!bg-inherit cursor-default': disabled }"14
class="group min-w-[50px] h-[50px] hover:bg-white rounded-full inline-flex justify-center items-center cursor-pointer transition-colors outline-none"15
>16
<v-icon
23
<slot v-else></slot>24
<p25
v-if="text"26
:class="[ active ? 'text-gray-100' : 'text-gray-400' ]"27
class="group-hover:text-gray-800 transition-colors -ml-[6px] pr-4 font-medium overflow-hidden text-ellipsis whitespace-nowrap"26
:class="[ active ? 'text-gray-100' : 'text-gray-400', disabled ? '!text-gray-700' : '' ]"27
class="group-hover:text-gray-800 transition-colors -ml-[6px] pr-4 font-medium overflow-hidden text-ellipsis whitespace-nowrap select-none"28
>29
{{text}}30
</p>
21
'^\/account$': 'account',22
'^\/station\/(\\d+)$': 'detail',23
'^@not-found$': 'not-found',24
'^@auth$': 'auth'24
'^\/auth$': 'auth'25
};27
export const state = reactive({
77
state.tab = 'search';78
state.station = null;79
if(state.account === null) {80
state.authenticated = false;81
$route('@auth', { update: false });82
return;80
localStorage.setItem(TOKEN_NAME, 'guest-token');81
state.account = await http`get::/api/account`();82
state.devices = await http`get::/api/devices`();83
state.token = localStorage.getItem(TOKEN_NAME);84
}85
state.authenticated = state.token !== 'guest-token';86
if(!state.authenticated) {87
const navigatorLanguage = navigator?.language;88
let language = 'en';89
if(/^de-?/.test(navigatorLanguage)) {90
language = 'de';91
}92
state.account.language = language;93
}84
state.authenticated = true;94
document.addEventListener('scroll', this.onScroll);95
document.addEventListener('wheel', this.onScroll);96
document.addEventListener('touchmove', this.onScroll);
149
v-if="state.authenticated !== null"150
class="px-4 sm:px-10 max-w-[1200px] mx-auto flex flex-col min-h-[100vh]"151
>143
<v-auth v-if="!state.authenticated" :state="state"></v-auth>144
<v-menu v-if="state.authenticated" :state="state"></v-menu>152
<v-menu :state="state"></v-menu>153
<v-auth :state="state"></v-auth>154
<div>146
<v-search v-if="state.authenticated" ref="search" :state="state"></v-search>147
<v-favorites v-if="state.authenticated" ref="favorites" :state="state"></v-favorites>148
<v-account v-if="state.authenticated" :state="state"></v-account>155
<v-search ref="search" :state="state"></v-search>156
<v-favorites ref="favorites" :state="state"></v-favorites>157
<v-account :state="state"></v-account>158
</div>150
<v-player ref="player" v-if="state.authenticated" :station="state.station"></v-player>151
<v-detail ref="detail" v-if="state.authenticated"></v-detail>152
<v-notfound v-if="state.authenticated" :state="state"></v-notfound>159
<v-player ref="player" :station="state.station"></v-player>160
<v-detail ref="detail"></v-detail>161
<v-notfound :state="state"></v-notfound>162
<v-popup ref="popup"></v-popup>163
</div>164
`
1
import {$lang, http} from '../utils.js';1
import {$lang, $route, http} from '../utils.js';2
import VTab from '../component/tab.js';3
import VSelect from '../component/select.js';4
import VButton from '../element/button.js';
19
},20
methods: {21
$lang,22
$route,23
isCurrentDevice(device) {24
return device.uid === this.state.token;25
},
41
},42
logout() {43
localStorage.removeItem('verbal-token');43
this.state.app.init();44
$route('/', { reload: true });45
}46
},47
template: `
95
<p class="text-sm text-gray-500">{{device.uid}}</p>96
</li>97
</ul>97
<v-button98
icon="plus"99
:text="$lang('account.devices.add')"100
class="mt-4 mx-auto"101
></v-button>98
</div>103
<div class="flex flex-col">99
<div class="flex flex-col pt-4">100
<button101
class="w-full h-[52px] px-4 text-md bg-zinc-900 hover:bg-zinc-800 text-zinc-100 rounded-md outline-none"102
@click="logout"
29
language: this.language30
});31
localStorage.setItem('verbal-token', device.uid);32
this.state.app.init();33
$route('/');32
$route('/', { reload: true });33
}34
catch(err) {35
console.error(err);
39
try {40
localStorage.setItem('verbal-token', this.token);41
await http`get::/api/account`();43
this.state.app.init();44
$route('/');42
$route('/', { reload: true });43
}44
catch(err) {45
localStorage.removeItem('verbal-token');
58
class="w-full h-[52px] px-4 text-md bg-zinc-100 hover:bg-zinc-300 text-zinc-900 rounded-md outline-none"59
@click="method = 'register'"60
>63
Create an account61
{{$lang('global.register')}}62
</button>63
<button64
class="w-full h-[52px] px-4 text-md bg-zinc-900 hover:bg-zinc-800 text-zinc-100 rounded-md outline-none"65
@click="method = 'login'"66
>69
Log In67
{{$lang('global.login')}}68
</button>69
</div>70
</div>
76
class="self-start"77
>78
</v-button>81
<h3 class="text-white text-[24px] font-bold pb-4 px-4 sm:pt-0">Create an account</h3>79
<h3 class="text-white text-[24px] font-bold pb-4 px-4 sm:pt-0">{{$lang('global.register')}}</h3>80
<div class="flex flex-col gap-1 w-full px-4">81
<label for="username" class="text-white text-lg">Choose your username</label>82
<input
104
class="h-[52px] px-4 mx-4 text-md bg-zinc-100 hover:bg-zinc-300 text-zinc-900 rounded-md outline-none mt-8"105
@click="register"106
>109
Sign up now107
{{$lang('global.register.now')}}108
</button>109
</div>110
<div v-if="method === 'login'" class="w-full flex flex-col gap-5 -mt-12">
115
class="self-start"116
>117
</v-button>120
<h3 class="text-white text-[24px] font-bold pb-4 px-4 sm:pt-0">Log In</h3>118
<h3 class="text-white text-[24px] font-bold pb-4 px-4 sm:pt-0">{{$lang('global.login')}}</h3>119
<div class="flex flex-col gap-1 w-full px-4">120
<label for="token" class="text-white text-lg">Insert account token</label>121
<input
131
class="h-[52px] px-4 mx-4 text-md bg-zinc-100 hover:bg-zinc-300 text-zinc-900 rounded-md outline-none mt-8"132
@click="login"133
>136
Sign In134
{{$lang('global.login.now')}}135
</button>136
</div>137
</div>
22
languages: [],23
playtime: null,24
latest: null,25
favorites: null26
};27
},28
components: {
62
async loadCategories() {63
this.playtime = await http`get::/api/category/playtime`();64
this.latest = await http`get::/api/category/latest`();65
let favorites = await http`get::/api/favorite`();66
favorites = favorites.sort(() => Math.random() - 0.5);67
favorites.length = 10;68
this.favorites = favorites;69
},70
async loadFilters() {71
this.countries = await http`get::/api/countries`();
151
</li>152
</ul>153
<div v-else class="flex flex-col gap-3 md:gap-10">149
<v-carousel :title="$lang('search.latest')" :items="latest"></v-carousel>150
<v-carousel :title="$lang('search.playtime')" :items="playtime"></v-carousel>154
<v-carousel v-if="state.authenticated" :title="$lang('search.latest')" :items="latest"></v-carousel>155
<v-carousel v-if="state.authenticated" :title="$lang('search.playtime')" :items="playtime"></v-carousel>156
<v-carousel v-if="state.authenticated" :title="$lang('search.favorites')" :items="favorites"></v-carousel>157
</div>158
<div159
v-show="loading"
81
return message;82
}84
export function $route(path, { update = true } = {}) {84
export function $route(path, { update = true, reload = false } = {}) {85
for(const [key, value] of Object.entries(ROUTES)) {86
const regex = new RegExp(key);87
const match = regex.exec(path);88
if(match !== null) {89
state.tab = value;90
if(value === 'detail') {91
if(state.app.$refs.detail) {92
state.app.$refs.detail.show({ id: match[1] });89
if(!reload) {90
state.tab = value;91
if(value === 'detail') {92
if(state.app.$refs.detail) {93
state.app.$refs.detail.show({ id: match[1] });94
}95
}96
}97
if(update) {98
window.history.pushState(null, null, path);99
}100
if(reload) {101
window.location.reload();102
}103
return;104
}105
}
126
ADD CONSTRAINT favorite_station_id127
FOREIGN KEY (station_id)128
REFERENCES station(id);130
/* ############################################################ */131
/* # guest account # */132
/* ############################################################ */134
INSERT INTO account (id, name)135
VALUES (0, 'Guest');137
INSERT INTO device (uid, account_id)138
VALUES ('guest-token', 0);
1
/* ### create a test user ### */3
INSERT INTO account (id, name) VALUES (1, 'Test User');4
INSERT INTO device (uid, account_id) VALUES ('test-token', 1);
11
pub id: i32,12
pub name: Option<String>,13
pub language: String,14
pub playtime: i64,14
pub playtime: Option<i64>,15
}17
#[derive(Debug, Clone, Serialize, Deserialize, FromRow)]
122
}123
}125
.btn-icon-rotate .ti {126
transform: rotate(180deg);127
}129
@font-face {130
font-family: 'Inter';131
font-style: normal;
24
"global.brand": "Verbal",25
"global.slogan": "A mobile app for listening to radio stations from around the globe.",26
"global.upcoming": "<br><br>Comming soon!",27
"global.logout": "Log Out",27
"global.login": "Log in",28
"global.login.now": "Sign in",29
"global.logout": "Log out",30
"global.listen": "Listen",31
"global.not-found": "Page not found",32
"global.requires-auth": "You need to have an account to use this",33
"global.register": "Create an account",34
"global.register.now": "Sign up",35
"player.loading": "Loading...",36
"player.no-song-title": "- No song title available -",37
"search.input.all": "All",
41
"search.recommended": "Recommended",42
"search.latest": "Recently played",43
"search.playtime": "Your top stations",44
"search.favorites": "Liked stations",45
"account.settings": "Settings",46
"account.username": "Username",47
"account.username.info": "This is your primary account name which is visible to everyone",
84
"global.brand": "Verbal",85
"global.slogan": "Eine mobile App zum Hören von Radiosendern aus aller Welt.",86
"global.upcoming": "<br><br>Kommt bald!",87
"global.login": "Anmelden",88
"global.login.now": "Anmelden",89
"global.logout": "Abmelden",90
"player.loading": "Laden...",91
"global.listen": "Hören",92
"global.not-found": "Seite konnte nicht gefunden werden",93
"global.requires-auth": "Du benötigst ein Konto um dies zu nutzten",94
"global.register": "Konto erstellen",95
"global.register.now": "Registrieren",96
"player.no-song-title": "- Song Titel nicht verfügbar -",97
"search.input.all": "Alle",98
"search.input.placeholder": "Suche nach Sender",
101
"search.recommended": "Empfohlen",102
"search.latest": "Zuletzt gespielt",103
"search.playtime": "Deine Lieblingssender",104
"search.favorites": "Gespeicherte Sender",105
"account.settings": "Einstellungen",106
"account.username": "Nutzername",107
"account.username.info": "Dies ist Ihr primärer Kontoname, der von allen gesehen werden kann",
116
"account.devices.add": "Gerät hinzufügen",117
"detail.no-description": "Keine Beschreibung vorhanden",118
"detail.playtime": "Spielzeit",107
"detail.related": "Zugehörig Sender",119
"detail.related": "Zugehörige Sender",120
"detail.hosted-by": "Gehört zu"121
}122
}