Skip to content

Commit

Permalink
Render markdown in run comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Heufneutje committed Apr 7, 2024
1 parent 7a66f61 commit ae1505c
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public static IServiceCollection AddSpeedrunTrackerServices(this IServiceCollect

void ConfigureHttpClient(HttpClient client)
{
client.BaseAddress = new Uri(config["speedrun-dot-com:api-base-address"]);
client.BaseAddress = new Uri($"{config["speedrun-dot-com:base-address"]}{config["speedrun-dot-com:api-address"]}");
client.DefaultRequestHeaders.Add("User-Agent", $"Heufneutje-SpeedrunTracker/{App.Version}");
}
}
Expand Down
11 changes: 10 additions & 1 deletion SpeedrunTracker/Resources/Styles/Styles.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:material="http://schemas.enisn-projects.io/dotnet/maui/uraniumui/material"
xmlns:toolkit="http://schemas.microsoft.com/dotnet/2022/maui/toolkit">
xmlns:toolkit="http://schemas.microsoft.com/dotnet/2022/maui/toolkit"
xmlns:markdown="clr-namespace:Indiko.Maui.Controls.Markdown;assembly=Indiko.Maui.Controls.Markdown">

<Style TargetType="ActivityIndicator">
<Setter Property="Color" Value="{AppThemeBinding Light={StaticResource Primary}, Dark={StaticResource White}}" />
Expand Down Expand Up @@ -283,6 +284,14 @@
<Setter Property="StrokeThickness" Value="1" />
</Style>

<Style TargetType="markdown:MarkdownView">
<Setter Property="TextColor" Value="{AppThemeBinding Light={StaticResource Gray900}, Dark={StaticResource White}}" />
<Setter Property="BackgroundColor" Value="Transparent" />
<Setter Property="PlaceholderBackgroundColor" Value="Transparent" />
<Setter Property="TextFontSize" Value="14" />
<Setter Property="TextFontFace" Value="OpenSansRegular" />
</Style>

<Style x:Key="FlyoutItemStyle" TargetType="Grid">
<Setter Property="VisualStateManager.VisualStateGroups">
<VisualStateGroupList>
Expand Down
5 changes: 3 additions & 2 deletions SpeedrunTracker/SpeedrunTracker.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,15 @@
<ItemGroup>
<PackageReference Include="CommunityToolkit.Maui" Version="7.0.1" />
<PackageReference Include="CommunityToolkit.Mvvm" Version="8.2.2" />
<PackageReference Include="Indiko.Maui.Controls.Markdown" Version="1.0.1" />
<PackageReference Include="Macross.Json.Extensions" Version="3.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="8.0.0" />
<PackageReference Include="Microsoft.Maui.Controls" Version="8.0.10" />
<PackageReference Include="Microsoft.Maui.Controls" Version="8.0.14" />
<PackageReference Include="RangedObservableCollection" Version="1.0.1" />
<PackageReference Include="Refit" Version="7.0.0" />
<PackageReference Include="Refit.HttpClientFactory" Version="7.0.0" />
<PackageReference Include="sqlite-net-pcl" Version="1.8.116" />
<PackageReference Include="sqlite-net-pcl" Version="1.9.172" />
<PackageReference Include="SQLitePCLRaw.bundle_green" Version="2.1.8" />
</ItemGroup>

Expand Down
19 changes: 17 additions & 2 deletions SpeedrunTracker/ViewModels/RunDetailsViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using CommunityToolkit.Mvvm.Input;
using Microsoft.Extensions.Configuration;
using SpeedrunTracker.Extensions;
using SpeedrunTracker.Navigation;
using System.Collections.ObjectModel;
Expand All @@ -11,7 +12,7 @@ public class RunDetailsViewModel : BaseShareableViewModel
private readonly IBrowserService _browserService;
private readonly IUserService _userService;
private readonly IEmbedService _embedService;

private readonly IConfiguration _config;
private RunDetails _runDetails;

public RunDetails RunDetails
Expand All @@ -30,6 +31,7 @@ public RunDetails RunDetails
NotifyPropertyChanged(nameof(HasTrophyAsset));
NotifyPropertyChanged(nameof(StatusImage));
NotifyPropertyChanged(nameof(StatusDescription));
NotifyPropertyChanged(nameof(RunComment));

if (value.Run.Videos?.Links != null)
VideoUrls.AddRange(_embedService.GetEmbeddableUrls(value.Run.Videos));
Expand All @@ -44,6 +46,18 @@ public RunDetails RunDetails

public bool HasTrophyAsset => !string.IsNullOrEmpty(_runDetails?.TrophyAsset?.Uri);

private string _runComment;

public string RunComment
{
get
{
if (_runComment == null)
_runComment = RunDetails?.Run?.Comment?.Replace("(/static/blob", $"({_config["speedrun-dot-com:base-address"]}static/blob");
return _runComment;
}
}

private User _selectedPlayer;

public User SelectedPlayer
Expand Down Expand Up @@ -117,11 +131,12 @@ public string StatusDescription

public override ShareDetails ShareDetails => new(RunDetails?.Run?.Weblink, Title);

public RunDetailsViewModel(IBrowserService browserService, IUserService userService, IEmbedService embedService, IShareService shareService, IToastService toastService) : base(shareService, toastService)
public RunDetailsViewModel(IBrowserService browserService, IUserService userService, IEmbedService embedService, IShareService shareService, IToastService toastService, IConfiguration config) : base(shareService, toastService)
{
_browserService = browserService;
_userService = userService;
_embedService = embedService;
_config = config;
VideoUrls = new RangedObservableCollection<EmbeddableUrl>();
}

Expand Down
4 changes: 3 additions & 1 deletion SpeedrunTracker/Views/RunDetailsPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:controls="clr-namespace:SpeedrunTracker.Controls"
xmlns:viewmodels="clr-namespace:SpeedrunTracker.ViewModels"
xmlns:markdown="clr-namespace:Indiko.Maui.Controls.Markdown;assembly=Indiko.Maui.Controls.Markdown"
x:DataType="viewmodels:RunDetailsViewModel"
x:Class="SpeedrunTracker.Views.RunDetailsPage"
Title="{Binding Title}"
Expand Down Expand Up @@ -34,7 +35,8 @@
<Button Text="Open External Player" Command="{Binding ShowVideoCommand}" />
</VerticalStackLayout>
<Label Text="No Video Available" IsVisible="{Binding Path=HasVideo, Converter={StaticResource InverseBoolConverter}}" Margin="5,-5,0,5" />
<controls:RunPropertyControl Title="Description" Value="{Binding RunDetails.Run.Comment}" IsVisible="{Binding RunDetails.Run.Comment, Converter={StaticResource IsNotNullConverter}}" ImageSource="comment" />
<controls:RunPropertyControl Title="Description" IsVisible="{Binding RunComment, Converter={StaticResource IsNotNullConverter}}" ImageSource="comment" IsValueVisible="False" />
<markdown:MarkdownView MarkdownText="{Binding RunComment}" IsVisible="{Binding RunComment, Converter={StaticResource IsNotNullConverter}}" Margin="5,-5,0,5" />
</VerticalStackLayout>
</Border>

Expand Down
3 changes: 2 additions & 1 deletion SpeedrunTracker/appsettings.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"speedrun-dot-com": {
"api-base-address": "https://www.speedrun.com/api/v1"
"base-address": "https://www.speedrun.com/",
"api-address": "api/v1"
},
"storage": {
"db-name": "speedruntracker.db3"
Expand Down

0 comments on commit ae1505c

Please sign in to comment.