Skip to content

Commit

Permalink
feat/change-serach-to-get-request (#129)
Browse files Browse the repository at this point in the history
* change controller action to be get request instead of post

* move search form markup to a partial view
  • Loading branch information
JwanKhalaf authored Dec 27, 2023
1 parent d7a86b9 commit 7de48a6
Show file tree
Hide file tree
Showing 8 changed files with 16 additions and 34 deletions.
8 changes: 4 additions & 4 deletions Bejebeje.Mvc/Controllers/SearchController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,14 @@ public IActionResult Index()
return View(viewModel);
}

[HttpPost]
public async Task<IActionResult> Index(string searchTerm)
[HttpGet]
public async Task<IActionResult> Search(string searchTerm)
{
SearchViewModel viewModel = new SearchViewModel();

if (string.IsNullOrEmpty(searchTerm))
{
return View(viewModel);
return View("Index", viewModel);
}

viewModel.SearchTerm = searchTerm;
Expand All @@ -45,7 +45,7 @@ public async Task<IActionResult> Index(string searchTerm)
viewModel.Lyrics = await _lyricsService
.SearchLyricsAsync(searchTerm);

return View(viewModel);
return View("Index", viewModel);
}
}
}
6 changes: 1 addition & 5 deletions Bejebeje.Mvc/Views/Artist/Index.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,7 @@
</nav>
</div>

<div class="search">
<form asp-controller="Search" asp-action="Index" method="post" class="search__form">
<input class="search__input" placeholder="search for artist or lyric" name="searchTerm" />
</form>
</div>
@await Html.PartialAsync("_SearchForm")

<div class="letters-wrapper">
@foreach (char letter in dictionaryKeys)
Expand Down
6 changes: 1 addition & 5 deletions Bejebeje.Mvc/Views/Home/Index.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,7 @@
</nav>
</div>

<div class="search">
<form asp-controller="Search" asp-action="Index" method="post" class="search__form">
<input class="search__input" placeholder="search for artist or lyric" name="searchTerm" />
</form>
</div>
@await Html.PartialAsync("_SearchForm")

<section class="featured_list">
<h2 class="featured_list__title">Recent Submissions</h2>
Expand Down
6 changes: 1 addition & 5 deletions Bejebeje.Mvc/Views/Lyric/ArtistLyrics.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,7 @@
</nav>
</div>

<div class="search">
<form asp-controller="Search" asp-action="Index" method="post" class="search__form">
<input class="search__input" placeholder="search for artist or lyric" name="searchTerm" />
</form>
</div>
@await Html.PartialAsync("_SearchForm")

@if (!Model.Artist.IsApproved)
{
Expand Down
6 changes: 1 addition & 5 deletions Bejebeje.Mvc/Views/Lyric/Lyric.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,7 @@
</nav>
</div>

<div class="search">
<form asp-controller="Search" asp-action="Index" method="post" class="search__form">
<input class="search__input" placeholder="search for artist or lyric" name="searchTerm" />
</form>
</div>
@await Html.PartialAsync("_SearchForm")

@if (!Model.IsApproved)
{
Expand Down
6 changes: 1 addition & 5 deletions Bejebeje.Mvc/Views/Profile/Index.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,7 @@
</nav>
</div>

<div class="search">
<form asp-controller="Search" asp-action="Index" method="post" class="search__form">
<input class="search__input" placeholder="search for artist or lyric" name="searchTerm" />
</form>
</div>
@await Html.PartialAsync("_SearchForm")

<div class="actions">
<h2 class="actions__heading">Want to help?</h2>
Expand Down
6 changes: 1 addition & 5 deletions Bejebeje.Mvc/Views/Search/Index.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,7 @@
</nav>
</div>

<div class="search">
<form asp-controller="Search" asp-action="Index" method="post" class="search__form">
<input asp-for="@Model.SearchTerm" class="search__input" placeholder="artist name or lyric title" />
</form>
</div>
@await Html.PartialAsync("_SearchForm")

<div class="results">
@if (!Model.Lyrics.Any() && !Model.Artists.Any() && !string.IsNullOrEmpty(Model.SearchTerm))
Expand Down
6 changes: 6 additions & 0 deletions Bejebeje.Mvc/Views/Shared/_SearchForm.cshtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<div class="search">
<form asp-controller="Search" asp-action="Search" method="get" class="search__form">
<input class="search__input" placeholder="search for artist or lyric" name="searchTerm" />
</form>
</div>

0 comments on commit 7de48a6

Please sign in to comment.