Skip to content

Commit a0d1126

Browse files
committed
Enhance file upload and notification features
- Updated `Documents.razor` to change form submission handler to `UploadFile` and added `id` to `InputFile`. - Implemented `UploadFile` method to handle file uploads and reset input after successful upload. - Upgraded package references in `SqlDatabaseVectorSearch.csproj` for `Microsoft.SemanticKernel` and `Swashbuckle.AspNetCore.SwaggerUI`. - Introduced `resetFileInput` function in `functions.js` to clear file input selections.
1 parent d20b139 commit a0d1126

File tree

4 files changed

+13
-8
lines changed

4 files changed

+13
-8
lines changed

SqlDatabaseVectorSearch/Components/Layout/MainLayout.razor

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
@using System.Runtime.InteropServices
2-
3-
@inherits LayoutComponentBase
1+
@inherits LayoutComponentBase
42

53
<Toasts class="p-3" AutoHide="true" Placement="ToastsPlacement.TopRight" />
64

SqlDatabaseVectorSearch/Components/Pages/Documents.razor

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
Upload new document
1414
</h4>
1515

16-
<EditForm Model="Model" Enhance OnValidSubmit="HandleValidSubmit">
16+
<EditForm Model="Model" Enhance OnValidSubmit="UploadFile">
1717
<DataAnnotationsValidator />
1818

1919
<div class="row">
@@ -24,7 +24,7 @@
2424
<Icon Class="d-flex text-body-secondary" Name="IconName.InfoCircle"></Icon>
2525
</Tooltip>
2626
</span>
27-
<InputFile class="form-control" OnChange="@((e) => Model.File = e.File)" accept=".pdf,.docx,.txt,.md" />
27+
<InputFile class="form-control" OnChange="@((e) => Model.File = e.File)" accept=".pdf,.docx,.txt,.md" id="fileInput" />
2828
</div>
2929
</div>
3030
<div class="col-md-5 col-sm-5 col-5">
@@ -149,7 +149,7 @@ else
149149
}
150150
}
151151

152-
private async Task HandleValidSubmit()
152+
private async Task UploadFile()
153153
{
154154
if (Model.File is null)
155155
{
@@ -173,6 +173,9 @@ else
173173

174174
ToastService.Notify(await CreateToastMessageAsync(ToastType.Success, "Upload document", $"The document {fileName} has been successfully uploaded and indexed."));
175175

176+
Model = new UploadDocument();
177+
await JSRuntime.InvokeVoidAsync("resetFileInput", "fileInput");
178+
176179
await LoadDocumentsAsync(scope.ServiceProvider);
177180
}
178181
catch (Exception ex)

SqlDatabaseVectorSearch/SqlDatabaseVectorSearch.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,11 @@
2323
<PackageReference Include="Microsoft.ML.Tokenizers" Version="1.0.2" />
2424
<PackageReference Include="Microsoft.ML.Tokenizers.Data.Cl100kBase" Version="1.0.2" />
2525
<PackageReference Include="Microsoft.ML.Tokenizers.Data.O200kBase" Version="1.0.2" />
26-
<PackageReference Include="Microsoft.SemanticKernel" Version="1.41.0" />
26+
<PackageReference Include="Microsoft.SemanticKernel" Version="1.42.0" />
2727
<PackageReference Include="MimeMapping" Version="3.1.0" />
2828
<PackageReference Include="MinimalHelpers.Routing.Analyzers" Version="1.1.3" />
2929
<PackageReference Include="PdfPig" Version="0.1.10" />
30-
<PackageReference Include="Swashbuckle.AspNetCore.SwaggerUI" Version="7.3.1" />
30+
<PackageReference Include="Swashbuckle.AspNetCore.SwaggerUI" Version="8.0.0" />
3131
<PackageReference Include="TinyHelpers.AspNetCore" Version="4.0.21" />
3232
</ItemGroup>
3333

SqlDatabaseVectorSearch/wwwroot/js/functions.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ window.scrollTo = (element) => {
1010
}
1111
}
1212

13+
window.resetFileInput = (elementId) => {
14+
document.getElementById(elementId).value = '';
15+
};
16+
1317
function getLocalTime(utcDateTime) {
1418
return new Date(utcDateTime).toLocaleString();
1519
}

0 commit comments

Comments
 (0)