Skip to content

Commit

Permalink
working on global search
Browse files Browse the repository at this point in the history
  • Loading branch information
Yucked committed Dec 8, 2023
1 parent 0ca5262 commit b90bba1
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 9 deletions.
2 changes: 0 additions & 2 deletions src/Pages/SourcePage.razor
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,6 @@
private string LoadingMessage
=> $"Loading {SourceId.GetNameFromId()} content";

private string SortType { get; set; }

private Book _book;
private Page _currentPage;

Check warning on line 98 in src/Pages/SourcePage.razor

View workflow job for this annotation

GitHub Actions / Build

Non-nullable field '_currentPage' must contain a non-null value when exiting constructor. Consider declaring the field as nullable.

Expand Down
37 changes: 30 additions & 7 deletions src/Pages/SourcesPage.razor
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
@using Grimoire.Handlers
@using Grimoire.Sources.Interfaces

@inject IJSRuntime JSRuntime
@inject DatabaseHandler DatabaseHandler
@inject NavigationManager NavigationManager

Expand All @@ -10,21 +11,34 @@
<Waiting Message="Loading sources"/>
}
else {
<div class="border rounded-4 shadow">
<div class="rounded-4">
<div class="container p-4">
<Search OnSearchAsync="OnSearchAsync"></Search>
</div>

<ul class="list-group list-group-flush">
@foreach (var source in _sources) {
<a class="list-group-item list-group-item-action" @onclick="() => NavTo(source.Id)">
<img src="@DatabaseHandler.GetSourceIcon(source.Id)" class="img-thumbnail" alt="@source.Name" width="70">
<span>@source.Name</span>
</a>
}
<div class="row row-cols-1 g-4">
@foreach (var source in _sources) {
<div class="col rounded">
<a class="list-group-item list-group-item-action shadow" @onclick="() => NavTo(source.Id)">
<img src="@DatabaseHandler.GetSourceIcon(source.Id)" class="img-thumbnail" alt="@source.Name" width="70">
<span>@source.Name</span>
</a>
</div>

<div id="@source.Id" class="col visually-hidden">

</div>
}
</div>
</ul>
</div>
}
</div>

@code {
private IReadOnlyList<IGrimoireSource> _sources;

Check warning on line 40 in src/Pages/SourcesPage.razor

View workflow job for this annotation

GitHub Actions / Build

Non-nullable field '_sources' must contain a non-null value when exiting constructor. Consider declaring the field as nullable.
private bool _isHidden = true;

protected override async Task OnInitializedAsync() {
_sources = await DatabaseHandler.ListSourcesAsync();
Expand All @@ -34,4 +48,13 @@
NavigationManager.NavigateTo($"/sources/{sourceId}");
}

private async Task OnSearchAsync(string arg) {
var mangas = await DatabaseHandler.SearchAsync(SearchType.Global, arg);
var dict = mangas
.GroupBy(x => x.SourceId, y => y)
.ToDictionary(x => x.Key, x => x.ToList());

await JSRuntime.InvokeVoidAsync("displayData", dict);
}

}
1 change: 1 addition & 0 deletions src/Pages/_Host.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,6 @@

<script src="_framework/blazor.server.js"></script>
<script src="js/bootstrap.min.js"></script>
<script src="js/site.js"></script>
</body>
</html>
10 changes: 10 additions & 0 deletions src/wwwroot/js/site.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
function displayData(dictionary) {
console.log(dictionary);

for (let key in dictionary) {
let element = document.getElementById(key)
element.classList.remove("visually-hidden")

let value = dictionary[key]
}
}

0 comments on commit b90bba1

Please sign in to comment.