Skip to content

Commit

Permalink
The most significant changes involve the addition of a new Alphabet
Browse files Browse the repository at this point in the history
… component and the removal of the `WeatherForecastFunction` and `Weather.razor` files. The `Alphabet` component fetches data from an `alphabet.json` file and displays it in a table. The `alphabet.json` file, which contains a JSON array of alphabet words and corresponding picture URLs, has been added to both the `App_Data` and `wwwroot\sample-data` directories. The `WeatherForecastFunction` and `Weather.razor` files, which were likely related to a weather forecasting feature, have been completely removed.

Here is a list of the changes:

1. The `Api.csproj` file was updated to include a new `ItemGroup` that removes and includes the `alphabet.json` file in the `App_Data` directory. This file is set to always copy to the output directory and is excluded from single file deployments. It is also set to preserve the newest version when publishing.
2. The `launchSettings.json` file was updated to change the `launchBrowser` setting from `false` to `true`.
3. The `WeatherForecastFunction.cs` file was completely removed.
4. The `Client.csproj` file was updated to include a new `ItemGroup` that updates the `alphabet.json` file in the `wwwroot\sample-data` directory. This file is set to always copy to the output directory.
5. The `Home.razor` file was updated to replace the `Hello, world!` message and welcome message with the `Alphabet` component.
6. The `Weather.razor` file was completely removed.
7. The `Program.cs` file was updated to change the `HttpClient` service registration. The base address of the `HttpClient` is now always the host environment's base address, regardless of the `API_Prefix` configuration setting.
8. The `weather.json` file was completely removed.
9. A new `TalonAlphabetFunction.cs` file was added. This file defines a new Azure Function that reads the `alphabet.json` file from the `App_Data` directory and returns its contents as a JSON response.
10. A new `alphabet.json` file was added in the `App_Data` directory. This file contains a JSON array of alphabet words and corresponding picture URLs.
11. A new `Alphabet.razor` file was added. This file defines a new `Alphabet` component that fetches the alphabet data from the `alphabet.json` file and displays it in a table.
12. A new `Alphabet.razor.cs` file was added. This file defines the code-behind for the `Alphabet` component. It fetches the alphabet data from the `alphabet.json` file and handles any exceptions that occur during the fetch operation.
13. A new `alphabet.json` file was added in the `wwwroot\sample-data` directory. This file contains a JSON array of alphabet words and corresponding picture URLs.
  • Loading branch information
Mark-Phillipson committed Dec 25, 2023
1 parent e47d982 commit 8e28e41
Show file tree
Hide file tree
Showing 13 changed files with 360 additions and 144 deletions.
10 changes: 10 additions & 0 deletions Api/Api.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,16 @@
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<None Remove="App_Data\alphabet.json" />
</ItemGroup>
<ItemGroup>
<Content Include="App_Data\alphabet.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
<ExcludeFromSingleFile>true</ExcludeFromSingleFile>
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
</Content>
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Azure.Functions.Worker" Version="1.8.0" />
<PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.Http" Version="3.0.13" />
Expand Down
106 changes: 106 additions & 0 deletions Api/App_Data/alphabet.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
[
{
"alphabetWord": "Act",
"pictureUrl": "https://voicelauncherblazor.azurewebsites.net/images/act.jpeg"
},
{
"alphabetWord": "Bat",
"pictureUrl": "https://voicelauncherblazor.azurewebsites.net/images/bat.jpg"
},
{
"alphabetWord": "Cat",
"pictureUrl": "https://voicelauncherblazor.azurewebsites.net/images/cat.jpg"
},
{
"alphabetWord": "Drum",
"pictureUrl": "https://voicelauncherblazor.azurewebsites.net/images/drum.jpeg"
},
{
"alphabetWord": "Echo",
"pictureUrl": "https://voicelauncherblazor.azurewebsites.net/images/echo.jpeg"
},
{
"alphabetWord": "Fox",
"pictureUrl": "https://voicelauncherblazor.azurewebsites.net/images/fox.jpeg"
},
{
"alphabetWord": "Golf",
"pictureUrl": "https://voicelauncherblazor.azurewebsites.net/images/golf.jpeg"
},
{
"alphabetWord": "Hot",
"pictureUrl": "https://voicelauncherblazor.azurewebsites.net/images/hot.jpeg"
},
{
"alphabetWord": "sIt",
"pictureUrl": "https://voicelauncherblazor.azurewebsites.net/images/sit.jpeg"
},
{
"alphabetWord": "Jury",
"pictureUrl": "https://voicelauncherblazor.azurewebsites.net/images/jury.jpeg"
},
{
"alphabetWord": "Krunch",
"pictureUrl": "https://voicelauncherblazor.azurewebsites.net/images/crunch.jpeg"
},
{
"alphabetWord": "Look",
"pictureUrl": "https://voicelauncherblazor.azurewebsites.net/images/look.jpeg"
},
{
"alphabetWord": "Mike",
"pictureUrl": "https://voicelauncherblazor.azurewebsites.net/images/mike.jpeg"
},
{
"alphabetWord": "Near",
"pictureUrl": "https://voicelauncherblazor.azurewebsites.net/images/near.jpeg"
},
{
"alphabetWord": "Odd",
"pictureUrl": "https://voicelauncherblazor.azurewebsites.net/images/odd.jpeg"
},
{
"alphabetWord": "Pit",
"pictureUrl": "https://voicelauncherblazor.azurewebsites.net/images/pit.jpg"
},
{
"alphabetWord": "Quench",
"pictureUrl": "https://voicelauncherblazor.azurewebsites.net/images/quench.jpg"
},
{
"alphabetWord": "Red",
"pictureUrl": "https://voicelauncherblazor.azurewebsites.net/images/red.jpg"
},
{
"alphabetWord": "Sun",
"pictureUrl": "https://voicelauncherblazor.azurewebsites.net/images/sun.jpeg"
},
{
"alphabetWord": "Trap",
"pictureUrl": "https://voicelauncherblazor.azurewebsites.net/images/trap.jpeg"
},
{
"alphabetWord": "Urge",
"pictureUrl": "https://voicelauncherblazor.azurewebsites.net/images/urge.jpg"
},
{
"alphabetWord": "Vest",
"pictureUrl": "https://voicelauncherblazor.azurewebsites.net/images/vest.jpeg"
},
{
"alphabetWord": "Whale",
"pictureUrl": "https://voicelauncherblazor.azurewebsites.net/images/whale.jpeg"
},
{
"alphabetWord": "pleX",
"pictureUrl": "https://voicelauncherblazor.azurewebsites.net/images/plex.webp"
},
{
"alphabetWord": "Yank",
"pictureUrl": "https://voicelauncherblazor.azurewebsites.net/images/yank.jpeg"
},
{
"alphabetWord": "Zip",
"pictureUrl": "https://voicelauncherblazor.azurewebsites.net/images/zip.jpeg"
}
]
2 changes: 1 addition & 1 deletion Api/Properties/launchSettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"Api": {
"commandName": "Project",
"commandLineArgs": "--port 7100",
"launchBrowser": false
"launchBrowser": true
}
}
}
54 changes: 54 additions & 0 deletions Api/TalonAlphabetFunction.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
using Microsoft.Azure.Functions.Worker;
using Microsoft.Azure.Functions.Worker.Http;
using Microsoft.Extensions.Logging;
using System.Diagnostics;
using System.Net;
using System.Text.Json;
using System.Text.Json.Serialization;

namespace API {
public class TalonAlphabetFunction {
private readonly ILogger _logger;
public TalonAlphabetFunction(ILoggerFactory loggerFactory) {
_logger = loggerFactory.CreateLogger<TalonAlphabetFunction>();
}

[Function("TalonAlphabet")]
public HttpResponseData Run([HttpTrigger(AuthorizationLevel.Anonymous, "get")] HttpRequestData req) {
//var result= Http.GetFromJsonAsync<TalonAlphabet[]>("sample-data/alphabet.json");
string? basedDirectory = Path.GetDirectoryName(Process.GetCurrentProcess().MainModule?.FileName);
string jsonString = string.Empty;
if (basedDirectory != null) {
string filePath = Path.Combine(basedDirectory, "App_Data", "alphabet.json");
jsonString = File.ReadAllText(filePath);
}
TalonAlphabet? alphabetWords = JsonSerializer.Deserialize<TalonAlphabet>(jsonString);
HttpResponseData response = req.CreateResponse(HttpStatusCode.OK);
if (jsonString?.Length > 0) {
}
if (alphabetWords != null) {
}
response.WriteAsJsonAsync(alphabetWords);
return response;
}

private string GetSummary(int temp) {
var summary = "Mild";
if (temp >= 32) {
summary = "Hot";
} else if (temp <= 16 && temp > 0) {
summary = "Cold";
} else if (temp <= 0) {
summary = "Freezing";
}
return summary;
}

public class TalonAlphabet {
[JsonPropertyName("alphabetWord")]
public string AlphabetWord { get; set; } = "Act";
[JsonPropertyName("pictureUrl")]
public string PictureUrl { get; set; } = "https://somedomain.com/images/act.png";
}
}
}
48 changes: 0 additions & 48 deletions Api/WeatherForecastFunction.cs

This file was deleted.

6 changes: 6 additions & 0 deletions Client/Client.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,10 @@
<ServiceWorker Include="wwwroot\service-worker.js" PublishedContent="wwwroot\service-worker.published.js" />
</ItemGroup>

<ItemGroup>
<Content Update="wwwroot\sample-data\alphabet.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
</ItemGroup>

</Project>
38 changes: 38 additions & 0 deletions Client/Pages/Alphabet.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
@page "/alphabet"
@inject HttpClient Http

<PageTitle>Talon Alphabet</PageTitle>

<h1>Talon Alphabet</h1>

<p>Create and edit your own Talon Alphabet with pictures to remind you.</p>

@if (alphabetItems == null) {
<p><em>Loading...</em></p>
} else {
<table class="table">
<thead>
<tr>
<th>Word</th>
<th>Picture</th>
</tr>
</thead>
<tbody>
@foreach (var word in alphabetItems) {
<tr>
<td>@word.AlphabetWord</td>
<td>
<img src="@word.PictureUrl" alt="@word.AlphabetWord" width="400" />
</td>
</tr>
}
</tbody>
</table>
}
@if (!string.IsNullOrWhiteSpace(Message)) {

<div class="alert alert-warning alert-dismissible fade show" role="alert">
<strong>Warning!</strong> @Message
<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
</div>
}
34 changes: 34 additions & 0 deletions Client/Pages/Alphabet.razor.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
using System.Net.Http.Json;
using System.Text.Json;
using System.Text.Json.Serialization;

namespace Client.Pages {
public partial class Alphabet {
private TalonAlphabet[]? alphabetItems;
public string? Message { get; set; }
protected override async Task OnInitializedAsync() {
try {
alphabetItems = await Http.GetFromJsonAsync<TalonAlphabet[]>("sample-data/alphabet.json");
//alphabetItems= await Http.GetFromJsonAsync<TalonAlphabet[]>("/api/TalonAlphabet") ?? new TalonAlphabet[] { };
} catch (Exception exception) {
Message = exception.Message;
Console.WriteLine(exception.Message);
}
// try
// {
// forecasts = await Http.GetFromJsonAsync<WeatherForecast[]>("/api/WeatherForecast") ?? new WeatherForecast[] { };
// }
// catch (Exception ex)
// {
// Console.WriteLine(ex.Message);
// }
}

public class TalonAlphabet {
[JsonPropertyName("alphabetWord")]
public string AlphabetWord { get; set; } = "Act";
[JsonPropertyName("pictureUrl")]
public string PictureUrl { get; set; } = "https://somedomain.com/images/act.png";
}
}
}
4 changes: 2 additions & 2 deletions Client/Pages/Home.razor
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

<PageTitle>Home</PageTitle>

<h1>Hello, world!</h1>

Welcome to your new app.

<Alphabet />
65 changes: 0 additions & 65 deletions Client/Pages/Weather.razor

This file was deleted.

Loading

0 comments on commit 8e28e41

Please sign in to comment.