Fixed resolution bugs after viewing a shop or filtering by state

This commit is contained in:
Josh Deck 2024-09-12 10:13:00 -04:00
parent 3d5c720a5d
commit 62e1f5d8e7
16 changed files with 274 additions and 244 deletions

View File

@ -9,9 +9,9 @@ namespace TSC2.Components.CSharp
{
public class DatabaseManager
{
private static string _connectionString = "Server=127.0.0.1;User ID=root;Password=root;Database=tsc2";
private static string _connectionString = MainLayout.isDev ? "Server=127.0.0.1;User ID=root;Password=root;Database=tsc2" : "PROD_CONNECTION_STRING";
private static Random rng = new Random();
/**********************************************/
// SHOP INFORMATION
@ -62,21 +62,20 @@ namespace TSC2.Components.CSharp
cmd.Parameters.AddWithValue("@state", state);
using (MySqlDataReader reader = cmd.ExecuteReader())
{
Console.WriteLine("Executed filter");
while (reader.Read())
{
Console.WriteLine("Result found");
var uniqueID = reader.GetString(0);
var shopName = reader.GetString(1);
var address = reader.GetString(2);
var score = 5.0f; // TODO: replace with average lookup. Will require a query or new field on each shop in the db
//var phone = reader.GetString(3);
//var website = reader.GetString(4);
//var hours = reader.GetString(5);
//var about = reader.GetString(6);
//double latitude = reader.GetDouble(7);
//double longitude = reader.GetDouble(8);
var score = reader.GetInt32(9); // TODO: replace with average lookup. Will require a query or new field on each shop in the db
//var reviewCount = reader.GetInt32(10);
Tuple<string, string, string, float> tuple = new Tuple<string, string, string, float>(uniqueID, shopName, address, score);
results.Add(tuple);
@ -88,6 +87,45 @@ namespace TSC2.Components.CSharp
public static void UpdateShopScore(string shopID)
{
List<int> scores = GetShopReviewScores(shopID);
int count = scores.Count;
int shopScore = 0;
foreach (int score in scores)
{
shopScore += score;
}
shopScore /= count;
if (count > 0)
{
try
{
MySqlConnection conn = new MySqlConnection(_connectionString);
conn.Open();
var cmd = new MySqlCommand();
cmd.CommandText = "UPDATE shopinformation SET ReviewScore = @shopScore, ReviewCount = @count WHERE UniqueID=@uniqueid;";
cmd.Connection = conn;
cmd.Parameters.AddWithValue("@shopScore", shopScore);
cmd.Parameters.AddWithValue("@count", count);
cmd.Parameters.AddWithValue("@uniqueid", shopID);
cmd.ExecuteNonQuery();
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
}
}
/**********************************************/
// LOGIN FLOW
/**********************************************/
@ -204,9 +242,11 @@ namespace TSC2.Components.CSharp
insert_cmd.Parameters.AddWithValue("@reviewid", reviewID);
insert_cmd.Parameters.AddWithValue("@reviewtext", "This is a review! Surely this will work on the Second Try!");
insert_cmd.Parameters.AddWithValue("@reviewscore", 1);
insert_cmd.Parameters.AddWithValue("@reviewscore", rng.Next(1, 6));
insert_cmd.ExecuteNonQuery();
UpdateShopScore(shopID);
}
catch (Exception ex)
{

View File

@ -44,16 +44,9 @@
<ul class="menu-container">
<li class="menu-item current"><a class="menu-link" href=""><div>Home</div></a></li>
<!-- Mega Menu -->
<li class="menu-item"><a class="menu-link" href="/browse"><div>Browse By State</div></a></li>
<li class="menu-item"><a class="menu-link" href="demo-car-dealers.html"><div>Dealers</div></a></li>
<li class="menu-item"><a class="menu-link" href="demo-car-accessories.html"><div>Accessories</div></a></li>
<li class="menu-item"><a class="menu-link" href="demo-car-interiors.html"><div>Interiors</div></a></li>
<li class="menu-item"><a class="menu-link" href="demo-car-faqs.html"><div>FAQs</div></a></li>
<li class="menu-item"><a class="menu-link" href="demo-car-blog.html"><div>Blog</div></a></li>
<li class="menu-item"><a class="menu-link" href="demo-car-contact.html"><div>Contacts</div></a></li>
<li class="menu-item"><a class="menu-link" href="/browse"><div>Browse By State</div></a></li>
</ul>
</nav><!-- #primary-menu end -->
</div>
</div>
</div>
@ -63,14 +56,6 @@
<main>
@Body
</main>
<div id="blazor-error-ui">
An unhandled error has occurred.
<a href="" class="reload">Reload</a>
<a class="dismiss">🗙</a>
</div>
<!-- Font Imports -->
<link rel="preconnect" href="https://fonts.googleapis.com">
@ -80,6 +65,11 @@
<!-- Core Style -->
<link rel="stylesheet" href="style.css">
<!-- Telerik Blazor -->
<link href="https://blazor.cdn.telerik.com/blazor/6.0.2/kendo-font-icons/font-icons.css" rel="stylesheet" type="text/css" />
<script src="https://blazor.cdn.telerik.com/blazor/6.0.2/telerik-blazor.min.js" defer></script>
<script src="_content/Telerik.UI.for.Blazor/js/telerik-blazor.js"></script>
<!-- Font Icons -->
<link rel="stylesheet" href="css/font-icons.css">
<link rel="stylesheet" href="demos/car/css/car-icons/style.css">

View File

@ -1,7 +1,9 @@
namespace TSC2.Components.Layout
{
public partial class MainLayout
{
{
public static readonly bool isDev = true;
public static string Greeting = "Hello, {}";
public string GoogleClientId = CSharp.Credentials.GoogleClientId;
public string GoogleClientSecret = CSharp.Credentials.GoogleClientSecret;
@ -9,8 +11,8 @@
public static string GoogleRedirect = "https://localhost:7282/signin-google";
public static string FacebookRedirect = "https://localhost:7282/signin-facebook";
public static Dictionary<string, string> Session = new Dictionary<string, string>();
public static bool isSignedIn = false;
public static void UpdateGreeting()
{
@ -28,6 +30,7 @@
public void SignOut()
{
Session = new Dictionary<string, string>();
isSignedIn = false;
_navigationManager.NavigateTo("/");
}
}

View File

@ -1,29 +0,0 @@
<div class="top-row ps-3 navbar navbar-dark">
<div class="container-fluid">
<a class="navbar-brand" href="">TSC2</a>
</div>
</div>
<input type="checkbox" title="Navigation menu" class="navbar-toggler" />
<div class="nav-scrollable" onclick="document.querySelector('.navbar-toggler').click()">
<nav class="flex-column">
<div class="nav-item px-3">
<NavLink class="nav-link" href="" Match="NavLinkMatch.All">
<span class="bi bi-house-door-fill" aria-hidden="true"></span> Home
</NavLink>
</div>
<div class="nav-item px-3">
<NavLink class="nav-link" href="counter">
<span class="bi bi-plus-square-fill" aria-hidden="true"></span> Counter
</NavLink>
</div>
<div class="nav-item px-3">
<NavLink class="nav-link" href="weather">
<span class="bi bi-list-nested" aria-hidden="true"></span> Weather
</NavLink>
</div>
</nav>
</div>

View File

@ -9,7 +9,7 @@ Code for the map is found in wwwroot/js/clickableMap.js
-->
@page "/browse"
<title>Browse | The Shop Critics</title>
<!-- CSS start (put inside <head> tag) -->
<style>
.cmm-usa {
@ -126,4 +126,96 @@ Code for the map is found in wwwroot/js/clickableMap.js
<!-- JS start -->
<script src="js/clickableMap.js"></script>
<!-- JS end -->
<!-- End of clickable map code -->
<!-- End of clickable map code -->
<br>
<br>
<br>
<style>
table th, td {
padding: 15px;
}
</style>
<table class="center" style="margin-left: auto;margin-right:auto">
<tr>
<th><a href="@baseUrl/AL">Alabama</a></th>
<th><a href="@baseUrl/AK">Alaska</a></th>
<th><a href="@baseUrl/AZ">Arizona</a></th>
<th><a href="@baseUrl/AR">Arkansas</a></th>
<th><a href="@baseUrl/CA">California</a></th>
</tr>
<tr>
<th><a href="@baseUrl/CO">Colorado</a></th>
<th><a href="@baseUrl/CT">Connecticut</a></th>
<th><a href="@baseUrl/DE">Delaware</a></th>
<th><a href="@baseUrl/DC">District of Columbia</a></th>
<th><a href="@baseUrl/FL">Florida</a></th>
</tr>
<tr>
<th><a href="@baseUrl/GA">Georgia</a></th>
<th><a href="@baseUrl/HI">Hawaii</a></th>
<th><a href="@baseUrl/ID">Idaho</a></th>
<th><a href="@baseUrl/IL">Illinois</a></th>
<th><a href="@baseUrl/IN">Indiana</a></th>
</tr>
<tr>
<th><a href="@baseUrl/IA">Iowa</a></th>
<th><a href="@baseUrl/KS">Kansas</a></th>
<th><a href="@baseUrl/KY">Kentucky</a></th>
<th><a href="@baseUrl/LA">Louisiana</a></th>
<th><a href="@baseUrl/ME">Maine</a></th>
</tr>
<tr>
<th><a href="@baseUrl/MD">Maryland</a></th>
<th><a href="@baseUrl/MA">Massachusetts</a></th>
<th><a href="@baseUrl/MI">Michigan</a></th>
<th><a href="@baseUrl/MN">Minnesota</a></th>
<th><a href="@baseUrl/MS">Mississippi</a></th>
</tr>
<tr>
<th><a href="@baseUrl/MO">Missouri</a></th>
<th><a href="@baseUrl/MT">Montana</a></th>
<th><a href="@baseUrl/NE">Nebraska</a></th>
<th><a href="@baseUrl/NV">Nevada</a></th>
<th><a href="@baseUrl/NH">New Hampshire</a></th>
</tr>
<tr>
<th><a href="@baseUrl/NJ">New Jersey</a></th>
<th><a href="@baseUrl/NM">New Mexico</a></th>
<th><a href="@baseUrl/NY">New York</a></th>
<th><a href="@baseUrl/NC">North Carolina</a></th>
<th><a href="@baseUrl/ND">North Dakota</a></th>
</tr>
<tr>
<th><a href="@baseUrl/OH">Ohio</a></th>
<th><a href="@baseUrl/OK">Oklahoma</a></th>
<th><a href="@baseUrl/OR">Oregon</a></th>
<th><a href="@baseUrl/PA">Pennsylvania</a></th>
<th><a href="@baseUrl/RI">Rhode Island</a></th>
</tr>
<tr>
<th><a href="@baseUrl/SC">South Carolina</a></th>
<th><a href="@baseUrl/SD">South Dakota</a></th>
<th><a href="@baseUrl/TN">Tennessee</a></th>
<th><a href="@baseUrl/TX">Texas</a></th>
<th><a href="@baseUrl/UT">Uath</a></th>
</tr>
<tr>
<th><a href="@baseUrl/VT">Vermont</a></th>
<th><a href="@baseUrl/VA">Virginia</a></th>
<th><a href="@baseUrl/WA">Washington</a></th>
<th><a href="@baseUrl/WV">West Virginia</a></th>
<th><a href="@baseUrl/WI">Wisconsin</a></th>
</tr>
<tr>
<th></th>
<th></th>
<th><a href="@baseUrl/WY">Wyoming</a></th>
</tr>
</table>

View File

@ -0,0 +1,9 @@
using TSC2.Components.Layout;
namespace TSC2.Components.Pages
{
public partial class Browse
{
public static readonly string baseUrl = MainLayout.isDev ? "https://localhost:7282/browse" : "https://theshopcritics.com/browse";
}
}

View File

@ -2,37 +2,111 @@
@using TSC2.Components.CSharp;
<title>@State | The Shop Critics</title>
<h1>@State</h1>
<h2>@results</h2>
<ul>
@foreach(Tuple<string, string, string, float> current in filterResults)
<body>
@if (isValid)
{
<li><a href="/info/@current.Item2&@current.Item1">@current.Item4 * | @current.Item2 | @current.Item3</a></li>
<h1>@State</h1>
<h2>@results</h2>
<ul>
@foreach (Tuple<string, string, string, float> current in filterResults)
{
<li><a href="/info/@current.Item2&@current.Item1">@current.Item4 * | @current.Item2 | @current.Item3</a></li>
}
</ul>
}
</ul>
else
{
<h1>Invalid state.</h1>
}
</body>
@code {
[Parameter]
public string State { get; set; } = "MI";
private string results = "No results found.";
private List<Tuple<string,string,string,float>> filterResults = new();
@code {
[Parameter]
public string State { get; set; } = "MI";
private string results = "No results found.";
private List<Tuple<string,string,string,float>> filterResults = new();
private bool isValid = false;
protected override Task OnInitializedAsync()
{
protected override Task OnInitializedAsync()
{
// Verify that the requested url is valid
var states = Enum.GetValues(typeof(States)).Cast<States>().ToList();
if (Enum.IsDefined(typeof(States), State))
{
// If a valid state, let it filter
isValid = true;
filterResults = DatabaseManager.FilterByState(State);
if (filterResults.Count == 0)
if (filterResults.Count == 0)
return Task.FromResult(0);
this.results = "Results:\n";
return Task.FromResult(0);
/*foreach (Tuple<string, string, string, float> current in results)
{
}*/
this.results = "Results:\n";
}
else
{
isValid = false;
}
return Task.FromResult(0);
}
private enum States
{
AL,
AK,
AR,
AZ,
CA,
CO,
CT,
DC,
DE,
FL,
GA,
HI,
IA,
ID,
IL,
IN,
KS,
KY,
LA,
MA,
MD,
ME,
MI,
MN,
MO,
MS,
MT,
NC,
ND,
NE,
NH,
NJ,
NM,
NV,
NY,
OK,
OH,
OR,
PA,
RI,
SC,
SD,
TN,
TX,
UT,
VA,
VT,
WA,
WI,
WV,
WY
}
}

View File

@ -1,11 +0,0 @@
@page "/map"
<TelerikButton OnClick="@SayHelloHandler" ThemeColor="primary">Say Hello</TelerikButton>
@code {
void SayHelloHandler()
{
Console.WriteLine("TRYING");
}
}

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

@ -4,7 +4,7 @@
@using TSC2.Components.CSharp;
@page "/signin-facebook"
<title>The Shop Critics</title>
@inject NavigationManager _navigationManager
@code {
@ -67,8 +67,10 @@
if (MainLayout.Session.Count == 0) // Fpr security, only add to the session if nothing exists in the session.
{
// Add profile to session
MainLayout.Session.Add("id", profileResponse.id);
MainLayout.Session.Add("name", profileResponse.name);
MainLayout.isSignedIn = true;
MainLayout.UpdateGreeting();
// Contact database

View File

@ -4,11 +4,10 @@
@using TSC2.Components.CSharp;
@page "/signin-google"
<title>The Shop Critics</title>
@inject NavigationManager _navigationManager
@code {
[Parameter][SupplyParameterFromQuery] public string? code { get; set; }
[Parameter][SupplyParameterFromQuery] public string? scope { get; set; }
[Parameter][SupplyParameterFromQuery] public string? authuser { get; set; }
@ -54,6 +53,7 @@
MainLayout.Session.Add("id", profileResponse.id);
MainLayout.Session.Add("email", profileResponse.email);
MainLayout.Session.Add("name", profileResponse.name);
MainLayout.isSignedIn = true;
MainLayout.UpdateGreeting();
// Contact database

View File

@ -142,19 +142,18 @@
<!-- Document Wrapper
============================================= -->
<div id="wrapper">
<div>
<!-- Slider
============================================= -->
<div id="slider" class="slider-element h-auto">
<div class="slider-inner">
<div class="row align-items-stretch flex-md-row-reverse mx-0">
<div class="col-md-8 col-sm-12 px-0 min-vh-40">
<TelerikMap @ref="@MapRef" Zoom="@Zoom" Height="@MapHeight" Center="@Center" OnMarkerClick="@OnMarkerClick">
<TelerikMap @ref="@MapRef" Zoom="@Zoom" Height="@MapHeight" Width="@MapWidth" Center="@Center" OnMarkerClick="@OnMarkerClick">
<MapLayers>
<MapLayer Type="@MapLayersType.Tile"
Attribution="@Attribution"
Subdomains="@Subdomains"
UrlTemplate="@UrlTemplate">
</MapLayer>
<MapLayer Type="@MapLayersType.Marker"
@ -165,7 +164,7 @@
</MapLayers>
</TelerikMap>
</div>
<div class="col-md-4 col-sm-12 px-0">
<div class="card bg-color rounded-0 shadow-sm p-4 h-100" style="background-color: #6aa84f">
<div class="card-body">
@ -223,7 +222,6 @@
{
string destination = "/info/" + CurrentSelection + "&" + CurrentUniqueID;
NavManager.NavigateTo(destination);
}
}
</WindowContent>

View File

@ -11,13 +11,12 @@ namespace TSC2.Components.Pages
public double Zoom { get; set; } = 1;
public static double[] Center = [40.68, 74.04];
public string MapHeight { get; set; } = "800px";
public string MapWidth { get; set; } = "1300px";
public string ShopName { get; set; } = "";
public string CSZ { get; set; } = "";
public string[] Subdomains { get; set; } = new string[] { "a", "b", "c" };
public string UrlTemplate { get; set; } = "https://#= subdomain #.tile.openstreetmap.org/#= zoom #/#= x #/#= y #.png";
public string Attribution { get; set; } = "&copy; <a href='https://osm.org/copyright'>OpenStreetMap contributors</a>";
private bool initialized = false;

View File

@ -1,6 +1,6 @@
@page "/info/{Shop}&{UniqueID}"
<title>@Shop | The Shop Critics</title>
<!DOCTYPE html>
<html dir="ltr" lang="en-US">
@ -39,58 +39,18 @@
</head>
<body class="stretched side-push-panel" data-loader-html="<div><img src='demos/car/images/page-loader.gif' alt='Loader'></div>">
<!-- Side Panel Overlay -->
<div class="body-overlay"></div>
<!-- Side Panel -->
<div id="side-panel">
<div id="side-panel-trigger-close" class="side-panel-trigger"><a href="#"><i class="bi-x-lg"></i></a></div>
<div class="side-panel-wrap">
<div class="widget">
<a href="index.html"><img src="demos/car/images/logo@2x.png" alt="Canvas Logo" height="50"></a>
<p>It has always been, and will always be, about quality. We're passionate about ethically sourcing the finest coffee beans, roasting them with great care. We'd like to hear your message!</p>
<div class="widget quick-contact-widget form-widget border-0 pt-0">
<h4>Quick Contact</h4>
<div class="form-result"></div>
<form id="quick-contact-form" name="quick-contact-form" action="include/form.php" method="post" class="quick-contact-form mb-0">
<div class="form-process">
<div class="css3-spinner">
<div class="css3-spinner-scaler"></div>
</div>
</div>
<input type="text" class="required form-control mb-2" id="quick-contact-form-name" name="quick-contact-form-name" value="" placeholder="Full Name">
<input type="text" class="required form-control email mb-2" id="quick-contact-form-email" name="quick-contact-form-email" value="" placeholder="Email Address">
<textarea class="required form-control mb-2 short-textarea" id="quick-contact-form-message" name="quick-contact-form-message" rows="4" cols="30" placeholder="Message"></textarea>
<input type="text" class="d-none" id="quick-contact-form-botcheck" name="quick-contact-form-botcheck" value="">
<input type="hidden" name="prefix" value="quick-contact-form-">
<button type="submit" id="quick-contact-form-submit" name="quick-contact-form-submit" class="button button-small button-3d m-0" value="submit">Send Email</button>
</form>
</div>
<body class="stretched side-push-panel">
</div>
</div>
</div>
<!-- Document Wrapper
============================================= -->
<div id="wrapper">
<div>
<!-- Page Title
============================================= -->
<section class="page-title page-title-parallax parallax scroll-detect dark" style="padding: 140px 0;">
<section class="page-title page-title-parallax parallax scroll-detect dark">
<img src="demos/car/images/accessories/page-title.jpg" class="parallax-bg">
<div class="container">
<div class="page-title-row">
@ -460,10 +420,6 @@
============================================= -->
<div id="gotoTop" class="uil uil-angle-up"></div>
<!-- Contact Button
============================================= -->
<div id="contact-me" class="bi-envelope side-panel-trigger bg-color"></div>
<!-- JavaScripts
============================================= -->
<script src="js/plugins.min.js"></script>
@ -471,10 +427,4 @@
</body>
</html>
@code{
private void TestFunction() {
Console.WriteLine(Shop);
}
}
</html>

View File

@ -1,63 +0,0 @@
@page "/weather"
<PageTitle>Weather</PageTitle>
<h1>Weather</h1>
<p>This component demonstrates showing data.</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()
{
// Simulate asynchronous loading to demonstrate a loading indicator
await Task.Delay(500);
var startDate = DateOnly.FromDateTime(DateTime.Now);
var summaries = new[] { "Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching" };
forecasts = Enumerable.Range(1, 5).Select(index => new WeatherForecast
{
Date = startDate.AddDays(index),
TemperatureC = Random.Shared.Next(-20, 55),
Summary = summaries[Random.Shared.Next(summaries.Length)]
}).ToArray();
}
private class WeatherForecast
{
public DateOnly Date { get; set; }
public int TemperatureC { get; set; }
public string? Summary { get; set; }
public int TemperatureF => 32 + (int)(TemperatureC / 0.5556);
}
}

View File

@ -329,12 +329,6 @@ var ClickableMap = {};
this.$map.style.fontFamily = this.globalData.fontName;
this.$map.style.fontSize = this.globalData.fontSize;
global.getEleByQuery('#' + this.$map.id + ' .' + classPrefix + 'title').textContent = this.globalData.mapTitle;
if (this.globalData.creditLink != null && this.globalData.creditLink != '') {
global.getEleByQuery('#' + this.$map.id + ' .' + classPrefix + 'credit-link').innerHTML = '<a target="_blank" href="' + creditLinkUrl + '"></a>';
global.getEleByQuery('#' + this.$map.id + ' .' + classPrefix + 'credit-link a').textContent = this.globalData.creditLink
} else {
global.getEleByQuery('#' + this.$map.id + ' .' + classPrefix + 'credit-link').innerHTML = ''
}
for (var stateId in this.statesData) {
if (!this.statesData.hasOwnProperty(stateId)) {
continue