Skip to content

Instantly share code, notes, and snippets.

@burkeholland
Created October 31, 2019 00:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save burkeholland/568ec708fc64775518a946328992f6f3 to your computer and use it in GitHub Desktop.
Save burkeholland/568ec708fc64775518a946328992f6f3 to your computer and use it in GitHub Desktop.
@page "/s/add"
@using System.Collections.Generic
@using System.Net.Http
@using LinkyLink.Models
@inject NavigationManager NavigationManager
@inject HttpClient Http
<div id="listDetails" class="addbar flex is-horizontally-centered">
<div class="container main">
<div class="columns">
<div class="column">
<label class="control-label" for="vanityUrl">Link Title</label>
<input type="text"
id="vanitUrl"
title="Optional: Enter a name for this list. The name will become the URL (i.e. my-list becomes theurlist.com/my-list). If you leave this box blank, we'll generate a random name for you."
class="input is-large has-tooltip"
@bind="Name" />
</div>
<div class="column">
<label class="control-label" for="description">Description</label>
<textarea type="text"
rows="2"
title="Optional: The description will show up as the title on your public list page."
class="textarea has-fixed-size"
@bind="Description" />
</div>
<div class="column is-narrow">
<label class="control-label is-hidden-mobile"> </label>
<p>@status</p>
<button class="button is-primary is-large has-text-white has-text-weight-bold" @onclick="Publish">Publish</button>
</div>
</div>
</div>
</div>
<div class="container main content">
<div id="newLink">
<p>Enter a link and press enter</p>
<input type="text" @bind="NewLink" placeholder="http://example.com" class="input is-large is-size-2" />
</div>
<div id="linkHeader" class="columns is-mobile is-vcentered is-gapless">
<div class="column">
<h3 class="has-text-primary is-size-3 has-text-weight-medium">
Links
</h3>
</div>
<div class="column">
<span class="is-pulled-right">Drag links to re-order</span>
</div>
</div>
<ListView Links=@Links />
</div>
@code {
private int updateVersion = 0;
private string Name = "";
private string Description = "";
private string PublishData = "";
private string NewLink = "";
private List<LinkDetailsResponse> AddedLinks = new List<LinkDetailsResponse>();
private string status = "";
private bool isError = false;
async Task Publish()
{
updateVersion++;
PublishData = Name + " - " + Description;
RequestClient.Initialize(Http);
LinkBundle submission = new LinkBundle("anonymousUser",
Name,
Description,
AddedLinks.Select(l => new Dictionary<string, string>() {
{ "id", l.id },
{ "url", l.id},
{ "title", l.title},
{ "description" , l.description},
{ "image", l.Image}
}).ToArray<Dictionary<string, string>>());
try
{
status = "Creating list...";
LinkBundle result = await Http.SendJsonAsync<LinkBundle>(
HttpMethod.Post,
"urlist-api-demo/links",
submission);
status = "";
NavigationManager.NavigateTo($"/list/{Name}");
}
catch (Exception e)
{
status = $"Url creation failed: {e.Message}";
}
}
async Task AddLink()
{
RequestClient.Initialize(Http);
var result = await Http.PostJsonAsync<LinkDetailsResponse>("urlist-api-demo/validatePage", new LinkDetailsRequest { url = NewLink, id = NewLink });
AddedLinks.Insert(0, result);
}
private IEnumerable<LinkDetailsResponse> Links
{
get
{
return AddedLinks;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment