Now allows the user to select a post

This commit is contained in:
BOT Alex 2023-05-11 01:28:34 +02:00
parent c4cd5ec41a
commit b00df41716
2 changed files with 29 additions and 24 deletions

View File

@ -20,13 +20,15 @@
<MudGrid Spacing="8" Justify="Justify.Center">
@for (int i = 0; i < 25; i++)
{
<MudItem>
int postId = (LoadedImages.Count > i) ? LoadedImages[i] : GetRandomImageNumber();
<MudItem @onclick="() => ClickPost(postId)">
<MudPaper Class="md-8" Style="position:relative">
<MudContainer Style="position:absolute;" Class="mt-4">
<MudText Style="background-color:rgba(0, 0, 0, 0.4); backdrop-filter:blur(2px)" Class="pl-2 rounded-t-lg" Color="Color.Secondary" Typo="Typo.h6">@("@" + RandomUsernames[random.Next(0, RandomUsernames.Length)])</MudText>
<MudText Style="background-color:rgba(0, 0, 0, 0.55); backdrop-filter:blur(2px)" Class="pl-2 rounded-t-lg" Color="Color.Secondary" Typo="Typo.h6">@("@" + RandomUsernames[postId])</MudText>
</MudContainer>
<MudContainer>
<MudImage Class="rounded-lg my-4" Src="@GetRandomImage()" Height="250" Width="250"></MudImage>
<MudImage Class="rounded-lg my-4" Src="@GetImage(postId)" Height="250" Width="250"></MudImage>
</MudContainer>
</MudPaper>
</MudItem>
@ -51,7 +53,7 @@
private Random random = new Random();
const int numImages = 211;
string GetRandomImage()
int GetRandomImageNumber()
{
int selectedImage;
reselect:
@ -60,21 +62,30 @@
goto reselect;
LoadedImages.Add(selectedImage);
return $@"\images\AnimeImages\AnimeImage ({selectedImage}).jpeg";
return selectedImage;
}
string GetImage(int imageIndex)
{
return $@"\images\AnimeImages\AnimeImage ({imageIndex}).jpeg";
}
protected override void OnAfterRender(bool firstRender)
{
if (!firstRender)
{
LoadedImages.Clear();
}
}
// TODO: Add a "save post" button to each post.
string[] RandomUsernames = new string[1000];
protected override async Task OnInitializedAsync()
{
RandomUsernames = (await Http.GetStringAsync("RandomUsernames.txt")).Split("\n");
}
void ClickPost(int postImage)
{
Console.WriteLine(postImage);
}
}

View File

@ -4,24 +4,20 @@
<MudLayout Class="overflow-hidden">
<MudAppBar Elevation="1">
@* <MudIconButton Icon="@Icons.Material.Filled.Menu" Color="Color.Inherit" Edge="Edge.Start" OnClick="@((e) => ToggleDrawer())" />
*@
<MudButton Variant="Variant.Filled" Color="Color.Primary" OnClick="AddUser">Primary</MudButton>
<MudSpacer />
<MudAvatar Class="mr-n2">
<MudImage Src="images/BOTAlex.png"></MudImage>
</MudAvatar>
<MudAvatar Style="cursor:pointer" @onclick="ToggleDrawer" Variant="Variant.Outlined" Color="Color.Success" Class="mr-n2">BT</MudAvatar>
</MudAppBar>
<MudDrawer @bind-Open="@openStart" ClipMode="DrawerClipMode.Always" Breakpoint="Breakpoint.Lg" PreserveOpenState="false" Elevation="1" Variant="@DrawerVariant.Mini" OpenMiniOnHover="true">
<MudDrawer @bind-Open="@openContentDrawer" ClipMode="DrawerClipMode.Always" Breakpoint="Breakpoint.Lg" PreserveOpenState="false" Elevation="1" Variant="@DrawerVariant.Mini" OpenMiniOnHover="true">
<MudNavMenu>
<MudNavLink Match="NavLinkMatch.All" Icon="@Icons.Material.Filled.Store">Store</MudNavLink>
<MudNavLink Match="NavLinkMatch.All" Icon="@Icons.Material.Filled.Image">Posts</MudNavLink>
<MudNavLink Match="NavLinkMatch.All" Icon="@Icons.Material.Filled.LibraryBooks">Library</MudNavLink>
<MudNavLink Match="NavLinkMatch.All" Icon="@Icons.Material.Filled.Group">Community</MudNavLink>
</MudNavMenu>
</MudDrawer>
<MudDrawer Anchor="Anchor.End" @bind-Open="@openEnd" ClipMode="DrawerClipMode.Always" Breakpoint="Breakpoint.Lg" PreserveOpenState="false" Elevation="1" Variant="@DrawerVariant.Mini" OpenMiniOnHover="true">
<MudDrawer Anchor="Anchor.End" @bind-Open="@openProfileDrawer" ClipMode="DrawerClipMode.Always" Breakpoint="Breakpoint.Lg" PreserveOpenState="true" Elevation="1" Variant="@DrawerVariant.Temporary">
<MudNavMenu>
<MudNavLink Match="NavLinkMatch.All" Icon="@Icons.Material.Filled.Store">Store</MudNavLink>
<MudNavLink Match="NavLinkMatch.All" Icon="@Icons.Material.Filled.LibraryBooks">Library</MudNavLink>
@ -37,15 +33,13 @@
@code {
bool openStart = false;
bool openEnd = false;
bool openContentDrawer = false;
bool openProfileDrawer = false;
void ToggleDrawer(Anchor anchor)
void ToggleDrawer()
{
if (anchor == Anchor.Start)
openStart = !openStart;
if (anchor == Anchor.End)
openEnd = !openEnd;
Console.WriteLine("Open!");
openProfileDrawer = !openProfileDrawer;
}
void getPos()