-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
♻️ Add route and http context to ServerLoad func
- Loading branch information
Showing
7 changed files
with
53 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,8 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using Microsoft.AspNetCore.Http; | ||
|
||
namespace BlazeKit.Web; | ||
|
||
internal interface IPageLoad<TPageData> | ||
{ | ||
virtual Task<TPageData> ServerLoadAsync() => Task.FromResult(default(TPageData)); | ||
virtual Task<TPageData> ServerLoadAsync(Uri route, HttpContext? context) => Task.FromResult(default(TPageData)); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
namespace BlazeKit.Web.Utils | ||
{ | ||
public static class UriExtensions | ||
{ | ||
public static string Param(this Uri uri, string name) | ||
{ | ||
return Param(uri,name, () => throw new InvalidOperationException($"There is no query param with the name '{name}' in the route.")); | ||
} | ||
|
||
public static string Param(this Uri uri, string name, string fallback) | ||
{ | ||
return Param(uri,name, fallbackFunc: () => fallback); | ||
} | ||
|
||
private static string Param(Uri uri, string name, Func<string> fallbackFunc) | ||
{ | ||
string result = string.Empty; | ||
var queryDictionary = System.Web.HttpUtility.ParseQueryString(uri.Query); | ||
if (queryDictionary.HasKeys() && queryDictionary.AllKeys.Contains(name)) | ||
{ | ||
result = queryDictionary[name]; | ||
} else | ||
{ | ||
result = fallbackFunc(); | ||
} | ||
return result; | ||
} | ||
} | ||
} |
14 changes: 12 additions & 2 deletions
14
src/BlazeKit.Website/Routes/Docs/(Core-Concepts)/Loading-Data/Page.razor
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters