From 62e1f5d8e783c51e9fb773fe9c6eca6596e0bb40 Mon Sep 17 00:00:00 2001 From: Josh Deck Date: Thu, 12 Sep 2024 10:13:00 -0400 Subject: [PATCH] Fixed resolution bugs after viewing a shop or filtering by state --- TSC2/Components/CSharp/DatabaseManager.cs | 54 ++++++++-- TSC2/Components/Layout/MainLayout.razor | 22 ++-- TSC2/Components/Layout/MainLayout.razor.cs | 9 +- TSC2/Components/Layout/_NavMenu.razor | 29 ----- TSC2/Components/Pages/Browse.razor | 96 ++++++++++++++++- TSC2/Components/Pages/Browse.razor.cs | 9 ++ TSC2/Components/Pages/BrowseState.razor | 118 +++++++++++++++++---- TSC2/Components/Pages/Component.razor | 11 -- TSC2/Components/Pages/Counter.razor | 18 ---- TSC2/Components/Pages/FacebookSignIn.razor | 4 +- TSC2/Components/Pages/GoogleSignIn.razor | 4 +- TSC2/Components/Pages/Home.razor | 10 +- TSC2/Components/Pages/Home.razor.cs | 5 +- TSC2/Components/Pages/Info.razor | 60 +---------- TSC2/Components/Pages/Weather.razor | 63 ----------- TSC2/wwwroot/js/clickableMap.js | 6 -- 16 files changed, 274 insertions(+), 244 deletions(-) delete mode 100644 TSC2/Components/Layout/_NavMenu.razor create mode 100644 TSC2/Components/Pages/Browse.razor.cs delete mode 100644 TSC2/Components/Pages/Component.razor delete mode 100644 TSC2/Components/Pages/Counter.razor delete mode 100644 TSC2/Components/Pages/Weather.razor diff --git a/TSC2/Components/CSharp/DatabaseManager.cs b/TSC2/Components/CSharp/DatabaseManager.cs index 0e98694..b394766 100644 --- a/TSC2/Components/CSharp/DatabaseManager.cs +++ b/TSC2/Components/CSharp/DatabaseManager.cs @@ -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 tuple = new Tuple(uniqueID, shopName, address, score); results.Add(tuple); @@ -88,6 +87,45 @@ namespace TSC2.Components.CSharp + public static void UpdateShopScore(string shopID) + { + List 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) { diff --git a/TSC2/Components/Layout/MainLayout.razor b/TSC2/Components/Layout/MainLayout.razor index 72765bc..2c9dd8d 100644 --- a/TSC2/Components/Layout/MainLayout.razor +++ b/TSC2/Components/Layout/MainLayout.razor @@ -44,16 +44,9 @@ - @@ -63,14 +56,6 @@
@Body
- - -
- An unhandled error has occurred. - Reload - - 🗙 -
@@ -80,6 +65,11 @@ + + + + + diff --git a/TSC2/Components/Layout/MainLayout.razor.cs b/TSC2/Components/Layout/MainLayout.razor.cs index cda628e..e7beefd 100644 --- a/TSC2/Components/Layout/MainLayout.razor.cs +++ b/TSC2/Components/Layout/MainLayout.razor.cs @@ -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 Session = new Dictionary(); - - + public static bool isSignedIn = false; + public static void UpdateGreeting() { @@ -28,6 +30,7 @@ public void SignOut() { Session = new Dictionary(); + isSignedIn = false; _navigationManager.NavigateTo("/"); } } diff --git a/TSC2/Components/Layout/_NavMenu.razor b/TSC2/Components/Layout/_NavMenu.razor deleted file mode 100644 index 2d4d214..0000000 --- a/TSC2/Components/Layout/_NavMenu.razor +++ /dev/null @@ -1,29 +0,0 @@ - - - - - \ No newline at end of file diff --git a/TSC2/Components/Pages/Browse.razor b/TSC2/Components/Pages/Browse.razor index 03105a4..9f555b1 100644 --- a/TSC2/Components/Pages/Browse.razor +++ b/TSC2/Components/Pages/Browse.razor @@ -9,7 +9,7 @@ Code for the map is found in wwwroot/js/clickableMap.js --> @page "/browse" - +Browse | The Shop Critics + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
AlabamaAlaskaArizonaArkansasCalifornia
ColoradoConnecticutDelawareDistrict of ColumbiaFlorida
GeorgiaHawaiiIdahoIllinoisIndiana
IowaKansasKentuckyLouisianaMaine
MarylandMassachusettsMichiganMinnesotaMississippi
MissouriMontanaNebraskaNevadaNew Hampshire
New JerseyNew MexicoNew YorkNorth CarolinaNorth Dakota
OhioOklahomaOregonPennsylvaniaRhode Island
South CarolinaSouth DakotaTennesseeTexasUath
VermontVirginiaWashingtonWest VirginiaWisconsin
Wyoming
\ No newline at end of file diff --git a/TSC2/Components/Pages/Browse.razor.cs b/TSC2/Components/Pages/Browse.razor.cs new file mode 100644 index 0000000..18d67a4 --- /dev/null +++ b/TSC2/Components/Pages/Browse.razor.cs @@ -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"; + } +} diff --git a/TSC2/Components/Pages/BrowseState.razor b/TSC2/Components/Pages/BrowseState.razor index da2a8b6..32a9207 100644 --- a/TSC2/Components/Pages/BrowseState.razor +++ b/TSC2/Components/Pages/BrowseState.razor @@ -2,37 +2,111 @@ @using TSC2.Components.CSharp; +@State | The Shop Critics -

@State

-

@results

- - + else + { +

Invalid state.

+ } + + - @code { - [Parameter] - public string State { get; set; } = "MI"; - private string results = "No results found."; - private List> filterResults = new(); +@code { + [Parameter] + public string State { get; set; } = "MI"; + private string results = "No results found."; + private List> 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().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 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 + } } \ No newline at end of file diff --git a/TSC2/Components/Pages/Component.razor b/TSC2/Components/Pages/Component.razor deleted file mode 100644 index 8848774..0000000 --- a/TSC2/Components/Pages/Component.razor +++ /dev/null @@ -1,11 +0,0 @@ -@page "/map" - - -Say Hello -@code { - - void SayHelloHandler() - { - Console.WriteLine("TRYING"); - } -} \ No newline at end of file diff --git a/TSC2/Components/Pages/Counter.razor b/TSC2/Components/Pages/Counter.razor deleted file mode 100644 index ef23cb3..0000000 --- a/TSC2/Components/Pages/Counter.razor +++ /dev/null @@ -1,18 +0,0 @@ -@page "/counter" - -Counter - -

Counter

- -

Current count: @currentCount

- - - -@code { - private int currentCount = 0; - - private void IncrementCount() - { - currentCount++; - } -} diff --git a/TSC2/Components/Pages/FacebookSignIn.razor b/TSC2/Components/Pages/FacebookSignIn.razor index 149229c..f9a8a1a 100644 --- a/TSC2/Components/Pages/FacebookSignIn.razor +++ b/TSC2/Components/Pages/FacebookSignIn.razor @@ -4,7 +4,7 @@ @using TSC2.Components.CSharp; @page "/signin-facebook" - +The Shop Critics @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 diff --git a/TSC2/Components/Pages/GoogleSignIn.razor b/TSC2/Components/Pages/GoogleSignIn.razor index 9795506..b655050 100644 --- a/TSC2/Components/Pages/GoogleSignIn.razor +++ b/TSC2/Components/Pages/GoogleSignIn.razor @@ -4,11 +4,10 @@ @using TSC2.Components.CSharp; @page "/signin-google" - +The Shop Critics @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 diff --git a/TSC2/Components/Pages/Home.razor b/TSC2/Components/Pages/Home.razor index 3eb32f3..023956d 100644 --- a/TSC2/Components/Pages/Home.razor +++ b/TSC2/Components/Pages/Home.razor @@ -142,19 +142,18 @@ -
+
+
- +
- +
@@ -223,7 +222,6 @@ { string destination = "/info/" + CurrentSelection + "&" + CurrentUniqueID; NavManager.NavigateTo(destination); - } } diff --git a/TSC2/Components/Pages/Home.razor.cs b/TSC2/Components/Pages/Home.razor.cs index bb5cdfb..d85bc14 100644 --- a/TSC2/Components/Pages/Home.razor.cs +++ b/TSC2/Components/Pages/Home.razor.cs @@ -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; } = "© OpenStreetMap contributors"; + private bool initialized = false; diff --git a/TSC2/Components/Pages/Info.razor b/TSC2/Components/Pages/Info.razor index f722dc0..6edc270 100644 --- a/TSC2/Components/Pages/Info.razor +++ b/TSC2/Components/Pages/Info.razor @@ -1,6 +1,6 @@ @page "/info/{Shop}&{UniqueID}" - +@Shop | The Shop Critics @@ -39,58 +39,18 @@ - - - -
- - -
- -
- -
- -
- - Canvas Logo - -

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!

- -
- -

Quick Contact

-
-
-
-
-
-
-
- - - - - - -
- -
+ -
-
- -
-
+
-
+
@@ -460,10 +420,6 @@ ============================================= -->
- -
- @@ -471,10 +427,4 @@ - - -@code{ - private void TestFunction() { - Console.WriteLine(Shop); - } -} \ No newline at end of file + \ No newline at end of file diff --git a/TSC2/Components/Pages/Weather.razor b/TSC2/Components/Pages/Weather.razor deleted file mode 100644 index 8eca4cc..0000000 --- a/TSC2/Components/Pages/Weather.razor +++ /dev/null @@ -1,63 +0,0 @@ -@page "/weather" - -Weather - -

Weather

- -

This component demonstrates showing data.

- -@if (forecasts == null) -{ -

Loading...

-} -else -{ - - - - - - - - - - - @foreach (var forecast in forecasts) - { - - - - - - - } - -
DateTemp. (C)Temp. (F)Summary
@forecast.Date.ToShortDateString()@forecast.TemperatureC@forecast.TemperatureF@forecast.Summary
-} - -@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); - } -} diff --git a/TSC2/wwwroot/js/clickableMap.js b/TSC2/wwwroot/js/clickableMap.js index fb8a5eb..eb67772 100644 --- a/TSC2/wwwroot/js/clickableMap.js +++ b/TSC2/wwwroot/js/clickableMap.js @@ -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 = ''; - 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