-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBook.razor
172 lines (156 loc) · 6.74 KB
/
Book.razor
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
@using Microsoft.AspNetCore.Components;
@using EveryoneReads.Backend
@using System.Globalization
@using System.Web;
@inject IJSRuntime JS
@page "/book"
<style>
body {
background: linear-gradient(320deg, rgba(155,234,255,1) 0%, rgba(101,61,255,1) 0%, rgba(162,139,255,1) 100%);
}
</style>
<button type="button" class="btn btn-primary" @onclick=GoBack>Back</button>
@if (curBook != null)
{
<PageTitle>@curBook.Title | Everyone Reads </PageTitle>
<div class="container-fluid">
<div class="row">
<div class="col">
<div class="col">
<div class="bookcontainer">
<div class="book">
<div class="front">
<div class="cover">
<img src=@curBook.CoverURL>
</div>
</div>
<div class="left-side">
<img src="BookSpine.png">
</div>
</div>
</div>
</div>
</div>
<div class="col">
<h1 class="text-white"><b>@curBook.Title</b></h1>
<h4 class="text-white">
By: @string.Join(",",@curBook.Authors)
<br>
<br>
Categories: @string.Join(",",@curBook.Categories)
<br>
Pages: @curBook.PageCount
<br>
Published: @curBook.PublishDate
<br>
Publisher: @curBook.Publisher
<br>
ISBN-13: @curBook.ISBN13
<br>
Language: @Util.GetLanguageList().First(x => x.Alpha2.Equals(curBook.Language)).Name
</h4>
</div>
</div>
@if (SameAuthor != null)
{
<div class="container-fluid rounded-3" style="background-color:#A28BFF">
<br>
<h3 class="text-white" style="font-family:Roboto">More by @string.Join(",",@curBook.Authors)</h3>
<div class="row row-cols-1 row-cols-sm-4 g-2">
@foreach (var book in SameAuthor)
{
<div class="col">
<div class="card">
<div class="card-header"><span class="d-inline-block text-truncate" style="max-width: 300px">@book.Title</span></div>
<div class="card-body">
<div class="container" style="height:200px">
<div class="row">
<div class="col-6">
<img @onclick="@(e => curBook = book)" src="@book.CoverURL" class="card-img-top img-fluid" alt="@book.Title's cover" style="height:80%;width:auto;object-fit:fill;cursor:pointer">
</div>
<div class="col">
<p class="text-sm-start">
Publisher: @book.Publisher
<br>
Authors: @string.Join(",",@book.Authors)
<br>
Published: @book.PublishDate
</p>
</div>
</div>
</div>
</div>
<div class="card-footer text-muted">
<div class="container">
<div class="row">
<div class="col">
<button class="btn btn-primary rounded-pill" style="background:#A088FF;color:#FFF;border-color:#A088FF" @onclick="() => Util.Wishlist.Add(book)">Add to Wishlist</button>
</div>
<div class="col">
<button class="btn btn-primary rounded-pill" style="background:#8263FF; color:#FFF;border-color:#8263FF" @onclick="() => Util.MyBooks.Add(book)">Add to my books</button>
</div>
</div>
</div>
</div>
</div>
</div>
}
</div>
<br>
</div>
<br />
<br />
}
</div>
}
@code {
public string BookISBN { get; set; }
public static BookObj curBook { get; set; } = null;
private ICollection<BookObj> SameAuthor { get; set; } = null;
[Inject]
public NavigationManager NavMan { get; set; } = default!;
protected override async Task OnInitializedAsync()
{
if (curBook == null)
{
string googleBooksID = GetQueryParm("google");
string isbn = GetQueryParm("isbn");
if (!string.IsNullOrEmpty(googleBooksID))
{
curBook = await BookObj.GetBookByID(googleBooksID);
}
else if (!string.IsNullOrEmpty(isbn))
{
curBook = await BookObj.GetBookByISBN(isbn);
}
}
if (curBook.Authors.Length > 0 && SameAuthor == null)
{
IEnumerable<BookObj> tmp = await BookObj.GetBookByAuthor(curBook.Authors[0], 40, Util.GetLanguageList().First(x => x.Alpha2.Equals(Search.BookLanguage)));
SameAuthor = GetRandom<BookObj>(tmp, 4).ToList();
}
}
public static IEnumerable<T> GetRandom<T>(IEnumerable<T> list, int count)
{
if (count <= 0)
yield break;
var r = new Random();
int limit = (count * 10);
foreach (var item in list.OrderBy(x => r.Next(0, limit)).Take(count))
yield return item;
}
private async Task NavigateTo(string googleBooksID)
{
NavMan.NavigateTo(NavMan.BaseUri + "book?google=" + googleBooksID);
}
string GetQueryParm(string parmName)
{
var uriBuilder = new UriBuilder(NavMan.Uri);
var q = HttpUtility.ParseQueryString(uriBuilder.Query);
return q[parmName] ?? "";
}
private async Task GoBack()
{
await JS.InvokeVoidAsync("history.back");
}
}