A mobile app for listening to radio stations from around the globe
git clone git://soophie.de/verbal
52
onScroll() {53
if(state.tab === 'search') {54
if(window.innerHeight + window.pageYOffset >= document.body.offsetHeight - 200) {55
this.$refs.search.doSearchMore();55
if(this.$refs.search.searching) {56
this.$refs.search.doSearchMore();57
}58
}59
}60
}
13
},14
results: [],15
loading: false,16
searching: false,17
more: true,18
countries: [19
{ name: 'All', value: '' },20
{ name: 'US', value: 'US' },21
{ name: 'GB', value: 'GB' },22
{ name: 'DE', value: 'DE' },22
{ name: 'CA', value: 'CA' }23
{ name: 'CA', value: 'CA' },24
{ name: 'JP', value: 'JP' }25
],26
languages: [27
{ name: 'All', value: '' },
29
{ name: 'DE', value: 'DE' },30
{ name: 'FR', value: 'FR' },31
{ name: 'ES', value: 'ES' }32
],33
recommended: [],34
popular: [35
45761,36
44366,37
37156,38
33977,39
56254,40
3061541
]42
};43
},
52
this.results = [];53
this.loading = true;54
this.more = true;55
this.searching = true;56
this.query.page = 0;57
const result = await http`get::/api/search`(this.query);58
this.loading = false;
70
}71
this.results.push(...result);72
},73
async loadRecommended() {74
for(const id of this.popular) {75
this.recommended.push(await http`get::/api/station`({ id }));76
}77
},78
reset() {79
this.query = {80
name : '',81
page: 082
};66
this.doSearch();83
this.searching = false;84
this.results = [];85
// this.doSearch();86
this.loadRecommended();87
}88
},89
mounted() {70
this.doSearch();90
// this.doSearch();91
this.loadRecommended();92
},93
template: `94
<v-tab id="search" :tab="state.tab" @show="doSearch">
117
<option v-for="language in languages" :value="language.value">{{language.name}}</option>118
</select>119
</div>99
<ul class="flex flex-col">120
<ul v-if="searching" class="flex flex-col">121
<li122
:key="station.id"123
v-for="station in results"
126
<v-station :station="station"></v-station>127
</li>128
</ul>129
<div v-else>130
<h3 class="text-white text-[24px] font-bold pb-8 pt-4 sm:pt-0">{{$lang('search.recommended')}}</h3>131
<ul class="flex flex-col">132
<li133
:key="station.id"134
v-for="station in recommended"135
class="border-t sm:border-t-2 first:border-none border-zinc-900 py-5 first:pt-0"136
>137
<v-station :station="station"></v-station>138
</li>139
</ul>140
</div>141
<div142
v-show="loading"143
class="w-[60px] h-[60px] select-none pointer-events-none mx-auto"
150
></v-icon>151
</div>152
<div120
v-if="!more && results.length > 0"153
v-if="searching && !more && results.length > 0"154
class="text-zinc-400 text-md mx-auto pb-6"155
>156
{{$lang('search.list.end')}}157
</div>158
<div126
v-if="results.length == 0"159
v-if="searching && results.length == 0"160
class="text-zinc-400 text-md mx-auto pb-6"161
>162
{{$lang('search.list.empty')}}
83
Ok(sql)84
}85
}87
#[derive(Debug, Clone, Deserialize)]88
pub struct StationId {89
pub id: i32,90
}
5
use tide_sqlx::SQLxRequestExt;7
use crate::model;8
use crate::model::StationId;9
use crate::unwrap_option_or_throw;10
use crate::unwrap_result_or_throw;11
use crate::Response;
165
sqlx::query(&sql).execute(conn.acquire().await?).await?;166
Response::with(())167
}169
pub async fn get_station(req: tide::Request<()>) -> tide::Result {170
let station_id = req.query::<StationId>()?;171
let account =172
unwrap_option_or_throw!(req.ext::<model::Account>(), "no account in request found!");173
let sql = format!(174
r#"175
SELECT176
station.*,177
station_status.is_restricted,178
station_status.is_broken,179
station_status.is_no_track_info,180
station_status.is_hidden,181
CASE182
WHEN favorite.id IS NULL OR favorite.account_id != {account_id}183
THEN false184
ELSE true185
END AS is_favorite186
FROM station187
LEFT JOIN favorite188
ON station.id = favorite.station_id189
LEFT JOIN station_status190
ON station.id = station_status.station_id191
WHERE station.id = {station_id}192
AND station_status.is_hidden IS NOT true193
"#,194
account_id = account.id,195
station_id = station_id.id,196
);197
let mut conn = req.sqlx_conn::<Postgres>().await;198
let result = sqlx::query_as::<_, model::Station>(&sql)199
.fetch_optional(conn.acquire().await?)200
.await?;201
Response::with(result)202
}
53
app.at("/api/favorite").get(route::get_favorites);54
app.at("/api/favorite").post(route::add_favorite);55
app.at("/api/favorite").delete(route::delete_favorite);56
app.at("/api/station").get(route::get_station);58
let address =59
unwrap_result_or_abort!(config.server.to_url(), "cannot parse server address!");
21
"search.input.placeholder": "Search for stations",22
"search.list.end": "You've reached the end",23
"search.list.empty": "No results found",24
"search.recommended": "Recommended",25
"account.settings": "Settings",26
"account.username": "Username",27
"account.username.info": "This is your primary account name which is visible to everyone",
54
"search.input.placeholder": "Suche nach Sender",55
"search.list.end": "Du hast das Ende erreicht",56
"search.list.empty": "Keine Ergebnisse gefunden",57
"search.recommended": "Empfohlen",58
"account.settings": "Einstellungen",59
"account.username": "Nutzername",60
"account.username.info": "Dies ist Ihr primärer Kontoname, der von allen gesehen werden kann",