Skip to content

Commit ef1eddd

Browse files
authored
Merge pull request #56 from pavel-zhur/feature/chords-fix
Feature/chords fix
2 parents ac5e64b + 75d9ef9 commit ef1eddd

File tree

20 files changed

+195
-206
lines changed

20 files changed

+195
-206
lines changed

HarmonyDB and OneShelf.sln

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -209,9 +209,9 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "OneShelf.Videos", "OneShelf
209209
EndProject
210210
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OneShelf.Videos.App", "OneShelf.Videos\OneShelf.Videos.App\OneShelf.Videos.App.csproj", "{99134E7C-CE2F-4641-A9E3-B961F76307F0}"
211211
EndProject
212-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OneShelf.Videos.Database", "OneShelf.Videos\OneShelf.Videos.Database\OneShelf.Videos.Database.csproj", "{D702C117-2C9A-44E0-B428-30371616FBAE}"
212+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OneShelf.Videos.Database", "OneShelf.Videos\OneShelf.Videos.Database\OneShelf.Videos.Database.csproj", "{D702C117-2C9A-44E0-B428-30371616FBAE}"
213213
EndProject
214-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OneShelf.Videos.BusinessLogic", "OneShelf.Videos\OneShelf.Videos.BusinessLogic\OneShelf.Videos.BusinessLogic.csproj", "{76A8BAAB-7065-45F8-82E8-E188D4C27EB3}"
214+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OneShelf.Videos.BusinessLogic", "OneShelf.Videos\OneShelf.Videos.BusinessLogic\OneShelf.Videos.BusinessLogic.csproj", "{76A8BAAB-7065-45F8-82E8-E188D4C27EB3}"
215215
EndProject
216216
Global
217217
GlobalSection(SolutionConfigurationPlatforms) = preSolution

HarmonyDB.Common/HarmonyDB.Common.Representations.OneShelf/NodeHtml.cs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System.Text;
22
using System.Text.Json.Serialization;
3+
using OneShelf.Common;
34

45
namespace HarmonyDB.Common.Representations.OneShelf;
56

@@ -177,4 +178,24 @@ internal override void AppendHtmlTo(StringBuilder builder, RepresentationSetting
177178
{
178179
return TraverseAll().Count();
179180
}
181+
182+
public void Fix0_Compress()
183+
{
184+
foreach (var nodeCollectionBase in TraverseAll().Select(x => x.element).OfType<NodeCollectionBase>().ToList())
185+
{
186+
var newChildren = nodeCollectionBase.Children.ToChunks(x => x.NodeText != null)
187+
.SelectMany(c =>
188+
!c.criterium
189+
? c.chunk
190+
: new NodeText(string.Join(string.Empty, c.chunk.Select(x => x.NodeText!.Text))).AsChild()
191+
.Once())
192+
.ToList();
193+
194+
if (newChildren.Count != nodeCollectionBase.Children.Count)
195+
{
196+
nodeCollectionBase.Children.Clear();
197+
nodeCollectionBase.Children.AddRange(newChildren);
198+
}
199+
}
200+
}
180201
}

HarmonyDB.Index/HarmonyDB.Index.Api/Functions/V1/GetSongs.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ async Task<List<Chords>> Process(int sourceIndex, IReadOnlyCollection<string> ex
3535
.Where(x => externalIds.Contains(x.Key) && x.Key == x.Value.ExternalId && sourceIndex == _downstreamApiClient.GetDownstreamSourceIndexBySourceKey(x.Value.Source))
3636
.Select(x =>
3737
{
38+
x.Value.Output.Fix0_Compress();
3839
x.Value.Source = _downstreamApiClient.GetSourceTitle(x.Value.Source);
3940
return x.Value;
4041
})

HarmonyDB.Index/HarmonyDB.Index.Api/Services/CommonExecutions.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ public async Task<GetSongResponse> GetSong(string externalId)
5555
var sourceIndex = _downstreamApiClient.GetDownstreamSourceIndexByExternalId(externalId);
5656
var getSongResponse = await _downstreamApiClient.V1GetSong(sourceIndex, externalId);
5757
getSongResponse.Song.Source = _downstreamApiClient.GetSourceTitle(getSongResponse.Song.Source);
58+
getSongResponse.Song.Output.Fix0_Compress();
5859
return getSongResponse;
5960
}
6061
}
Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,8 @@
1-
using DnetIndexedDb;
2-
3-
namespace OneShelf.Frontend.Web.IndexedDb;
1+
namespace OneShelf.Frontend.Web.IndexedDb;
42

53
public class IndexedItem
64
{
7-
[IndexDbKey]
85
public required string Key { get; init; }
96

10-
public required int Version { get; init; }
11-
127
public required string Contents { get; init; }
138
}

OneShelf.Frontend/OneShelf.Frontend.Web/IndexedDb/IndexedItemKey.cs

Lines changed: 0 additions & 11 deletions
This file was deleted.
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
namespace OneShelf.Frontend.Web.IndexedDb;
2+
3+
public enum IndexedItemType
4+
{
5+
Chords,
6+
Search,
7+
Progression,
8+
}

OneShelf.Frontend/OneShelf.Frontend.Web/IndexedDb/MyIndexedDb.cs

Lines changed: 0 additions & 12 deletions
This file was deleted.
Binary file not shown.

OneShelf.Frontend/OneShelf.Frontend.Web/Pages/Index.razor

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
@inject CollectionNavigation CollectionNavigation
66
@inject CollectionIndexProvider CollectionIndexProvider
77
@inject IllustrationsProvider IllustrationsProvider
8+
@inject ChordsCacheLoader ChordsCacheLoader
89

910
<PageTitle>Один Шкаф</PageTitle>
1011

@@ -111,6 +112,7 @@ else
111112
{
112113
CollectionIndexProvider.MightSync();
113114
IllustrationsProvider.MaybeInit();
115+
ChordsCacheLoader.StartDelayed();
114116
}
115117

116118
return base.OnAfterRenderAsync(firstRender);

OneShelf.Frontend/OneShelf.Frontend.Web/Pages/Print.razor

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,11 @@ else
4646
}
4747
<div>
4848
<span>Люблю:</span>
49-
<input type="radio" name="alteration" id="preferSharp" value="@NoteAlteration.Sharp" checked="@(_preferences.Alteration == NoteAlteration.Sharp)" @onchange="e => SetAlteration(NoteAlteration.Sharp)"/>
49+
<input type="radio" name="alteration" id="preferSharp" value="@NoteAlteration.Sharp" checked="@(_preferences.Alteration == NoteAlteration.Sharp)" @onchange="() => SetAlteration(NoteAlteration.Sharp)"/>
5050
<label for="preferSharp">###</label>
51-
<input type="radio" name="alteration" id="preferFlat" value="@NoteAlteration.Flat" checked="@(_preferences.Alteration == NoteAlteration.Flat)" @onchange="e => SetAlteration(NoteAlteration.Flat)"/>
51+
<input type="radio" name="alteration" id="preferFlat" value="@NoteAlteration.Flat" checked="@(_preferences.Alteration == NoteAlteration.Flat)" @onchange="() => SetAlteration(NoteAlteration.Flat)"/>
5252
<label for="preferFlat">bbb</label>
53-
<input type="radio" name="alteration" id="preferNone" value="null" checked="@(_preferences.Alteration == null)" @onchange="e => SetAlteration(null)"/>
53+
<input type="radio" name="alteration" id="preferNone" value="null" checked="@(_preferences.Alteration == null)" @onchange="() => SetAlteration(null)"/>
5454
<label for="preferNone">Что есть, то есть</label>
5555
</div>
5656
<div>

OneShelf.Frontend/OneShelf.Frontend.Web/Pages/ReleaseNotes.razor

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,16 @@
22

33
<h1>Один шкаф</h1>
44

5+
<h3>Версия 1.1</h3>
6+
7+
<div>
8+
<p>1 октября 2024.</p>
9+
<ul>
10+
<li>Исправлено офлайн-хранилище аккордов.</li>
11+
<li>Автоскачивание аккордов через полминуты после инициализации.</li>
12+
</ul>
13+
</div>
14+
515
<h3>Версия 1.0</h3>
616

717
<div>

OneShelf.Frontend/OneShelf.Frontend.Web/Program.cs

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
using System.Text.Json.Serialization;
22
using BlazorApplicationInsights;
33
using Blazored.LocalStorage;
4-
using DnetIndexedDb;
5-
using DnetIndexedDb.Fluent;
6-
using DnetIndexedDb.Models;
74
using HarmonyDB.Index.Analysis;
85
using Microsoft.AspNetCore.Components.Web;
96
using Microsoft.AspNetCore.Components.WebAssembly.Hosting;
@@ -14,6 +11,7 @@
1411
using OneShelf.Frontend.Web.Interop;
1512
using OneShelf.Frontend.Web.Models;
1613
using OneShelf.Frontend.Web.Services;
14+
using SpawnDev.BlazorJS;
1715

1816
var builder = WebAssemblyHostBuilder.CreateDefault(args);
1917
builder.RootComponents.Add<App>("#app");
@@ -48,21 +46,9 @@
4846
.AddBlazorApplicationInsights(config =>
4947
{
5048
config.ConnectionString = builder.Configuration.GetSection(nameof(FrontendOptions)).Get<FrontendOptions>()!.AppInsightsConnectionString;
51-
});
52-
53-
builder.Services
54-
.AddIndexedDbDatabase<MyIndexedDb>(options =>
55-
{
56-
var model = new IndexedDbDatabaseModel()
57-
.WithName("OneShelfDatabase")
58-
.WithVersion(6)
59-
.WithModelId(0);
60-
61-
model.AddStore<IndexedItem>();
62-
model.AddStore<IndexedItemKey>();
63-
64-
options.UseDatabase(model);
65-
}, ServiceLifetime.Singleton);
49+
})
50+
.AddTransient<MyIndexedDb>()
51+
.AddBlazorJSRuntime();
6652

6753
var host = builder.Build();
6854

OneShelf.Frontend/OneShelf.Frontend.Web/Services/CacheLoaderBase.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,10 +93,13 @@ public virtual void Dispose()
9393

9494
private async void Go(CancellationToken token)
9595
{
96+
Logger.LogInformation("Chords loading started.");
97+
9698
try
9799
{
98100
await Work(token);
99101
OnProgressChanged(null);
102+
Logger.LogInformation("Chords loading finished successfully.");
100103
}
101104
catch (TaskCanceledException)
102105
{

OneShelf.Frontend/OneShelf.Frontend.Web/Services/ChordsCacheLoader.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ namespace OneShelf.Frontend.Web.Services;
44

55
public class ChordsCacheLoader : CacheLoaderBase
66
{
7+
private static readonly TimeSpan FirstDelay = TimeSpan.FromSeconds(20);
8+
79
private readonly CollectionIndexProvider _collectionIndexProvider;
810
private readonly DataProvider _dataProvider;
911
private readonly Api _api;
@@ -65,4 +67,10 @@ protected override async Task Work(CancellationToken token)
6567
await Task.Delay(300, token);
6668
}
6769
}
70+
71+
public async void StartDelayed()
72+
{
73+
await Task.Delay(FirstDelay);
74+
Start();
75+
}
6876
}

0 commit comments

Comments
 (0)