From b074b9d453dcbc4242b6708d8abe9362649b596e Mon Sep 17 00:00:00 2001 From: Gordon Pedersen Date: Thu, 25 Jul 2024 13:59:57 +1000 Subject: [PATCH] Added a "toast" message when copying a paste --- Components/PasteCard.razor | 13 +++++++++++-- MauiProgram.cs | 8 ++++++-- Neighbourhood.omg.lol.csproj | 1 + Platforms/Windows/Package.appxmanifest | 24 +++++++++++++++++++++++- 4 files changed, 41 insertions(+), 5 deletions(-) diff --git a/Components/PasteCard.razor b/Components/PasteCard.razor index 7c26111..f8e5273 100644 --- a/Components/PasteCard.razor +++ b/Components/PasteCard.razor @@ -1,4 +1,5 @@ -@inject IJSRuntime JS +@using CommunityToolkit.Maui.Alerts +@inject IJSRuntime JS
@* TODO: link to paste view *@ @@ -13,7 +14,7 @@ { } - + @@ -59,4 +60,12 @@ Subject = Paste!.Title }); } + + public async Task CopyPaste() { + if(Paste != null && !string.IsNullOrEmpty(Paste?.Content)) { + await Clipboard.Default.SetTextAsync(Paste?.Content); + var toast = Toast.Make("Copied to clipboard"); + await toast.Show(); + } + } } diff --git a/MauiProgram.cs b/MauiProgram.cs index 23d0025..e83f99d 100644 --- a/MauiProgram.cs +++ b/MauiProgram.cs @@ -1,4 +1,5 @@ -using Microsoft.AspNetCore.Components.Authorization; +using CommunityToolkit.Maui; +using Microsoft.AspNetCore.Components.Authorization; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Logging; @@ -7,7 +8,10 @@ namespace Neighbourhood.omg.lol { public static MauiApp CreateMauiApp() { var builder = MauiApp.CreateBuilder(); builder - .UseMauiApp(); + .UseMauiApp() + .UseMauiCommunityToolkit(options => { + options.SetShouldEnableSnackbarOnWindows(true); + }); builder.Services.AddMauiBlazorWebView(); builder.Services.AddTransient(); diff --git a/Neighbourhood.omg.lol.csproj b/Neighbourhood.omg.lol.csproj index 9ccb835..ab2c7cb 100644 --- a/Neighbourhood.omg.lol.csproj +++ b/Neighbourhood.omg.lol.csproj @@ -125,6 +125,7 @@ + diff --git a/Platforms/Windows/Package.appxmanifest b/Platforms/Windows/Package.appxmanifest index 29f6bf8..a1e73f5 100644 --- a/Platforms/Windows/Package.appxmanifest +++ b/Platforms/Windows/Package.appxmanifest @@ -4,7 +4,9 @@ xmlns:uap="http://schemas.microsoft.com/appx/manifest/uap/windows10" xmlns:mp="http://schemas.microsoft.com/appx/2014/phone/manifest" xmlns:rescap="http://schemas.microsoft.com/appx/manifest/foundation/windows10/restrictedcapabilities" - IgnorableNamespaces="uap rescap"> + xmlns:com="http://schemas.microsoft.com/appx/manifest/com/windows10" + xmlns:desktop="http://schemas.microsoft.com/appx/manifest/desktop/windows10" + IgnorableNamespaces="uap rescap com desktop"> @@ -36,6 +38,26 @@ + + + + + + + + + + + + + + + + + + + +