Skip to content

Commit a7fa4d7

Browse files
committed
Admin post list virtual scroll
1 parent 8e634ab commit a7fa4d7

File tree

2 files changed

+53
-41
lines changed

2 files changed

+53
-41
lines changed

src/Blogifier.Admin/Pages/Account/Login.razor.cs

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using Blogifier.Shared;
22
using Microsoft.AspNetCore.WebUtilities;
3+
using System;
34
using System.Linq;
45
using System.Net.Http.Json;
56
using System.Threading.Tasks;
@@ -11,18 +12,18 @@ public partial class Login
1112
public bool showError = false;
1213
public LoginModel model = new LoginModel { Email = "", Password = "" };
1314

14-
public async Task LoginUser()
15+
public async Task LoginUser()
1516
{
16-
var returnUrl = "admin/";
17-
var uri = _navigationManager.ToAbsoluteUri(_navigationManager.Uri);
17+
var returnUrl = "admin/";
18+
var uri = _navigationManager.ToAbsoluteUri(_navigationManager.Uri);
1819

19-
if (QueryHelpers.ParseQuery(uri.Query).TryGetValue("returnUrl", out var param))
20-
returnUrl = param.First();
21-
22-
if(returnUrl.StartsWith("http"))
20+
if (QueryHelpers.ParseQuery(uri.Query).TryGetValue("returnUrl", out var param))
21+
returnUrl = param.First();
22+
23+
if(!IsLocalUrl(returnUrl))
2324
returnUrl = "admin/";
2425

25-
var result = await Http.PostAsJsonAsync<LoginModel>("api/author/login", model);
26+
var result = await Http.PostAsJsonAsync<LoginModel>("api/author/login", model);
2627

2728
if (result.IsSuccessStatusCode)
2829
{
@@ -35,5 +36,14 @@ public async Task LoginUser()
3536
StateHasChanged();
3637
}
3738
}
39+
40+
static bool IsLocalUrl(string url)
41+
{
42+
if(url.Contains("//"))
43+
return false;
44+
45+
Uri result;
46+
return Uri.TryCreate(url, UriKind.Relative, out result);
47+
}
3848
}
3949
}

src/Blogifier.Admin/Pages/Blog/PostsView.razor

Lines changed: 35 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -81,26 +81,27 @@
8181

8282
@if (Posts != null && Posts.Count > 0)
8383
{
84-
<ul class="list" aria-label="posts">
85-
<Virtualize Items="Posts" Context="post">
86-
87-
@{
88-
string pubDate = post.Published > DateTime.MinValue ? post.Published.ToFriendlyShortDateString() : @_localizer["draft"];
89-
string pubStatus = post.Published > DateTime.MinValue ? "published" : "";
90-
string featured = post.IsFeatured ? "featured" : "";
91-
}
92-
93-
<li class="list-item">
94-
<label class="list-check form-check" data-bs-toggle="tooltip" title="@_localizer["select"]">
95-
<input type="checkbox" @bind="post.Selected" class="list-check-input form-check-input">
96-
</label>
97-
<a class="list-title -link" href="/admin/editor/@post.Slug">
98-
@post.Title
99-
</a>
100-
<span class="list-text -nowrap ms-auto">
101-
@pubDate
102-
</span>
103-
<button class="list-btn" @onclick="(async () => await Publish(post))">
84+
<div style="height:650px;overflow-y:scroll">
85+
<ul class="list" aria-label="posts">
86+
<Virtualize Items="Posts" Context="post">
87+
88+
@{
89+
string pubDate = post.Published > DateTime.MinValue ? post.Published.ToFriendlyShortDateString() : @_localizer["draft"];
90+
string pubStatus = post.Published > DateTime.MinValue ? "published" : "";
91+
string featured = post.IsFeatured ? "featured" : "";
92+
}
93+
94+
<li class="list-item">
95+
<label class="list-check form-check" data-bs-toggle="tooltip" title="@_localizer["select"]">
96+
<input type="checkbox" @bind="post.Selected" class="list-check-input form-check-input">
97+
</label>
98+
<a class="list-title -link" href="/admin/editor/@post.Slug">
99+
@post.Title
100+
</a>
101+
<span class="list-text -nowrap ms-auto">
102+
@pubDate
103+
</span>
104+
<button class="list-btn" @onclick="(async () => await Publish(post))">
104105
@if (@pubStatus == "published")
105106
{
106107
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" fill="currentColor" class="bi bi-check link-success" viewBox="0 0 16 16" data-bs-toggle="tooltip" title="@_localizer["published"]">
@@ -113,8 +114,8 @@
113114
<path d="M6 12.5C6 11.6716 6.67157 11 7.5 11H16.5C17.3284 11 18 11.6716 18 12.5C18 13.3284 17.3284 14 16.5 14H7.5C6.67157 14 6 13.3284 6 12.5Z" />
114115
</svg>
115116
}
116-
</button>
117-
<button class="list-btn" @onclick="(async () => await Featured(post))">
117+
</button>
118+
<button class="list-btn" @onclick="(async () => await Featured(post))">
118119
@if (@featured == "featured")
119120
{
120121
<svg xmlns="http://www.w3.org/2000/svg" width="15" height="15" fill="currentColor" class="bi bi-star-fill link-gold" viewBox="0 0 16 16" data-bs-toggle="tooltip" title="@_localizer["featured"]">
@@ -127,17 +128,18 @@
127128
<path d="M3.612 15.443c-.386.198-.824-.149-.746-.592l.83-4.73L.173 6.765c-.329-.314-.158-.888.283-.95l4.898-.696L7.538.792c.197-.39.73-.39.927 0l2.184 4.327 4.898.696c.441.062.612.636.282.95l-3.522 3.356.83 4.73c.078.443-.36.79-.746.592L8 13.187l-4.389 2.256z"/>
128129
</svg>
129130
}
130-
</button>
131-
<a class="list-btn" href="posts/@post.Slug" target="_blank">
132-
<svg class="bi" width="15" height="15" viewBox="0 0 16 16" fill="currentColor" xmlns="http://www.w3.org/2000/svg" data-bs-toggle="tooltip" title="@_localizer["view"]">
133-
<path d="M7.85724 2.17097L6 4L7 5L8.93201 3.24577C9.89935 2.27845 11.4719 2.27845 12.4393 3.24577C13.4066 4.21308 13.4066 5.78571 12.4393 6.75303L10.5141 8.75674L11.5141 9.75674L13.5141 7.82783C15.0754 6.26652 15.0754 3.73225 13.5141 2.17094C11.9528 0.609657 9.41852 0.609688 7.85724 2.17097Z" />
134-
<path d="M3.24575 12.4392C2.2784 11.4719 2.2784 9.89935 3.24575 8.93201L5 7L4 6L2.17098 7.85721C0.609703 9.41849 0.609642 11.9528 2.17098 13.514C3.73226 15.0753 6.26656 15.0753 7.82784 13.514L9.5141 11.7567L8.5141 10.7567L6.75301 12.4392C5.78573 13.4066 4.2131 13.4066 3.24575 12.4392Z" />
135-
<path d="M4.99941 9.55426L9.52486 5.02878L10.6563 6.16016L6.13076 10.6856L4.99941 9.55426Z" />
136-
</svg>
137-
</a>
138-
</li>
139-
</Virtualize>
140-
</ul>
131+
</button>
132+
<a class="list-btn" href="posts/@post.Slug" target="_blank">
133+
<svg class="bi" width="15" height="15" viewBox="0 0 16 16" fill="currentColor" xmlns="http://www.w3.org/2000/svg" data-bs-toggle="tooltip" title="@_localizer["view"]">
134+
<path d="M7.85724 2.17097L6 4L7 5L8.93201 3.24577C9.89935 2.27845 11.4719 2.27845 12.4393 3.24577C13.4066 4.21308 13.4066 5.78571 12.4393 6.75303L10.5141 8.75674L11.5141 9.75674L13.5141 7.82783C15.0754 6.26652 15.0754 3.73225 13.5141 2.17094C11.9528 0.609657 9.41852 0.609688 7.85724 2.17097Z" />
135+
<path d="M3.24575 12.4392C2.2784 11.4719 2.2784 9.89935 3.24575 8.93201L5 7L4 6L2.17098 7.85721C0.609703 9.41849 0.609642 11.9528 2.17098 13.514C3.73226 15.0753 6.26656 15.0753 7.82784 13.514L9.5141 11.7567L8.5141 10.7567L6.75301 12.4392C5.78573 13.4066 4.2131 13.4066 3.24575 12.4392Z" />
136+
<path d="M4.99941 9.55426L9.52486 5.02878L10.6563 6.16016L6.13076 10.6856L4.99941 9.55426Z" />
137+
</svg>
138+
</a>
139+
</li>
140+
</Virtualize>
141+
</ul>
142+
</div>
141143
}
142144
else
143145
{

0 commit comments

Comments
 (0)