generated from NetCoreTemplates/razor-ssg
/
Top.cshtml
71 lines (58 loc) · 1.77 KB
/
Top.cshtml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
@page "/top"
@inherits ServiceStack.Mvc.RazorPage
@attribute [RenderStatic]
@{
ViewBag.Title = "Top Images";
}
@inject UserState UserState
@{
const int GridColumns = 4;
SearchArtifacts request = new();
List<Artifact> results = new();
HashSet<int> resultIds = new();
bool hasMore;
ApiResult<QueryResponse<ArtifactResult>> api = new();
GalleryResults GalleryResults = new() { GridColumns = GridColumns };
request.Skip = 0;
request.Take = UserState.StaticTake;
request.Show = "top";
api = await Gateway.ApiAsync(request);
clearResults();
if (api.Succeeded)
{
if (api.Response?.Results != null)
{
addResults(api.Response.Results);
}
}
void setResults(IEnumerable<Artifact> newResults)
{
results = newResults.ToList();
GalleryResults = X.Apply(GalleryResults.Clone(), x => x.Artifacts = results.ShuffleGridArtifacts(GridColumns).ToList());
}
void clearResults()
{
results.Clear();
resultIds.Clear();
}
void addResults(List<ArtifactResult> artifacts, bool reset = false)
{
if (reset)
clearResults();
hasMore = artifacts.Count >= request.Take;
foreach (var artifact in artifacts)
{
if (resultIds.Contains(artifact.Id))
continue;
resultIds.Add(artifact.Id);
results.Add(artifact);
}
setResults(results);
}
}
<div id="albums" class="mx-auto px-6 lg:px-8">
<div class="mb-8 mx-auto max-w-2xl text-center">
<h1 class="max-w-4xl font-display text-4xl font-semibold tracking-tight text-slate-50 sm:text-5xl lg:text-6xl">Top Images</h1>
</div>
@await Html.PartialAsync("Gallery", GalleryResults)
</div>