()
| 55 | #[tracing::instrument(level = "debug", skip())] |
| 56 | #[component] |
| 57 | pub fn Explore() -> impl IntoView { |
| 58 | let provider_store: Arc<ProviderStore> = expect_context(); |
| 59 | let provider_keys = provider_store.get_provider_keys(ExtensionProviderScope::Recommendations); |
| 60 | let suggestion_items = RwSignal::new(vec![]); |
| 61 | let analytics = RwSignal::<Option<AllAnalyticsParsed>>::new(None); |
| 62 | spawn_local(async move { |
| 63 | if let Ok(a) = get_top_listened_songs().await { |
| 64 | tracing::debug!("Got analytics {:?}, {:?}", a, a.songs.len()); |
| 65 | analytics.set(Some(AllAnalyticsParsed { |
| 66 | total_listen_time: a.total_listen_time, |
| 67 | songs: vec![], |
| 68 | })); |
| 69 | for (song_id, time) in a.songs { |
| 70 | let provider = get_provider_key_by_id(song_id.clone()).await; |
| 71 | if let Ok(provider) = provider { |
| 72 | let song = get_song_from_id(provider.clone(), song_id).await; |
| 73 | match song { |
| 74 | Ok(song) => { |
| 75 | analytics.update(|a| { |
| 76 | if let Some(a) = a.as_mut() { |
| 77 | a.songs.push((song, time)) |
| 78 | } |
| 79 | }); |
| 80 | } |
| 81 | Err(e) => tracing::error!("Failed to fetch song from {} {:?}", provider, e), |
| 82 | } |
| 83 | } else { |
| 84 | let song = get_songs_by_options(GetSongOptions { |
| 85 | song: Some(SearchableSong { |
| 86 | _id: Some(song_id), |
| 87 | ..Default::default() |
| 88 | }), |
| 89 | ..Default::default() |
| 90 | }) |
| 91 | .await; |
| 92 | if let Ok(song) = song { |
| 93 | if let Some(song) = song.first() { |
| 94 | analytics.update(|a| { |
| 95 | if let Some(a) = a.as_mut() { |
| 96 | a.songs.push((song.clone(), time)) |
| 97 | } |
| 98 | }); |
| 99 | } |
| 100 | } |
| 101 | } |
| 102 | } |
| 103 | } |
| 104 | }); |
| 105 | |
| 106 | spawn_local(async move { |
| 107 | for key in provider_keys { |
| 108 | let suggestions = get_suggestions(key).await; |
| 109 | if let Ok(suggestions) = suggestions { |
| 110 | suggestion_items.update(|s| s.extend(suggestions)); |
| 111 | } |
| 112 | } |
| 113 | }); |
| 114 | let total_time = create_read_slice(analytics, |a| a.as_ref().map(|a| a.total_listen_time)); |
nothing calls this directly
no test coverage detected