Add project files.
This commit is contained in:
18
Pages/Counter.razor
Normal file
18
Pages/Counter.razor
Normal file
@@ -0,0 +1,18 @@
|
||||
@page "/counter"
|
||||
|
||||
<PageTitle>Counter</PageTitle>
|
||||
|
||||
<h1>Counter</h1>
|
||||
|
||||
<p role="status">Current count: @currentCount</p>
|
||||
|
||||
<button class="btn btn-primary" @onclick="IncrementCount">Click me</button>
|
||||
|
||||
@code {
|
||||
private int currentCount = 0;
|
||||
|
||||
private void IncrementCount()
|
||||
{
|
||||
currentCount++;
|
||||
}
|
||||
}
|
||||
42
Pages/Error.cshtml
Normal file
42
Pages/Error.cshtml
Normal file
@@ -0,0 +1,42 @@
|
||||
@page
|
||||
@model LiveChat.Pages.ErrorModel
|
||||
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
|
||||
<title>Error</title>
|
||||
<link href="~/css/bootstrap/bootstrap.min.css" rel="stylesheet" />
|
||||
<link href="~/css/site.css" rel="stylesheet" asp-append-version="true" />
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<div class="main">
|
||||
<div class="content px-4">
|
||||
<h1 class="text-danger">Error.</h1>
|
||||
<h2 class="text-danger">An error occurred while processing your request.</h2>
|
||||
|
||||
@if (Model.ShowRequestId)
|
||||
{
|
||||
<p>
|
||||
<strong>Request ID:</strong> <code>@Model.RequestId</code>
|
||||
</p>
|
||||
}
|
||||
|
||||
<h3>Development Mode</h3>
|
||||
<p>
|
||||
Swapping to the <strong>Development</strong> environment displays detailed information about the error that occurred.
|
||||
</p>
|
||||
<p>
|
||||
<strong>The Development environment shouldn't be enabled for deployed applications.</strong>
|
||||
It can result in displaying sensitive information from exceptions to end users.
|
||||
For local debugging, enable the <strong>Development</strong> environment by setting the <strong>ASPNETCORE_ENVIRONMENT</strong> environment variable to <strong>Development</strong>
|
||||
and restarting the app.
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
27
Pages/Error.cshtml.cs
Normal file
27
Pages/Error.cshtml.cs
Normal file
@@ -0,0 +1,27 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Mvc.RazorPages;
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace LiveChat.Pages
|
||||
{
|
||||
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
|
||||
[IgnoreAntiforgeryToken]
|
||||
public class ErrorModel : PageModel
|
||||
{
|
||||
public string? RequestId { get; set; }
|
||||
|
||||
public bool ShowRequestId => !string.IsNullOrEmpty(RequestId);
|
||||
|
||||
private readonly ILogger<ErrorModel> _logger;
|
||||
|
||||
public ErrorModel(ILogger<ErrorModel> logger)
|
||||
{
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public void OnGet()
|
||||
{
|
||||
RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier;
|
||||
}
|
||||
}
|
||||
}
|
||||
47
Pages/FetchData.razor
Normal file
47
Pages/FetchData.razor
Normal file
@@ -0,0 +1,47 @@
|
||||
@page "/fetchdata"
|
||||
@using LiveChat.Data
|
||||
@inject WeatherForecastService ForecastService
|
||||
|
||||
<PageTitle>Weather forecast</PageTitle>
|
||||
|
||||
<h1>Weather forecast</h1>
|
||||
|
||||
<p>This component demonstrates fetching data from a service.</p>
|
||||
|
||||
@if (forecasts == null)
|
||||
{
|
||||
<p><em>Loading...</em></p>
|
||||
}
|
||||
else
|
||||
{
|
||||
<table class="table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Date</th>
|
||||
<th>Temp. (C)</th>
|
||||
<th>Temp. (F)</th>
|
||||
<th>Summary</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@foreach (var forecast in forecasts)
|
||||
{
|
||||
<tr>
|
||||
<td>@forecast.Date.ToShortDateString()</td>
|
||||
<td>@forecast.TemperatureC</td>
|
||||
<td>@forecast.TemperatureF</td>
|
||||
<td>@forecast.Summary</td>
|
||||
</tr>
|
||||
}
|
||||
</tbody>
|
||||
</table>
|
||||
}
|
||||
|
||||
@code {
|
||||
private WeatherForecast[]? forecasts;
|
||||
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
forecasts = await ForecastService.GetForecastAsync(DateOnly.FromDateTime(DateTime.Now));
|
||||
}
|
||||
}
|
||||
97
Pages/Index.razor
Normal file
97
Pages/Index.razor
Normal file
@@ -0,0 +1,97 @@
|
||||
@page "/"
|
||||
@using LiveChat.Models;
|
||||
@using Microsoft.AspNetCore.SignalR.Client
|
||||
@inject NavigationManager Navigation
|
||||
@implements IAsyncDisposable
|
||||
|
||||
<PageTitle>LiveChat app</PageTitle>
|
||||
|
||||
<p>Sortert fra topp-bunn</p>
|
||||
|
||||
@if (msgs != null)
|
||||
{
|
||||
<div class="MessagesList" id="messagesList">
|
||||
@foreach (var message in msgs)
|
||||
{
|
||||
<div class="message">@message</div>
|
||||
}
|
||||
</div>
|
||||
} else
|
||||
{
|
||||
<h1>Ingen meldinger tilgjengelig.</h1>
|
||||
}
|
||||
|
||||
<div class="messageFormContainer">
|
||||
@if (messageModel == null)
|
||||
{
|
||||
<p>laster inn meldingsboks</p>
|
||||
}
|
||||
else
|
||||
{
|
||||
<EditForm Model="@messageModel" OnValidSubmit="@HandleSubmit" class="MessageForm">
|
||||
<DataAnnotationsValidator />
|
||||
<div class="MessageFormValidation">
|
||||
<ValidationSummary />
|
||||
</div>
|
||||
|
||||
<div class="MessageFormInputs">
|
||||
<input @bind-value="messageModel.User" placeholder="Navn" class="MessageFormName" />
|
||||
<input @bind-value="messageModel.Message" placeholder="Skriv inn din melding..." class="MessageFormMessage" />
|
||||
<button type="submit" disabled="@(!IsConnected)" class="MessageFormButton">Send melding!</button>
|
||||
</div>
|
||||
</EditForm>
|
||||
}
|
||||
</div>
|
||||
@code {
|
||||
private HubConnection? hubConnection;
|
||||
private MessageModel messageModel = new MessageModel() { User = "", Message = "" };
|
||||
private List<string> msgs = new List<string>();
|
||||
|
||||
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
Console.WriteLine(messageModel);
|
||||
hubConnection = new HubConnectionBuilder()
|
||||
.WithUrl(Navigation.ToAbsoluteUri("/chathub"))
|
||||
.Build();
|
||||
|
||||
using (var db = new ChattingContext())
|
||||
{
|
||||
var messages = db.Messages.ToList();
|
||||
|
||||
foreach (var msg in messages)
|
||||
{
|
||||
var encodedMsg = $"{msg.User}: {msg.Message}";
|
||||
msgs.Add(encodedMsg);
|
||||
InvokeAsync(StateHasChanged);
|
||||
}
|
||||
}
|
||||
|
||||
hubConnection.On<string, string>("ReceiveMessage", (user, message) => {
|
||||
var encodedMsg = $"{user}: {message}";
|
||||
msgs.Add(encodedMsg);
|
||||
InvokeAsync(StateHasChanged);
|
||||
});
|
||||
|
||||
await hubConnection.StartAsync();
|
||||
}
|
||||
|
||||
private async Task HandleSubmit()
|
||||
{
|
||||
if (hubConnection is not null)
|
||||
{
|
||||
await hubConnection.SendAsync("SendMessage", messageModel.User, messageModel.Message);
|
||||
}
|
||||
}
|
||||
|
||||
public bool IsConnected =>
|
||||
hubConnection?.State == HubConnectionState.Connected;
|
||||
|
||||
public async ValueTask DisposeAsync()
|
||||
{
|
||||
if (hubConnection is not null)
|
||||
{
|
||||
await hubConnection.DisposeAsync();
|
||||
}
|
||||
}
|
||||
}
|
||||
34
Pages/_Host.cshtml
Normal file
34
Pages/_Host.cshtml
Normal file
@@ -0,0 +1,34 @@
|
||||
@page "/"
|
||||
@using Microsoft.AspNetCore.Components.Web
|
||||
@namespace LiveChat.Pages
|
||||
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
|
||||
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<base href="~/" />
|
||||
<link rel="stylesheet" href="css/bootstrap/bootstrap.min.css" />
|
||||
<link href="css/site.css" rel="stylesheet" />
|
||||
<link href="LiveChat.styles.css" rel="stylesheet" />
|
||||
<link rel="icon" type="image/png" href="favicon.png"/>
|
||||
<component type="typeof(HeadOutlet)" render-mode="ServerPrerendered" />
|
||||
</head>
|
||||
<body>
|
||||
<component type="typeof(App)" render-mode="ServerPrerendered" />
|
||||
|
||||
<div id="blazor-error-ui">
|
||||
<environment include="Staging,Production">
|
||||
An error has occurred. This application may no longer respond until reloaded.
|
||||
</environment>
|
||||
<environment include="Development">
|
||||
An unhandled exception has occurred. See browser dev tools for details.
|
||||
</environment>
|
||||
<a href="" class="reload">Reload</a>
|
||||
<a class="dismiss">🗙</a>
|
||||
</div>
|
||||
|
||||
<script src="_framework/blazor.server.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user