Skip to content

Commit 62d36da

Browse files
committed
Cache alternative commit hash
1 parent 96e2acf commit 62d36da

File tree

1 file changed

+20
-3
lines changed

1 file changed

+20
-3
lines changed

src/App/Lab/CommitHashView.razor

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,13 @@ title="@GetTitle()">@Commit.ShortHash</a>
2929
private const string dateFormat = "MMM d, yyyy, HH:mm";
3030
private readonly AsyncLock loading = new();
3131
private CommitInfo? commitInfo;
32-
private (CommitLink Result, CommitLink For)? alternativeCommit;
32+
private AlternativeCommitInfo? alternativeCommit;
33+
34+
private readonly struct AlternativeCommitInfo
35+
{
36+
public required CommitLink Result { get; init; }
37+
public required CommitLink For { get; init; }
38+
}
3339

3440
[Parameter, EditorRequired]
3541
public bool Enabled { get; init; }
@@ -174,6 +180,12 @@ title="@GetTitle()">@Commit.ShortHash</a>
174180

175181
private async Task LoadAlternativeInfoAsync()
176182
{
183+
var saveKey = SaveKey + "_AlternativeCommitLink";
184+
if (alternativeCommit is null)
185+
{
186+
alternativeCommit = await LocalStorage.GetItemAsync<AlternativeCommitInfo?>(saveKey);
187+
}
188+
177189
if ((AlternativeRepoUrl is null || AlternativeRepoUrl == Commit.RepoUrl) &&
178190
(AlternativeCommitHash is null || AlternativeCommitHash == Commit.Hash))
179191
{
@@ -193,15 +205,20 @@ title="@GetTitle()">@Commit.ShortHash</a>
193205
}
194206
else
195207
{
196-
alternativeCommit = (Result: new CommitLink
208+
alternativeCommit = new()
209+
{
210+
Result = new CommitLink
197211
{
198212
RepoUrl = AlternativeRepoUrl ?? Commit.RepoUrl,
199213
Hash = altCommitHash,
200214
},
201-
For: Commit);
215+
For = Commit,
216+
};
202217
}
203218

204219
StateHasChanged();
220+
221+
await LocalStorage.SetItemAsync(saveKey, alternativeCommit);
205222
}
206223

207224
private static bool Matches(CommitLink commit, CommitInfo? info)

0 commit comments

Comments
 (0)