-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
75 additions
and
5 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
using HotwiredBooks.Models; | ||
using HotwiredBooks.ViewModels; | ||
using Microsoft.AspNetCore.Mvc; | ||
using MonadicBits; | ||
|
||
namespace HotwiredBooks.ViewComponents; | ||
|
||
public sealed class BookFormViewComponent : ViewComponent | ||
{ | ||
public IViewComponentResult Invoke(Maybe<Book> book) => View(new BookFormViewModel(book)); | ||
} |
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,6 @@ | ||
using HotwiredBooks.Models; | ||
using MonadicBits; | ||
|
||
namespace HotwiredBooks.ViewModels; | ||
|
||
public sealed record BookFormViewModel(Maybe<Book> Book); |
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,5 @@ | ||
using HotwiredBooks.Models; | ||
|
||
namespace HotwiredBooks.ViewModels; | ||
|
||
public sealed record BooksEditViewModel(Book Book); |
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,10 @@ | ||
@using HotwiredBooks.Extensions | ||
@using MonadicBits | ||
@model HotwiredBooks.ViewModels.BooksEditViewModel | ||
@{ | ||
Layout = null; | ||
} | ||
|
||
<turbo-frame id="@Html.DomId(Model.Book)"> | ||
<vc:book-form book="@Model.Book.Just()"/> | ||
</turbo-frame> |
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
34 changes: 34 additions & 0 deletions
34
HotwiredBooks/Views/Shared/Components/BookForm/Default.cshtml
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,34 @@ | ||
@model HotwiredBooks.ViewModels.BookFormViewModel | ||
|
||
@{ | ||
var id = Model.Book.Map(book => book.Id).Match(id => id.ToString(), () => string.Empty); | ||
var action = Model.Book.Match(_ => "Update", () => "Create"); | ||
var method = Model.Book.Match(_ => "put", () => "post"); | ||
var title = Model.Book.Map(book => book.Title).Match(title => title, () => string.Empty); | ||
var author = Model.Book.Map(book => book.Author).Match(author => author, () => string.Empty); | ||
} | ||
|
||
<form asp-controller="Books" | ||
asp-action="@action" | ||
asp-route-id="@id" | ||
method="@method" | ||
accept-charset="UTF-8" | ||
class="book-form"> | ||
<div class="form-field title"> | ||
<label style="display: block" for="title">Title</label> | ||
<input type="text" name="title" id="title" value="@title"/> | ||
</div> | ||
|
||
<div class="form-field author"> | ||
<label style="display: block" for="author">Author</label> | ||
<input type="text" name="author" id="author" value="@author"/> | ||
</div> | ||
|
||
<div class="action-left"> | ||
<a class="button secondary" asp-controller="Books" asp-action="Index">Cancel</a> | ||
</div> | ||
|
||
<div class="action-right"> | ||
<input type="submit" name="commit" value="Submit" class="button primary" data-disable-with="Submit"/> | ||
</div> | ||
</form> |