dfgsdfdfgsdfdfgsdfdfgsdf

This commit is contained in:
Alex
2023-05-20 20:28:51 +02:00
parent dc0b504114
commit c5d43489de
18 changed files with 237 additions and 159 deletions

13
Pages/Chat.razor Normal file
View File

@@ -0,0 +1,13 @@
@page "/chat/{room?}"
<PageTitle>Chat room </PageTitle>
@if(Room is null or "")
{
<p class="alert alert-info"><i class="bi bi-exclamation-circle-fill"></i> Ingen rom ble avgitt. Lag et rom og putt det i URLen.</p>
}
@code {
[Parameter]
public string? Room { get; set; }
}

View File

@@ -1,18 +0,0 @@
@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++;
}
}

View File

@@ -1,47 +0,0 @@
@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));
}
}

View File

@@ -1,56 +1,90 @@
@page "/"
@using LiveChat.Models;
@using Microsoft.AspNetCore.SignalR.Client
@inject Blazored.LocalStorage.ILocalStorageService localStorage
@inject NavigationManager Navigation
@implements IAsyncDisposable
<PageTitle>LiveChat app</PageTitle>
<p>Sortert fra topp-bunn</p>
<div class="container d-flex flex-column flex-wrap gap-4">
<div hidden="@(!ModalIsVisible)">
<EditForm Model="@userModel" OnValidSubmit="@SetUser">
<DataAnnotationsValidator />
<ValidationSummary />
<div class="giveNameMessage">
<h1>Skriv inn navnet ditt</h1>
<p>Dette kan ikke endres (helt til du oppdaterer sida)</p>
<input @bind-value="userModel.User" disabled="@(!ModalIsVisible)" placeholder="Navn" class="MessageFormName" />
<button type="submit" disabled="@(!IsConnected)" class="MessageFormButton"><i class="bi bi-send-fill"></i> Sett navn</button>
</div>
</EditForm>
</div>
<div hidden="@(!ModalIsVisible)">
<div >
<h1>Skriv inn romkode</h1>
<p>Få tak i koden av eieren av rommet eller noen som er i det.</p>
</div>
</div>
<div hidden="@(!ModalIsVisible)">
<div>
<h1>Lag et rom</h1>
<p>Snakk med venner osv.</p>
<button type="submit" disabled="@(!IsConnected)" class="MessageFormButton">Lag et tilfeldig rom</button>
</div>
</div>
</div>
@if (msgs != null)
{
<div class="MessagesList" id="messagesList">
<div class="MessagesList" id="messagesList" hidden="@(ModalIsVisible)">
@foreach (var message in msgs)
{
<div class="message">@message</div>
}
</div>
} else
}
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 class="messageFormContainer" hidden="@(ModalIsVisible)">
@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.Message" placeholder="Skriv inn din melding..." class="MessageFormMessage" />
<button type="submit" disabled="@(!IsConnected || ModalIsVisible)" class="MessageFormButton"><i class="bi bi-send-fill"></i></button>
</div>
</EditForm>
}
</div>
@code {
private HubConnection? hubConnection;
private bool ModalIsVisible = true;
private MessageModel messageModel = new MessageModel() { User = "", Message = "" };
private UserModel userModel = new UserModel() { User = "" };
private List<string> msgs = new List<string>();
protected override async Task OnInitializedAsync()
{
Console.WriteLine(messageModel);
hubConnection = new HubConnectionBuilder()
.WithUrl(Navigation.ToAbsoluteUri("/chathub"))
.Build();
@@ -63,11 +97,12 @@ else
{
var encodedMsg = $"{msg.User}: {msg.Message}";
msgs.Add(encodedMsg);
InvokeAsync(StateHasChanged);
}
await InvokeAsync(StateHasChanged);
}
hubConnection.On<string, string>("ReceiveMessage", (user, message) => {
hubConnection.On<string, string>("ReceiveMessage", (user, message) =>
{
var encodedMsg = $"{user}: {message}";
msgs.Add(encodedMsg);
InvokeAsync(StateHasChanged);
@@ -76,13 +111,35 @@ else
await hubConnection.StartAsync();
}
private async Task SetUser()
{
ModalIsVisible = false;
messageModel.User = userModel.User;
await localStorage.SetItemAsync("user", userModel.User);
}
private async Task HandleSubmit()
{
var filter = new ProfanityFilter.ProfanityFilter();
// Kjempegøy
filter.AddProfanity("faen");
filter.AddProfanity("jævla");
filter.AddProfanity("jævel");
filter.AddProfanity("homse");
filter.AddProfanity("homo");
filter.AddProfanity("neger");
filter.AddProfanity("transe");
filter.AddProfanity("dritt");
messageModel.User = filter.CensorString(messageModel.User);
messageModel.Message = filter.CensorString(messageModel.Message);
if (hubConnection is not null)
{
await hubConnection.SendAsync("SendMessage", messageModel.User, messageModel.Message);
}
}
}
public bool IsConnected =>
hubConnection?.State == HubConnectionState.Connected;

View File

@@ -10,6 +10,7 @@
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<base href="~/" />
<link rel="stylesheet" href="css/bootstrap/bootstrap.min.css" />
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.10.3/font/bootstrap-icons.css">
<link href="css/site.css" rel="stylesheet" />
<link href="LiveChat.styles.css" rel="stylesheet" />
<link rel="icon" type="image/png" href="favicon.png"/>