Skip to content

Commit

Permalink
#19 NuGet Search on page
Browse files Browse the repository at this point in the history
  • Loading branch information
alex-hedley committed Nov 27, 2023
1 parent 289de9f commit 09bd7fd
Show file tree
Hide file tree
Showing 10 changed files with 80 additions and 6 deletions.
12 changes: 11 additions & 1 deletion docs/NUGET.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,14 @@ info : OK https://api.nuget.org/v3-flatcontainer/mono.unix/index.json 166ms
info : GET https://api.nuget.org/v3-flatcontainer/mono.unix/7.1.0-final.1.21458.1/mono.unix.7.1.0-final.1.21458.1.nupkg
info : OK https://api.nuget.org/v3-flatcontainer/dynamiclanguageruntime/1.3.4/dynamiclanguageruntime.1.3.4.nupkg 86ms
info : OK https://api.nuget.org/v3-flatcontainer/mono.unix/7.1.0-final.1.21458.1/mono.unix.7.1.0-final.1.21458.1.nupkg 92ms
```
```

## Testing in Blazor WASM project

[Log] https://api.nuget.org/v3-flatcontainer/ironpython/index.json
[Log] Extracted IronPython.nuspec
[Log] Extracted lib/net6.0/IronPython.dll
[Log] Extracted lib/net6.0/IronPython.Modules.dll
[Log] Extracted lib/net6.0/IronPython.SQLite.dll
[Log] Extracted lib/net6.0/IronPython.Wpf.dll
[Log] Success
3 changes: 2 additions & 1 deletion src/BlazorInteractive.Compilation/AssemblyLoader.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
using System.Reflection;
using Microsoft.CodeAnalysis;
using Microsoft.Extensions.Logging;
using BlazorInteractive.Compilation;
using BlazorInteractive.Compilation.Results;
using AssemblyLoaderResult = BlazorInteractive.Compilation.Results.AssemblyLoaderResult;

namespace BlazorInteractive.Compilation;

public class AssemblyLoader : IAssemblyLoader
{
private readonly ILogger _logger;
Expand Down
2 changes: 1 addition & 1 deletion src/BlazorInteractive.ConsoleApp/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace BlazorInteractive.ConsoleApp;

class Program
{
private static readonly ILogger _logger;
private static readonly ILogger<NuGetPackageGetter> _logger;

async static Task Main(string[] args)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ record IndexResource([property:JsonPropertyName("@Id")] string Id, [property:Jso
record IndexResponse(string Version, List<IndexResource> Resources);
record PackageVersions(List<string> Versions);

public NuGetPackageGetter(ILogger logger)
public NuGetPackageGetter(ILogger<NuGetPackageGetter> logger)
{
_logger = logger;
}
Expand Down Expand Up @@ -67,6 +67,7 @@ public async Task<PackageResult> GetPackage(string name)
{
file.ExtractToFile(target);
Console.WriteLine($"Extracted {file.FullName}");
// Console.WriteLine($"{Path.GetFullPath(file.Name)}");
}
else if (file.Name.EndsWith("nuspec"))
{
Expand Down
1 change: 1 addition & 0 deletions src/BlazorInteractive/BlazorInteractive.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@

<ItemGroup>
<ProjectReference Include="..\BlazorInteractive.Compilation\BlazorInteractive.Compilation.csproj" />
<ProjectReference Include="..\BlazorInteractive.DependencyManagement\BlazorInteractive.DependencyManagement.csproj" />
</ItemGroup>

<ItemGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@
SelectedValues="@SelectedIds"
DisabledValues="@DisabledIds"
Style="@Style"
/>
/>
<NuGetComponent Data="@(null)"
/>
</div>
<div class="col-md-8">
<StandaloneCodeEditor
Expand Down
53 changes: 53 additions & 0 deletions src/BlazorInteractive/Components/Editor/NuGetComponent.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
@inject IPackageGetter NuGetPackageGetter
@inject IToastService ToastService

<div class="input-group mb-3">
<div class="input-group-prepend">
<img src="https://raw.githubusercontent.com/NuGet/Media/main/Images/MainLogo/Vector/nuget.svg"
alt="NuGet logo" height="25px" />
</div>
<input type="text" class="form-control" placeholder="Search Term" aria-label="Search Term" @bind="SearchTerm" @bind:event="oninput"/>
<div class="input-group-append">
<button class="btn btn-outline-secondary" type="button" @onclick="GetPackage">Add</button>
</div>
</div>

<div>
@if (Data != null)
{
foreach (var item in Data.Where(i => i is not null))
{
<label class="form-check-label" for="@($"{item}")">
@($"{item}")
</label>
}
}
</div>

@code {
//[Parameter]
string? SearchTerm { get; set; }

[Parameter]
public List<string> Data { get; set; } = new List<string>();

private async void GetPackage()
{
var package = await NuGetPackageGetter.GetPackage(SearchTerm);
package.Switch(
success =>
{
Console.WriteLine("Success");
ToastService.ShowSuccess("Added NuGet Package");
Data.Add(SearchTerm);
},
failure =>
{
Console.WriteLine("Failure");
ToastService.ShowError("Failed to add");
}
);
StateHasChanged();
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
img {
margin-right: 10px;
}
2 changes: 2 additions & 0 deletions src/BlazorInteractive/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using BlazorInteractive;
using BlazorInteractive.AssemblyCompilation;
using BlazorInteractive.Compilation;
using BlazorInteractive.DependencyManagement;

var builder = WebAssemblyHostBuilder.CreateDefault(args);
builder.RootComponents.Add<App>("#app");
Expand All @@ -16,6 +17,7 @@
builder.Services.AddScoped<IAssemblyInvoker, AssemblyInvoker>();
builder.Services.AddScoped<IAssemblyLoader, AssemblyLoader>();
builder.Services.AddScoped<ICSharpCompiler, CSharpCompiler>();
builder.Services.AddScoped<IPackageGetter, NuGetPackageGetter>();
builder.Services.AddBlazoredToast();

builder.Services.AddScoped(sp => new HttpClient { BaseAddress = new Uri(builder.HostEnvironment.BaseAddress) });
Expand Down
3 changes: 2 additions & 1 deletion src/BlazorInteractive/_Imports.razor
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@
@using BlazorInteractive.AssemblyCompilation
@using BlazorInteractive.Compilation
@using BlazorInteractive.Components
@using BlazorInteractive.Extensions
@using BlazorInteractive.Extensions
@using BlazorInteractive.DependencyManagement

0 comments on commit 09bd7fd

Please sign in to comment.