Skip to content

Commit 0154c8c

Browse files
committed
Remove boilerplate by using EditForm context
1 parent 4ed150e commit 0154c8c

8 files changed

Lines changed: 44 additions & 140 deletions

File tree

BlazorDiffusion/Pages/admin/Albums.razor

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
{
1818
case "All":
1919
default:
20-
<AutoQueryGrid Model="Album" Apis="Apis.AutoQuery<QueryAlbums, CreateAlbum, UpdateAlbum, DeleteAlbum>()">
20+
<AutoQueryGrid Model="Album" Apis="Apis.AutoQuery<QueryAlbums,CreateAlbum,UpdateAlbum,DeleteAlbum>()">
2121

2222
</AutoQueryGrid>
2323
break;

BlazorDiffusion/Pages/admin/Artifacts.razor

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,15 @@
1212

1313
@if (Tab == "Reported")
1414
{
15-
<ArtifactReportsAutoQueryGrid></ArtifactReportsAutoQueryGrid>
15+
<ArtifactReportsAutoQueryGrid />
1616
}
1717
else if (Tab == "Stats")
1818
{
1919
<AutoQueryGrid Model="ArtifactStat" Apis="Apis.AutoQuery<QueryArtifactStats>()" />
2020
}
21-
else
21+
else //All
2222
{
23-
<!--All Artifacts-->
24-
<ArtifactAutoQueryGrid></ArtifactAutoQueryGrid>
23+
<ArtifactAutoQueryGrid />
2524
}
2625

2726
@code {

BlazorDiffusion/Pages/admin/Artists.razor

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
</Breadcrumb>
1111
</Breadcrumbs>
1212

13-
<AutoQueryGrid Model="Artist" Apis="Apis.AutoQuery<QueryArtists, CreateArtist, UpdateArtist, DeleteArtist>()">
13+
<AutoQueryGrid Model="Artist" Apis="Apis.AutoQuery<QueryArtists,CreateArtist,UpdateArtist,DeleteArtist>()">
1414
<Columns>
1515
<Column Field="(Artist x) => x.FirstName"></Column>
1616
<Column Field="(Artist x) => x.LastName"></Column>

BlazorDiffusion/Pages/admin/Creatives.razor

Lines changed: 8 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -12,22 +12,14 @@
1212

1313
<Tabs TabOptions="TabOptions" TabChanged="TabChangedAsync" />
1414

15-
<AutoQueryGrid @ref=@grid Model="Creative" Apis="Apis.AutoQuery<QueryCreatives, UpdateCreative, HardDeleteCreative>()"
16-
RowSelected="RowSelected" ConfigureQuery="ConfigureQuery">
15+
<AutoQueryGrid @ref=@grid Model="Creative" Apis="Apis.AutoQuery<QueryCreatives,UpdateCreative,HardDeleteCreative>()"
16+
ConfigureQuery="ConfigureQuery">
1717
<EditForm>
18-
@if (reviewItem != null)
19-
{
20-
<div class="relative z-10" aria-labelledby="slide-over-title" role="dialog" aria-modal="true">
21-
<div class="">
22-
<div class="">
23-
<div class="pointer-events-none fixed inset-y-0 right-0 flex max-w-full pl-10 sm:pl-16">
24-
<CreativeEdit Creative="reviewItem" OnClose="Close" OnDelete="DeleteAsync" OnSave="SaveAsync"
25-
EditPanelClass=@EditPanelClass />
26-
</div>
27-
</div>
28-
</div>
18+
<div class="relative z-10" aria-labelledby="slide-over-title" role="dialog" aria-modal="true">
19+
<div class="pointer-events-none fixed inset-y-0 right-0 flex max-w-full pl-10 sm:pl-16">
20+
<CreativeEdit Creative="context" OnClose="grid!.OnEditDone" />
2921
</div>
30-
}
22+
</div>
3123
</EditForm>
3224
<Columns>
3325
<Column Title="User" Field="(Creative x) => x.OwnerId" />
@@ -71,25 +63,17 @@
7163
</Columns>
7264
</AutoQueryGrid>
7365

74-
7566
@code {
76-
77-
[Parameter, SupplyParameterFromQuery]
78-
public string? Edit { get; set; }
79-
80-
public Creative? reviewItem = null;
8167
AutoQueryGrid<Creative>? grid;
8268

8369
public string? Tab { get; set; }
8470

8571
public Dictionary<string, string> TabOptions = new()
8672
{
87-
{"All","All"},
88-
{"MissingPrimaryArtifact","Missing Primary Artifact"}
73+
["All"] = "All",
74+
["MissingPrimaryArtifact"] = "Missing Primary Artifact",
8975
};
9076

91-
string EditPanelClass { get; set; } = "show";
92-
9377
void ConfigureQuery(QueryBase query)
9478
{
9579
switch (Tab)
@@ -108,20 +92,4 @@
10892
if (grid != null)
10993
await grid.RefreshAsync();
11094
}
111-
112-
void RowSelected(Creative item)
113-
{
114-
reviewItem = item;
115-
EditPanelClass = "show";
116-
}
117-
118-
void Close()
119-
{
120-
EditPanelClass = "hidden";
121-
reviewItem = null;
122-
}
123-
124-
async Task SaveAsync() => await grid!.RefreshAsync();
125-
126-
async Task DeleteAsync() => await grid!.RefreshAsync();
12795
}

BlazorDiffusion/Shared/ArtifactEdit.razor

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,8 @@
7878
</div>
7979
</div>
8080

81-
<div class="mt-4 px-4 py-3 bg-gray-50 dark:bg-gray-900 sm:px-6 flex flex-wrap justify-between">
81+
<div class=@CssDefaults.Form.ButtonsClass>
82+
<div></div>
8283
<div class="flex justify-end">
8384
<SecondaryButton onclick="Close">Cancel</SecondaryButton>
8485
<PrimaryButton type="submit" class="ml-4 bg-indigo-300">Save</PrimaryButton>

BlazorDiffusion/Shared/CreativeEdit.razor

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88
<div class=@CssDefaults.SlideOver.TitlebarClass>
99
<div class="flex items-start justify-between space-x-3">
1010
<div class="space-y-1">
11-
<h2 class=@CssDefaults.SlideOver.HeadingClass id="slide-over-title">@Creative?.UserPrompt</h2>
11+
<h2 class=@CssDefaults.SlideOver.HeadingClass id="slide-over-title">@Creative.UserPrompt</h2>
1212
<div class="mt-1">
13-
<p class="text-sm text-gray-500">@Creative?.ModifierNames.Join(", ")&nbsp;</p>
13+
<p class="text-sm text-gray-500">@Creative.ModifierNames.Join(", ")&nbsp;</p>
1414
</div>
1515
</div>
1616
<div class="flex h-7 items-center">
@@ -28,14 +28,14 @@
2828
<div class="divide-y divide-gray-200 px-4 sm:px-6">
2929
<div class="space-y-6 pt-6 pb-5">
3030
<div class="">
31-
@if (selectedPrimary != null)
31+
@if (selectedPrimary != null)
3232
{
3333
<img src="https://cdn.diffusion.works@(selectedPrimary.FilePath)" @onclick="UnpinArtifact" alt=""
3434
class="object-cover group-hover:opacity-75 border-yellow-500 rounded-xl border-4">
3535
}
3636
</div>
3737
<ul role="list" class="grid grid-cols-2 gap-x-4 gap-y-8 sm:grid-cols-3 sm:gap-x-6 lg:grid-cols-4 xl:gap-x-8">
38-
@foreach (var artifact in Creative?.Artifacts ?? Array.Empty<Artifact>().ToList())
38+
@foreach (var artifact in Creative.Artifacts.OrEmpty())
3939
{
4040
<li class="relative" @onclick="(x) => selectPrimaryArtifact(artifact)">
4141
<div class="group aspect-w-10 aspect-h-7 block w-full overflow-hidden rounded-lg bg-gray-100">
@@ -55,7 +55,7 @@
5555
</div>
5656
</div>
5757

58-
<div class="mt-4 px-4 py-3 bg-gray-50 dark:bg-gray-900 sm:px-6 flex flex-wrap justify-between">
58+
<div class=@CssDefaults.Form.ButtonsClass>
5959
<div>
6060
<ConfirmDelete OnDelete="DeleteCreative" />
6161
</div>
@@ -136,7 +136,6 @@
136136
await OnDelete.InvokeAsync();
137137
await Close();
138138
}
139-
140139
}
141140

142141
void selectPrimaryArtifact(Artifact artifact)
Lines changed: 6 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,10 @@
1-
<AutoQueryGrid Model="Artifact" Apis="Apis.AutoQuery<QueryArtifacts,UpdateArtifact>()"
2-
@ref=@autoQueryGrid
3-
RowSelected="RowSelected">
1+
<AutoQueryGrid @ref=@grid Model="Artifact" Apis="Apis.AutoQuery<QueryArtifacts,UpdateArtifact>()">
42
<EditForm>
5-
@if (reviewItem != null)
6-
{
7-
<div class="relative z-10" aria-labelledby="slide-over-title" role="dialog" aria-modal="true">
8-
<div class="">
9-
<div class="">
10-
<div class="pointer-events-none fixed inset-y-0 right-0 flex max-w-full pl-10 sm:pl-16">
11-
<ArtifactEdit Artifact="reviewItem" OnClose="Close"
12-
OnDelete="Delete" OnSave="Save"
13-
EditPanelClass=@editPanelClass />
14-
</div>
15-
</div>
16-
</div>
3+
<div class="relative z-10" aria-labelledby="slide-over-title" role="dialog" aria-modal="true">
4+
<div class="pointer-events-none fixed inset-y-0 right-0 flex max-w-full pl-10 sm:pl-16">
5+
<ArtifactEdit Artifact="context" OnClose="grid!.OnEditDone" />
176
</div>
18-
}
7+
</div>
198
</EditForm>
209
<Columns>
2110
<Column Title="Creative" Field="(Artifact x) => x.CreativeId">
@@ -47,10 +36,7 @@
4736
</AutoQueryGrid>
4837

4938
@code {
50-
AutoQueryGrid<Artifact>? autoQueryGrid;
51-
public Artifact? reviewItem;
52-
53-
string editPanelClass = "show";
39+
AutoQueryGrid<Artifact>? grid;
5440

5541
string ImageSizeDescription(Artifact artifact)
5642
{
@@ -60,27 +46,4 @@
6046
return "Landscape";
6147
return "Portrait";
6248
}
63-
64-
void RowSelected(Artifact item)
65-
{
66-
reviewItem = item;
67-
editPanelClass = "show";
68-
StateHasChanged();
69-
}
70-
71-
void Close()
72-
{
73-
editPanelClass = "hidden";
74-
reviewItem = null;
75-
}
76-
77-
async Task Save()
78-
{
79-
await autoQueryGrid!.RefreshAsync();
80-
}
81-
82-
async Task Delete()
83-
{
84-
await autoQueryGrid!.RefreshAsync();
85-
}
8649
}
Lines changed: 18 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,27 @@
11
@inherits AuthBlazorComponentBase
22
@inject NavigationManager NavigationManager
33

4-
<AutoQueryGrid Model="ArtifactReport" Apis="Apis.AutoQuery<QueryArtifactReports, UpdateArtifactReport>()"
5-
@ref="autoQueryGrid"
6-
RowSelected="RowSelected">
4+
<AutoQueryGrid @ref="grid" Model="ArtifactReport" Apis="Apis.AutoQuery<QueryArtifactReports,UpdateArtifactReport>()">
75
<EditForm>
8-
@if (reviewItem != null)
9-
{
106
<div class="relative z-10" aria-labelledby="slide-over-title" role="dialog" aria-modal="true">
11-
<div class="">
12-
<div class="">
13-
<div class="pointer-events-none fixed inset-y-0 right-0 flex max-w-full pl-10 sm:pl-16">
14-
<ArtifactEdit Artifact="reviewItem.Artifact" OnClose="Close" OnSave="Save" EditPanelClass=@editPanelClass>
15-
<div class="flex flex-1 flex-col justify-between">
16-
<div class="divide-y divide-gray-200 px-4 sm:px-6">
17-
<div class="space-y-6 pt-6 pb-5">
18-
<h2>Artifact Report Info (@reviewItem.Type)</h2>
19-
<div>
20-
<TextInput @bind-Value="reviewItem.AppUserId" disabled />
21-
</div>
22-
<div>
23-
<TextInput @bind-Value="reviewItem.Description" disabled />
24-
</div>
25-
</div>
7+
<div class="pointer-events-none fixed inset-y-0 right-0 flex max-w-full pl-10 sm:pl-16">
8+
<ArtifactEdit Artifact="context.Artifact" OnClose="grid!.OnEditDone" OnSave="_ => SaveAsync(context)">
9+
<div class="flex flex-1 flex-col justify-between">
10+
<div class="divide-y divide-gray-200 px-4 sm:px-6">
11+
<div class="space-y-6 pt-6 pb-5">
12+
<h2>Artifact Report Info (@context.Type)</h2>
13+
<div>
14+
<TextInput @bind-Value="context.AppUserId" disabled />
15+
</div>
16+
<div>
17+
<TextInput @bind-Value="context.Description" disabled />
2618
</div>
2719
</div>
28-
</ArtifactEdit>
20+
</div>
2921
</div>
30-
</div>
22+
</ArtifactEdit>
3123
</div>
3224
</div>
33-
}
3425
</EditForm>
3526
<Columns>
3627
<Column Title="Artifact" Field="(ArtifactReport x) => x.ArtifactId">
@@ -51,37 +42,20 @@
5142
</AutoQueryGrid>
5243

5344
@code {
54-
AutoQueryGrid<ArtifactReport>? autoQueryGrid;
55-
public ArtifactReport? reviewItem = null;
56-
57-
string editPanelClass = "show";
45+
AutoQueryGrid<ArtifactReport>? grid;
5846

5947
void NavigateToArtifact(int artifactId)
6048
{
6149
NavigationManager.NavigateTo($"/admin/artifacts?id={artifactId}&tab=All");
6250
}
6351

64-
void RowSelected(ArtifactReport item)
65-
{
66-
reviewItem = item;
67-
editPanelClass = "show";
68-
StateHasChanged();
69-
}
70-
71-
void Close()
72-
{
73-
editPanelClass = "hidden";
74-
reviewItem = null;
75-
}
76-
77-
async Task Save()
52+
async Task SaveAsync(ArtifactReport reviewItem)
7853
{
7954
var request = new DeleteArtifactReport
8055
{
81-
ArtifactId = reviewItem!.ArtifactId
56+
ArtifactId = reviewItem.ArtifactId
8257
};
8358
var api = await ApiAsync(request);
84-
await autoQueryGrid!.RefreshAsync();
59+
await grid!.RefreshAsync();
8560
}
86-
8761
}

0 commit comments

Comments
 (0)