Some basic project tidy up
This commit is contained in:
parent
908f126987
commit
1b0155d064
46 changed files with 83 additions and 133 deletions
|
@ -1,17 +1,15 @@
|
||||||
using Markdig;
|
using Microsoft.AspNetCore.Components;
|
||||||
using Microsoft.AspNetCore.Components;
|
|
||||||
using Microsoft.AspNetCore.Components.Forms;
|
using Microsoft.AspNetCore.Components.Forms;
|
||||||
using Neighbourhood.omg.lol.Models;
|
using Neighbourhood.omg.lol.Models;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.Net;
|
|
||||||
using System.Net.Http.Json;
|
using System.Net.Http.Json;
|
||||||
using System.Reflection;
|
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Text.Json;
|
using System.Text.Json;
|
||||||
using System.Text.RegularExpressions;
|
using System.Text.RegularExpressions;
|
||||||
|
|
||||||
namespace Neighbourhood.omg.lol {
|
namespace Neighbourhood.omg.lol
|
||||||
public class RestService {
|
{
|
||||||
|
public class RestService {
|
||||||
HttpClient _client;
|
HttpClient _client;
|
||||||
JsonSerializerOptions _serializerOptions;
|
JsonSerializerOptions _serializerOptions;
|
||||||
public const string BaseUrl = "https://api.omg.lol";
|
public const string BaseUrl = "https://api.omg.lol";
|
|
@ -2,8 +2,9 @@
|
||||||
using System.ComponentModel;
|
using System.ComponentModel;
|
||||||
using System.Globalization;
|
using System.Globalization;
|
||||||
using System.Text.Json;
|
using System.Text.Json;
|
||||||
|
using Neighbourhood.omg.lol.Models;
|
||||||
|
|
||||||
namespace Neighbourhood.omg.lol.Models {
|
namespace Neighbourhood.omg.lol {
|
||||||
public class State : INotifyPropertyChanged {
|
public class State : INotifyPropertyChanged {
|
||||||
// Feature flags
|
// Feature flags
|
||||||
public bool FeatureFollowing { get; } = false;
|
public bool FeatureFollowing { get; } = false;
|
56
Classes/Utilities.cs
Normal file
56
Classes/Utilities.cs
Normal file
|
@ -0,0 +1,56 @@
|
||||||
|
using Markdig;
|
||||||
|
using Microsoft.AspNetCore.Components;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace Neighbourhood.omg.lol
|
||||||
|
{
|
||||||
|
public static class Utilities
|
||||||
|
{
|
||||||
|
|
||||||
|
private static MarkdownPipeline markdownPipeline { get; }
|
||||||
|
= new MarkdownPipelineBuilder().UseAutoLinks().Build();
|
||||||
|
|
||||||
|
public static string MdToHtml(string markdown) =>
|
||||||
|
Markdown.ToHtml(markdown, markdownPipeline);
|
||||||
|
|
||||||
|
public static MarkupString MdToHtmlMarkup(string markdown) =>
|
||||||
|
(MarkupString)MdToHtml(markdown);
|
||||||
|
|
||||||
|
public static async Task<long> FileSize(FileResult file)
|
||||||
|
{
|
||||||
|
using var fileStream = await file.OpenReadAsync();
|
||||||
|
return fileStream.Length;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static async Task<string> Base64FromFile(FileResult file)
|
||||||
|
{
|
||||||
|
using var memoryStream = new MemoryStream();
|
||||||
|
using var fileStream = await file.OpenReadAsync();
|
||||||
|
await fileStream.CopyToAsync(memoryStream);
|
||||||
|
byte[] bytes = memoryStream.ToArray();
|
||||||
|
return Convert.ToBase64String(bytes);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static string RelativeTimeFromUnix(long unix)
|
||||||
|
{
|
||||||
|
DateTimeOffset createdTime = DateTimeOffset.UnixEpoch.AddSeconds(unix);
|
||||||
|
TimeSpan offset = DateTimeOffset.UtcNow - createdTime;
|
||||||
|
|
||||||
|
var offsetString = string.Empty;
|
||||||
|
if (Math.Floor(offset.TotalDays) == 1) offsetString = $"{Math.Floor(offset.TotalDays)} day ago";
|
||||||
|
else if (offset.TotalDays > 1) offsetString = $"{Math.Floor(offset.TotalDays)} days ago";
|
||||||
|
else if (Math.Floor(offset.TotalHours) == 1) offsetString = $"{Math.Floor(offset.TotalHours)} hour ago";
|
||||||
|
else if (offset.TotalHours > 1) offsetString = $"{Math.Floor(offset.TotalHours)} hours ago";
|
||||||
|
else if (Math.Floor(offset.TotalMinutes) == 1) offsetString = $"{Math.Floor(offset.TotalMinutes)} minute ago";
|
||||||
|
else if (offset.TotalMinutes > 1) offsetString = $"{Math.Floor(offset.TotalMinutes)} minutes ago";
|
||||||
|
else if (Math.Floor(offset.TotalSeconds) == 1) offsetString = $"{Math.Floor(offset.TotalSeconds)} second ago";
|
||||||
|
else offsetString = $"{Math.Floor(offset.TotalSeconds)} seconds ago";
|
||||||
|
|
||||||
|
return offsetString;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,12 +0,0 @@
|
||||||
<?xml version="1.0" encoding="utf-8" ?>
|
|
||||||
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
|
|
||||||
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
|
|
||||||
x:Class="Neighbourhood.omg.lol.EphemeralWebPage"
|
|
||||||
BackgroundColor="{DynamicResource PageBackgroundColor}">
|
|
||||||
<Grid>
|
|
||||||
<WebView x:Name="webview"
|
|
||||||
Navigating="webview_Navigating"
|
|
||||||
VerticalOptions="Fill"
|
|
||||||
HorizontalOptions="Fill" />
|
|
||||||
</Grid>
|
|
||||||
</ContentPage>
|
|
|
@ -1,18 +0,0 @@
|
||||||
namespace Neighbourhood.omg.lol;
|
|
||||||
|
|
||||||
public partial class EphemeralWebPage : ContentPage
|
|
||||||
{
|
|
||||||
private NavigatorService NavigatorService { get; set; }
|
|
||||||
|
|
||||||
public EphemeralWebPage(NavigatorService navigatorService)
|
|
||||||
{
|
|
||||||
this.NavigatorService = navigatorService;
|
|
||||||
InitializeComponent();
|
|
||||||
this.webview.Source = $"https://home.omg.lol/ephemeral";
|
|
||||||
}
|
|
||||||
|
|
||||||
public async void webview_Navigating(object sender, WebNavigatingEventArgs e) {
|
|
||||||
var cookies = this.webview.Cookies;
|
|
||||||
Uri uri = new Uri(e.Url);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -17,7 +17,6 @@ namespace Neighbourhood.omg.lol {
|
||||||
|
|
||||||
builder.Services.AddMauiBlazorWebView();
|
builder.Services.AddMauiBlazorWebView();
|
||||||
builder.Services.AddTransient<LoginWebViewPage>();
|
builder.Services.AddTransient<LoginWebViewPage>();
|
||||||
builder.Services.AddTransient<EphemeralWebPage>();
|
|
||||||
|
|
||||||
builder.Services.AddSingleton<RestService>();
|
builder.Services.AddSingleton<RestService>();
|
||||||
builder.Services.AddSingleton<State>();
|
builder.Services.AddSingleton<State>();
|
||||||
|
@ -25,12 +24,7 @@ namespace Neighbourhood.omg.lol {
|
||||||
|
|
||||||
//ConfigurationBuilder configurationBuilder = new ConfigurationBuilder();
|
//ConfigurationBuilder configurationBuilder = new ConfigurationBuilder();
|
||||||
//builder.Services.AddSingleton<IConfiguration>(configurationBuilder.AddUserSecrets<App>().Build());
|
//builder.Services.AddSingleton<IConfiguration>(configurationBuilder.AddUserSecrets<App>().Build());
|
||||||
var assembly = Assembly.GetExecutingAssembly();
|
using Stream stream = App.Assembly.GetManifestResourceStream($"{App.Name}.appsettings.json")!;
|
||||||
var details = assembly.GetName();
|
|
||||||
App.Name = details.Name!;
|
|
||||||
App.Version = details.Version!.ToString();
|
|
||||||
var appSettings = $"{App.Name}.appsettings.json";
|
|
||||||
using var stream = assembly.GetManifestResourceStream(appSettings);
|
|
||||||
var config = new ConfigurationBuilder().AddJsonStream(stream).Build();
|
var config = new ConfigurationBuilder().AddJsonStream(stream).Build();
|
||||||
builder.Configuration.AddConfiguration(config);
|
builder.Configuration.AddConfiguration(config);
|
||||||
|
|
||||||
|
|
|
@ -1,11 +1,6 @@
|
||||||
using System;
|
namespace Neighbourhood.omg.lol.Models
|
||||||
using System.Collections.Generic;
|
{
|
||||||
using System.Linq;
|
public class NowData {
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace Neighbourhood.omg.lol.Models {
|
|
||||||
public class NowData {
|
|
||||||
public string Address { get; set; }
|
public string Address { get; set; }
|
||||||
public string Url { get; set; }
|
public string Url { get; set; }
|
||||||
public TimeData Updated { get; set; }
|
public TimeData Updated { get; set; }
|
|
@ -1,15 +1,9 @@
|
||||||
using Markdig;
|
using System.Text.Json;
|
||||||
using Microsoft.AspNetCore.Components;
|
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Text.Json;
|
|
||||||
using System.Text.Json.Serialization;
|
using System.Text.Json.Serialization;
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace Neighbourhood.omg.lol.Models {
|
namespace Neighbourhood.omg.lol.Models
|
||||||
public class Pic {
|
{
|
||||||
|
public class Pic {
|
||||||
public string Id { get; set; }
|
public string Id { get; set; }
|
||||||
public string Url { get; set; }
|
public string Url { get; set; }
|
||||||
public string Address { get; set; }
|
public string Address { get; set; }
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
using Markdig;
|
using Microsoft.AspNetCore.Components;
|
||||||
using Microsoft.AspNetCore.Components;
|
|
||||||
|
|
||||||
namespace Neighbourhood.omg.lol.Models {
|
namespace Neighbourhood.omg.lol.Models
|
||||||
public class Status {
|
{
|
||||||
|
public class Status {
|
||||||
public string Id { get; set; }
|
public string Id { get; set; }
|
||||||
public string Address { get; set; }
|
public string Address { get; set; }
|
||||||
public string Created { get; set; }
|
public string Created { get; set; }
|
||||||
|
|
|
@ -1,51 +0,0 @@
|
||||||
using Markdig;
|
|
||||||
using Microsoft.AspNetCore.Components;
|
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace Neighbourhood.omg.lol {
|
|
||||||
public static class Utilities {
|
|
||||||
|
|
||||||
private static MarkdownPipeline markdownPipeline { get; }
|
|
||||||
= new MarkdownPipelineBuilder().UseAutoLinks().Build();
|
|
||||||
|
|
||||||
public static string MdToHtml(string markdown) =>
|
|
||||||
Markdown.ToHtml(markdown, markdownPipeline);
|
|
||||||
|
|
||||||
public static MarkupString MdToHtmlMarkup(string markdown) =>
|
|
||||||
(MarkupString)MdToHtml(markdown);
|
|
||||||
|
|
||||||
public static async Task<long> FileSize(FileResult file) {
|
|
||||||
using var fileStream = await file.OpenReadAsync();
|
|
||||||
return fileStream.Length;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static async Task<string> Base64FromFile(FileResult file) {
|
|
||||||
using var memoryStream = new MemoryStream();
|
|
||||||
using var fileStream = await file.OpenReadAsync();
|
|
||||||
await fileStream.CopyToAsync(memoryStream);
|
|
||||||
byte[] bytes = memoryStream.ToArray();
|
|
||||||
return Convert.ToBase64String(bytes);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static string RelativeTimeFromUnix(long unix) {
|
|
||||||
DateTimeOffset createdTime = DateTimeOffset.UnixEpoch.AddSeconds(unix);
|
|
||||||
TimeSpan offset = DateTimeOffset.UtcNow - createdTime;
|
|
||||||
|
|
||||||
var offsetString = string.Empty;
|
|
||||||
if (Math.Floor(offset.TotalDays) == 1) offsetString = $"{Math.Floor(offset.TotalDays)} day ago";
|
|
||||||
else if (offset.TotalDays > 1) offsetString = $"{Math.Floor(offset.TotalDays)} days ago";
|
|
||||||
else if (Math.Floor(offset.TotalHours) == 1) offsetString = $"{Math.Floor(offset.TotalHours)} hour ago";
|
|
||||||
else if (offset.TotalHours > 1) offsetString = $"{Math.Floor(offset.TotalHours)} hours ago";
|
|
||||||
else if (Math.Floor(offset.TotalMinutes) == 1) offsetString = $"{Math.Floor(offset.TotalMinutes)} minute ago";
|
|
||||||
else if (offset.TotalMinutes > 1) offsetString = $"{Math.Floor(offset.TotalMinutes)} minutes ago";
|
|
||||||
else if (Math.Floor(offset.TotalSeconds) == 1) offsetString = $"{Math.Floor(offset.TotalSeconds)} second ago";
|
|
||||||
else offsetString = $"{Math.Floor(offset.TotalSeconds)} seconds ago";
|
|
||||||
|
|
||||||
return offsetString;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -241,13 +241,10 @@
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<MauiXaml Update="AppShell.xaml">
|
<MauiXaml Update="XamlComponents\AppShell.xaml">
|
||||||
<Generator>MSBuild:Compile</Generator>
|
<Generator>MSBuild:Compile</Generator>
|
||||||
</MauiXaml>
|
</MauiXaml>
|
||||||
<MauiXaml Update="EphemeralWebPage.xaml">
|
<MauiXaml Update="XamlComponents\LoginWebViewPage.xaml">
|
||||||
<Generator>MSBuild:Compile</Generator>
|
|
||||||
</MauiXaml>
|
|
||||||
<MauiXaml Update="LoginWebViewPage.xaml">
|
|
||||||
<Generator>MSBuild:Compile</Generator>
|
<Generator>MSBuild:Compile</Generator>
|
||||||
</MauiXaml>
|
</MauiXaml>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
|
@ -1,13 +1,15 @@
|
||||||
namespace Neighbourhood.omg.lol {
|
using System.Reflection;
|
||||||
|
|
||||||
|
namespace Neighbourhood.omg.lol {
|
||||||
public partial class App : Application {
|
public partial class App : Application {
|
||||||
|
|
||||||
public static string Name { get; set; }
|
public static Assembly Assembly { get; } = Assembly.GetExecutingAssembly();
|
||||||
public static string Version { get; set; }
|
public static string Name { get; } = App.Assembly.GetName().Name!;
|
||||||
|
public static string Version { get; } = App.Assembly.GetName().Version!.ToString();
|
||||||
|
|
||||||
public App(NavigatorService navigatorService) {
|
public App(NavigatorService navigatorService) {
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
|
|
||||||
//MainPage = new AppShell();
|
|
||||||
NavigatorService = navigatorService;
|
NavigatorService = navigatorService;
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,6 +7,5 @@ public partial class AppShell : Shell
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
|
|
||||||
Routing.RegisterRoute(nameof(LoginWebViewPage), typeof(LoginWebViewPage));
|
Routing.RegisterRoute(nameof(LoginWebViewPage), typeof(LoginWebViewPage));
|
||||||
Routing.RegisterRoute(nameof(EphemeralWebPage), typeof(EphemeralWebPage));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,6 +1,4 @@
|
||||||
using Microsoft.AspNetCore.Components;
|
|
||||||
using Microsoft.AspNetCore.Components.Authorization;
|
using Microsoft.AspNetCore.Components.Authorization;
|
||||||
using System.Diagnostics;
|
|
||||||
using System.Web;
|
using System.Web;
|
||||||
using Microsoft.Extensions.Configuration;
|
using Microsoft.Extensions.Configuration;
|
||||||
|
|
|
@ -1,7 +1,4 @@
|
||||||
using Microsoft.AspNetCore.Components;
|
using Microsoft.AspNetCore.Components.WebView;
|
||||||
using Microsoft.AspNetCore.Components.WebView;
|
|
||||||
using Microsoft.AspNetCore.Components.WebView.Maui;
|
|
||||||
using System.Diagnostics;
|
|
||||||
|
|
||||||
namespace Neighbourhood.omg.lol {
|
namespace Neighbourhood.omg.lol {
|
||||||
public partial class MainPage : ContentPage {
|
public partial class MainPage : ContentPage {
|
Loading…
Reference in a new issue