feat: basic initial implementation of spotify client link validator and song submission form refs: NOISSUE
This commit is contained in:
2
song_of_the_day/Pages/Shared/UpdateInputText.razor
Normal file
2
song_of_the_day/Pages/Shared/UpdateInputText.razor
Normal file
@@ -0,0 +1,2 @@
|
||||
@inherits Microsoft.AspNetCore.Components.Forms.InputText
|
||||
<input @attributes="@AdditionalAttributes" class="@CssClass" @bind="@CurrentValueAsString" @bind:event="oninput" />
|
@@ -43,6 +43,12 @@
|
||||
<a class="nav-link text-dark" asp-area="" asp-page="/UnclaimedPhoneNumbers">Unclaimed Phone Numbers</a>
|
||||
</li>
|
||||
}
|
||||
@if (this.User.Identity.IsAuthenticated && DoesUserHaveClaimedPhoneNumber())
|
||||
{
|
||||
<li class="nav-item">
|
||||
<a class="nav-link text-dark" asp-area="" asp-page="/SubmitSongs">Submit Songs</a>
|
||||
</li>
|
||||
}
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
|
7
song_of_the_day/Pages/Shared/_SongPartial.cshtml
Normal file
7
song_of_the_day/Pages/Shared/_SongPartial.cshtml
Normal file
@@ -0,0 +1,7 @@
|
||||
@model Song
|
||||
<label asp-for="Name">Name:</label>
|
||||
<input asp-for="Name" />
|
||||
<label asp-for="Artist">Artist:</label>
|
||||
<input asp-for="Artist" />
|
||||
<label asp-for="SpotifyId">Spotify ID:</label>
|
||||
<input asp-for="SpotifyId" />
|
25
song_of_the_day/Pages/SubmitSongs.cshtml
Normal file
25
song_of_the_day/Pages/SubmitSongs.cshtml
Normal file
@@ -0,0 +1,25 @@
|
||||
@page
|
||||
@model SubmitSongsModel
|
||||
@{
|
||||
ViewData["Title"] = "Submit Songs";
|
||||
}
|
||||
|
||||
<div class="text-left">
|
||||
<form method="post">
|
||||
<label asp-for="SubmitUrl" >Song Url:</label>
|
||||
<input asp-for="SubmitUrl" oninput="Update(this)" />
|
||||
</form>
|
||||
<form method="post">
|
||||
<div id="songdata">
|
||||
<partial name="_SongPartial" model="@Model.SongData" />
|
||||
</div>
|
||||
<input type="submit" title="Submit" value="Submit" disabled="CanSubmit" />
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
function Update(t) {
|
||||
var url = '?handler=Update&&SubmitUrl=' + $(t).val();
|
||||
$('#songdata').load(url)
|
||||
}
|
||||
</script>
|
71
song_of_the_day/Pages/SubmitSongs.cshtml.cs
Normal file
71
song_of_the_day/Pages/SubmitSongs.cshtml.cs
Normal file
@@ -0,0 +1,71 @@
|
||||
using Microsoft.AspNetCore.Components;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Mvc.RazorPages;
|
||||
using Microsoft.VisualBasic;
|
||||
|
||||
namespace sotd.Pages;
|
||||
|
||||
public class SubmitSongsModel : PageModel
|
||||
{
|
||||
private readonly ILogger<UserModel> _logger;
|
||||
|
||||
private SongResolver songResolver;
|
||||
|
||||
private string _submitUrl;
|
||||
|
||||
public SubmitSongsModel(ILogger<UserModel> logger, SongResolver songResolver)
|
||||
{
|
||||
_logger = logger;
|
||||
this.songResolver = songResolver;
|
||||
}
|
||||
|
||||
[BindProperty]
|
||||
public bool IsValidUrl { get; set; } = true;
|
||||
|
||||
[BindProperty]
|
||||
public string SubmitUrl {
|
||||
get {
|
||||
return _submitUrl;
|
||||
}
|
||||
set {
|
||||
_submitUrl = value.ToString();
|
||||
Uri? newValue = default;
|
||||
try {
|
||||
newValue = new Uri(_submitUrl);
|
||||
}
|
||||
catch (UriFormatException)
|
||||
{
|
||||
IsValidUrl = false;
|
||||
return;
|
||||
}
|
||||
|
||||
IsValidUrl = true;
|
||||
|
||||
if(this.songResolver.CanValidate(newValue))
|
||||
{
|
||||
this.SongData = this.songResolver.ResolveSongAsync(newValue).Result;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[BindProperty]
|
||||
public bool CanSubmit { get {
|
||||
return !string.IsNullOrEmpty(SongData?.Artist) && ! string.IsNullOrEmpty(SongData?.Name);
|
||||
} }
|
||||
|
||||
[BindProperty]
|
||||
public Song SongData { get; set; }
|
||||
|
||||
public void OnPost()
|
||||
{
|
||||
// Todo implement save submission
|
||||
var x = SongData.Name;
|
||||
}
|
||||
|
||||
public IActionResult OnGetUpdate()
|
||||
{
|
||||
var songUrl = Request.Query["SubmitUrl"];
|
||||
this.SubmitUrl = songUrl.ToString();
|
||||
return Partial("_SongPartial", SongData);;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user