Skip to content

Commit 0f6d806

Browse files
Tom BrewerTom Brewer
authored andcommitted
feat: add guid generator in tools
adds a way to easily generate guids in app
1 parent 262a625 commit 0f6d806

File tree

6 files changed

+73
-0
lines changed

6 files changed

+73
-0
lines changed

Apollo.Components/Editor/ToolsMenu.razor

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,21 @@
11
@using Apollo.Components.Infrastructure.MessageBus
22
@using Apollo.Components.NuGet.Commands
3+
@using Apollo.Components.Tools.Commands
34
@using Apollo.Components.Theme
45
@using MouseEvent = MudBlazor.MouseEvent
56

67
<MudMenu Label="Tools" Dense ActivationEvent="MouseEvent.MouseOver">
78
<MudMenuItem Icon="@ApolloIcons.NuGet" OnClick="@(async () => await Bus.PublishAsync(new OpenNuGetDialog()))">
89
NuGet Packages
910
</MudMenuItem>
11+
<MudMenu StartIcon="@ApolloIcons.Guid" Label="Generate GUID">
12+
<MudMenuItem Icon="@ApolloIcons.Guid" OnClick="@(async () => await Bus.PublishAsync(new GenerateGuid()))">
13+
GUID
14+
</MudMenuItem>
15+
<MudMenuItem Icon="@ApolloIcons.GuidV7" OnClick="@(async () => await Bus.PublishAsync(new GenerateGuidV7()))">
16+
GUID v7 (Timestamp)
17+
</MudMenuItem>
18+
</MudMenu>
1019
</MudMenu>
1120

1221
@code {

Apollo.Components/Theme/ApolloIcons.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,4 +117,8 @@ public static class ApolloIcons
117117
public const string Search = Icons.Material.TwoTone.Search;
118118

119119
public const string Verified = Icons.Material.TwoTone.Verified;
120+
121+
public const string Guid = Icons.Material.TwoTone.Fingerprint;
122+
123+
public const string GuidV7 = Icons.Material.TwoTone.Schedule;
120124
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
namespace Apollo.Components.Tools.Commands;
2+
3+
public record GenerateGuid();
4+
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
namespace Apollo.Components.Tools.Commands;
2+
3+
public record GenerateGuidV7();
4+
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
using Apollo.Components.Infrastructure.MessageBus;
2+
using Apollo.Components.Shared.ApolloNotificationBar;
3+
using Apollo.Components.Tools.Commands;
4+
using MudBlazor;
5+
6+
namespace Apollo.Components.Tools.Consumers;
7+
8+
public class GuidGenerator : IConsumer<GenerateGuid>
9+
{
10+
private readonly IJsApiService _jsApiService;
11+
private readonly ISnackbar _snackbar;
12+
13+
public GuidGenerator(IJsApiService jsApiService, ISnackbar snackbar)
14+
{
15+
_jsApiService = jsApiService;
16+
_snackbar = snackbar;
17+
}
18+
19+
public async Task Consume(GenerateGuid message)
20+
{
21+
var guid = Guid.NewGuid().ToString();
22+
await _jsApiService.CopyToClipboardAsync(guid);
23+
_snackbar.AddApolloNotification($"Copied {guid} to clipboard!", Severity.Success);
24+
}
25+
}
26+
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
using Apollo.Components.Infrastructure.MessageBus;
2+
using Apollo.Components.Shared.ApolloNotificationBar;
3+
using Apollo.Components.Tools.Commands;
4+
using MudBlazor;
5+
6+
namespace Apollo.Components.Tools.Consumers;
7+
8+
public class GuidV7Generator : IConsumer<GenerateGuidV7>
9+
{
10+
private readonly IJsApiService _jsApiService;
11+
private readonly ISnackbar _snackbar;
12+
13+
public GuidV7Generator(IJsApiService jsApiService, ISnackbar snackbar)
14+
{
15+
_jsApiService = jsApiService;
16+
_snackbar = snackbar;
17+
}
18+
19+
public async Task Consume(GenerateGuidV7 message)
20+
{
21+
var guid = Guid.CreateVersion7().ToString();
22+
await _jsApiService.CopyToClipboardAsync(guid);
23+
_snackbar.AddApolloNotification($"Copied {guid} to clipboard!", Severity.Success);
24+
}
25+
}
26+

0 commit comments

Comments
 (0)