From e86899be53566dd3348f59741fd29ebc6506bc22 Mon Sep 17 00:00:00 2001 From: kawaiizenbo <48113593+kawaiizenbo@users.noreply.github.com> Date: Fri, 5 May 2023 22:01:29 -0700 Subject: [PATCH] change some poorly thought out design choices --- WMstodon/HTTPUtils.cs | 16 ++++++++-------- WMstodon/LoginPage.xaml.cs | 10 +++++----- WMstodon/MainPage.xaml | 23 ++++++++++++++++++----- WMstodon/MainPage.xaml.cs | 9 +++++---- WMstodon/SelectInstancePage.xaml.cs | 8 ++++---- WMstodon/StatusPage.xaml.cs | 2 +- WMstodon/WMstodon.csproj | 2 +- 7 files changed, 42 insertions(+), 28 deletions(-) diff --git a/WMstodon/HTTPUtils.cs b/WMstodon/HTTPUtils.cs index bd61bfd..a6286d0 100644 --- a/WMstodon/HTTPUtils.cs +++ b/WMstodon/HTTPUtils.cs @@ -13,42 +13,42 @@ namespace WMstodon { static ApplicationDataContainer localSettings = ApplicationData.Current.LocalSettings; // still usin em - public static async Task> GETAsync(string URL) + public static async Task GETAsync(string URL) { HttpClient httpClient = new HttpClient(); httpClient.BaseAddress = new Uri((string)localSettings.Values["instanceURL"]); httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", (string)localSettings.Values["accessToken"]); HttpResponseMessage response = await httpClient.GetAsync(URL); httpClient.Dispose(); - return new KeyValuePair(response.StatusCode, await response.Content.ReadAsStringAsync()); + return response; } - public static async Task> GETGenericAsync(string URL) + public static async Task GETGenericAsync(string URL) { HttpClient generic = new HttpClient(); generic.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", (string)localSettings.Values["accessToken"]); HttpResponseMessage response = await generic.GetAsync(new Uri(URL)); generic.Dispose(); - return new KeyValuePair(response.StatusCode, await response.Content.ReadAsStringAsync()); + return response; } - public static async Task> POSTAsync(string URL, HttpContent data) + public static async Task POSTAsync(string URL, HttpContent data) { HttpClient httpClient = new HttpClient(); httpClient.BaseAddress = new Uri((string)localSettings.Values["instanceURL"]); httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", (string)localSettings.Values["accessToken"]); HttpResponseMessage response = await httpClient.PostAsync(URL, data); httpClient.Dispose(); - return new KeyValuePair(response.StatusCode, await response.Content.ReadAsStringAsync()); + return response; } - public static async Task> POSTGenericAsync(string URL, HttpContent data) + public static async Task POSTGenericAsync(string URL, HttpContent data) { HttpClient generic = new HttpClient(); generic.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", (string)localSettings.Values["accessToken"]); HttpResponseMessage response = await generic.PostAsync(new Uri(URL), data); generic.Dispose(); - return new KeyValuePair(response.StatusCode, await response.Content.ReadAsStringAsync()); + return response; } } } diff --git a/WMstodon/LoginPage.xaml.cs b/WMstodon/LoginPage.xaml.cs index 4d92c07..e9990a0 100644 --- a/WMstodon/LoginPage.xaml.cs +++ b/WMstodon/LoginPage.xaml.cs @@ -52,13 +52,13 @@ namespace WMstodon postopts["grant_type"] = "authorization_code"; postopts["code"] = AuthCodeTextBox.Text; postopts["scope"] = "read write push"; - KeyValuePair response = + HttpResponseMessage response = await HTTPUtils.POSTAsync("/oauth/token", new FormUrlEncodedContent(postopts)); - if (response.Key == HttpStatusCode.OK) + if (response.StatusCode == HttpStatusCode.OK) { - JObject appResponseObj = JObject.Parse(response.Value); + JObject appResponseObj = JObject.Parse(await response.Content.ReadAsStringAsync()); localSettings.Values["accessToken"] = (string)appResponseObj["access_token"]; - if ((await HTTPUtils.GETAsync("/api/v1/accounts/verify_credentials")).Key != HttpStatusCode.OK) + if ((await HTTPUtils.GETAsync("/api/v1/accounts/verify_credentials")).StatusCode != HttpStatusCode.OK) { ErrorTextBlock.Text = "Could not log into service"; return; @@ -67,7 +67,7 @@ namespace WMstodon } else { - ErrorTextBlock.Text = "Could not log into service:\n" + response.Key; + ErrorTextBlock.Text = "Could not log into service:\n" + response.StatusCode; } } } diff --git a/WMstodon/MainPage.xaml b/WMstodon/MainPage.xaml index 8d634ff..7f9a323 100644 --- a/WMstodon/MainPage.xaml +++ b/WMstodon/MainPage.xaml @@ -9,7 +9,23 @@ Background="{ThemeResource ApplicationPageBackgroundThemeBrush}"> - + + + + + + + + + + + + + + + + + @@ -26,13 +42,10 @@ - + -