Skip to content

Commit 05fed9b

Browse files
committed
Code cs file isolation
1 parent 708d54f commit 05fed9b

28 files changed

+1388
-1288
lines changed

src/Component/AppBar.razor.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
namespace TomAndJerry.Component;
2+
3+
public partial class AppBar
4+
{
5+
6+
}

src/Component/Footer.razor.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
namespace TomAndJerry.Component;
2+
3+
public partial class Footer
4+
{
5+
6+
}

src/Component/Giscus.razor.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
namespace TomAndJerry.Component;
2+
3+
public partial class Giscus
4+
{
5+
6+
}

src/Component/LottieAnimation.razor

Lines changed: 0 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -3,82 +3,3 @@
33

44
<div id="@ContainerId" style="width:@Width; height:@Height; @AdditionalStyles"></div>
55

6-
@code {
7-
[Parameter] public string AnimationPath { get; set; } = "";
8-
[Parameter] public string Width { get; set; } = "300px";
9-
[Parameter] public string Height { get; set; } = "300px";
10-
[Parameter] public bool Loop { get; set; } = true;
11-
[Parameter] public bool Autoplay { get; set; } = true;
12-
[Parameter] public string Renderer { get; set; } = "svg";
13-
[Parameter] public string AdditionalStyles { get; set; } = "";
14-
[Parameter] public string CssClass { get; set; } = "";
15-
16-
private string ContainerId { get; set; } = "";
17-
private IJSObjectReference? lottieModule;
18-
19-
protected override async Task OnAfterRenderAsync(bool firstRender)
20-
{
21-
if (firstRender && !string.IsNullOrEmpty(AnimationPath))
22-
{
23-
ContainerId = $"lottie-container-{Guid.NewGuid():N}";
24-
await LoadLottieAnimation();
25-
}
26-
}
27-
28-
private async Task LoadLottieAnimation()
29-
{
30-
try
31-
{
32-
lottieModule = await JSRuntime.InvokeAsync<IJSObjectReference>("import", "./js/lottie-interop.js");
33-
await lottieModule.InvokeVoidAsync("loadLottieAnimation", new
34-
{
35-
containerId = ContainerId,
36-
path = AnimationPath,
37-
renderer = Renderer,
38-
loop = Loop,
39-
autoplay = Autoplay
40-
});
41-
}
42-
catch (Exception ex)
43-
{
44-
Console.WriteLine($"Error loading Lottie animation: {ex.Message}");
45-
}
46-
}
47-
48-
public async Task Play()
49-
{
50-
if (lottieModule != null)
51-
{
52-
await lottieModule.InvokeVoidAsync("playAnimation", ContainerId);
53-
}
54-
}
55-
56-
public async Task Pause()
57-
{
58-
if (lottieModule != null)
59-
{
60-
await lottieModule.InvokeVoidAsync("pauseAnimation", ContainerId);
61-
}
62-
}
63-
64-
public async Task Stop()
65-
{
66-
if (lottieModule != null)
67-
{
68-
await lottieModule.InvokeVoidAsync("stopAnimation", ContainerId);
69-
}
70-
}
71-
72-
public async Task SetSpeed(float speed)
73-
{
74-
if (lottieModule != null)
75-
{
76-
await lottieModule.InvokeVoidAsync("setAnimationSpeed", ContainerId, speed);
77-
}
78-
}
79-
80-
public void Dispose()
81-
{
82-
lottieModule?.DisposeAsync();
83-
}
84-
}
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
using Microsoft.AspNetCore.Components;
2+
using Microsoft.JSInterop;
3+
4+
namespace TomAndJerry.Component;
5+
6+
public partial class LottieAnimation : IDisposable
7+
{
8+
[Parameter] public string AnimationPath { get; set; } = "";
9+
[Parameter] public string Width { get; set; } = "300px";
10+
[Parameter] public string Height { get; set; } = "300px";
11+
[Parameter] public bool Loop { get; set; } = true;
12+
[Parameter] public bool Autoplay { get; set; } = true;
13+
[Parameter] public string Renderer { get; set; } = "svg";
14+
[Parameter] public string AdditionalStyles { get; set; } = "";
15+
[Parameter] public string CssClass { get; set; } = "";
16+
17+
private string ContainerId { get; set; } = "";
18+
private IJSObjectReference? lottieModule;
19+
20+
protected override async Task OnAfterRenderAsync(bool firstRender)
21+
{
22+
if (firstRender && !string.IsNullOrEmpty(AnimationPath))
23+
{
24+
ContainerId = $"lottie-container-{Guid.NewGuid():N}";
25+
await LoadLottieAnimation();
26+
}
27+
}
28+
29+
private async Task LoadLottieAnimation()
30+
{
31+
try
32+
{
33+
lottieModule = await JSRuntime.InvokeAsync<IJSObjectReference>("import", "./js/lottie-interop.js");
34+
await lottieModule.InvokeVoidAsync("loadLottieAnimation", new
35+
{
36+
containerId = ContainerId,
37+
path = AnimationPath,
38+
renderer = Renderer,
39+
loop = Loop,
40+
autoplay = Autoplay
41+
});
42+
}
43+
catch (Exception ex)
44+
{
45+
Console.WriteLine($"Error loading Lottie animation: {ex.Message}");
46+
}
47+
}
48+
49+
public async Task Play()
50+
{
51+
if (lottieModule != null)
52+
{
53+
await lottieModule.InvokeVoidAsync("playAnimation", ContainerId);
54+
}
55+
}
56+
57+
public async Task Pause()
58+
{
59+
if (lottieModule != null)
60+
{
61+
await lottieModule.InvokeVoidAsync("pauseAnimation", ContainerId);
62+
}
63+
}
64+
65+
public async Task Stop()
66+
{
67+
if (lottieModule != null)
68+
{
69+
await lottieModule.InvokeVoidAsync("stopAnimation", ContainerId);
70+
}
71+
}
72+
73+
public async Task SetSpeed(float speed)
74+
{
75+
if (lottieModule != null)
76+
{
77+
await lottieModule.InvokeVoidAsync("setAnimationSpeed", ContainerId, speed);
78+
}
79+
}
80+
81+
public void Dispose()
82+
{
83+
lottieModule?.DisposeAsync();
84+
}
85+
}

src/Component/RandomSticker.razor

Lines changed: 0 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -21,70 +21,4 @@ else
2121
</div>
2222
}
2323

24-
@code {
25-
[Parameter] public string CssClass { get; set; } = string.Empty;
26-
[Parameter] public string ImageCssClass { get; set; } = string.Empty;
27-
[Parameter] public string Style { get; set; } = string.Empty;
28-
[Parameter] public string Category { get; set; } = string.Empty;
29-
[Parameter] public bool AutoRefresh { get; set; } = false;
30-
[Parameter] public int RefreshIntervalSeconds { get; set; } = 30;
31-
32-
private Sticker? currentSticker;
33-
private Timer? refreshTimer;
34-
35-
protected override async Task OnInitializedAsync()
36-
{
37-
await LoadRandomStickerAsync();
38-
39-
if (AutoRefresh)
40-
{
41-
refreshTimer = new Timer(async _ => await LoadRandomStickerAsync(), null,
42-
TimeSpan.FromSeconds(RefreshIntervalSeconds),
43-
TimeSpan.FromSeconds(RefreshIntervalSeconds));
44-
}
45-
}
46-
47-
private async Task LoadRandomStickerAsync()
48-
{
49-
try
50-
{
51-
if (!string.IsNullOrEmpty(Category))
52-
{
53-
var allStickers = await StickerService.GetAllStickersAsync();
54-
var categoryStickers = allStickers.Where(s => s.Category.Equals(Category, StringComparison.OrdinalIgnoreCase)).ToList();
55-
if (categoryStickers.Any())
56-
{
57-
var random = new Random();
58-
currentSticker = categoryStickers[random.Next(categoryStickers.Count)];
59-
}
60-
else
61-
{
62-
currentSticker = await StickerService.GetRandomStickerAsync();
63-
}
64-
}
65-
else
66-
{
67-
currentSticker = await StickerService.GetRandomStickerAsync();
68-
}
69-
70-
await InvokeAsync(StateHasChanged);
71-
}
72-
catch (Exception)
73-
{
74-
// Fallback to null, which will show Tom.png
75-
currentSticker = null;
76-
}
77-
}
78-
79-
public async Task RefreshStickerAsync()
80-
{
81-
await LoadRandomStickerAsync();
82-
}
83-
84-
public new void Dispose()
85-
{
86-
refreshTimer?.Dispose();
87-
base.Dispose();
88-
}
89-
}
9024

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
using Microsoft.AspNetCore.Components;
2+
using TomAndJerry.Services;
3+
using TomAndJerry.Model;
4+
5+
namespace TomAndJerry.Component;
6+
7+
public partial class RandomSticker : BaseComponent
8+
{
9+
[Parameter] public string CssClass { get; set; } = string.Empty;
10+
[Parameter] public string ImageCssClass { get; set; } = string.Empty;
11+
[Parameter] public string Style { get; set; } = string.Empty;
12+
[Parameter] public string Category { get; set; } = string.Empty;
13+
[Parameter] public bool AutoRefresh { get; set; } = false;
14+
[Parameter] public int RefreshIntervalSeconds { get; set; } = 30;
15+
16+
private Sticker? currentSticker;
17+
private Timer? refreshTimer;
18+
19+
protected override async Task OnInitializedAsync()
20+
{
21+
await LoadRandomStickerAsync();
22+
23+
if (AutoRefresh)
24+
{
25+
refreshTimer = new Timer(async _ => await LoadRandomStickerAsync(), null,
26+
TimeSpan.FromSeconds(RefreshIntervalSeconds),
27+
TimeSpan.FromSeconds(RefreshIntervalSeconds));
28+
}
29+
}
30+
31+
private async Task LoadRandomStickerAsync()
32+
{
33+
try
34+
{
35+
if (!string.IsNullOrEmpty(Category))
36+
{
37+
var allStickers = await StickerService.GetAllStickersAsync();
38+
var categoryStickers = allStickers.Where(s => s.Category.Equals(Category, StringComparison.OrdinalIgnoreCase)).ToList();
39+
if (categoryStickers.Any())
40+
{
41+
var random = new Random();
42+
currentSticker = categoryStickers[random.Next(categoryStickers.Count)];
43+
}
44+
else
45+
{
46+
currentSticker = await StickerService.GetRandomStickerAsync();
47+
}
48+
}
49+
else
50+
{
51+
currentSticker = await StickerService.GetRandomStickerAsync();
52+
}
53+
54+
await InvokeAsync(StateHasChanged);
55+
}
56+
catch (Exception)
57+
{
58+
// Fallback to null, which will show Tom.png
59+
currentSticker = null;
60+
}
61+
}
62+
63+
public async Task RefreshStickerAsync()
64+
{
65+
await LoadRandomStickerAsync();
66+
}
67+
68+
public new void Dispose()
69+
{
70+
refreshTimer?.Dispose();
71+
base.Dispose();
72+
}
73+
}

0 commit comments

Comments
 (0)