make things a little prettier

This commit is contained in:
Ryan Peters 2023-02-16 10:06:43 -05:00
parent 3690b4d639
commit 4fc2524e14
5 changed files with 72 additions and 9 deletions

View File

@ -18,6 +18,5 @@ namespace WeatherDashboard.Web.Controllers
return View(weather);
}
}
}

View File

@ -3,10 +3,12 @@
ViewData["Title"] = "Home Page";
}
<div>
@Model.Location.Region, @Model.Location.Name
<div class="location">
<div>@Model.Location.Region, @Model.Location.Name</div>
<small>Last updated on @Model.Current.LastUpdated</small>
</div>
<div>
@Model.Current.LastUpdated @Model.Current.Temperature
<div class="current-conditions">
<div class="current-temperature">@Model.Current.Temperature<span class="degrees">&#176;F</span></div>
<div class="current-condition-name">@Model.Current.ConditionName</div>
</div>

View File

@ -1,12 +1,12 @@
html {
font-size: 14px;
font-size: 20px;
}
@media (min-width: 768px) {
/*@media (min-width: 768px) {
html {
font-size: 16px;
}
}
}*/
.btn:focus, .btn:active:focus, .btn-link.nav-link:focus, .form-control:focus, .form-check-input:focus {
box-shadow: 0 0 0 0.1rem white, 0 0 0 0.25rem #258cfb;
@ -19,5 +19,23 @@ html {
body {
font-family: 'Montserrat', sans-serif;
color: #777;
color: #444;
margin:40px;
background-color: floralwhite;
}
.location small {
font-size: 14px;
}
.degrees {
font-size: 50px;
position: absolute;
margin: 20px 0 0 10px;
opacity: .6;
}
.current-temperature {
font-size: 100px;
font-weight: 500;
}

View File

@ -2,6 +2,7 @@
namespace WeatherDashboard
{
[JsonConverter(typeof(JsonPathConverter))]
public class CurrentForecast
{
[JsonProperty("last_updated")]
@ -9,5 +10,8 @@ namespace WeatherDashboard
[JsonProperty("temp_f")]
public decimal Temperature { get; set; }
[JsonProperty("condition.text")]
public string ConditionName { get; set; }
}
}

View File

@ -0,0 +1,40 @@
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System.Reflection;
namespace WeatherDashboard
{
public class JsonPathConverter : JsonConverter
{
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
{
var jsonObject = JObject.Load(reader);
var target = Activator.CreateInstance(objectType);
foreach (PropertyInfo prop in objectType.GetProperties().Where(p => p.CanRead && p.CanWrite))
{
var attribute = prop
.GetCustomAttributes(true)
.OfType<JsonPropertyAttribute>()
.FirstOrDefault();
var jsonPath = (attribute != null ? attribute.PropertyName : prop.Name);
var token = jsonObject.SelectToken(jsonPath);
if (token != null && token.Type != JTokenType.Null)
{
object value = token.ToObject(prop.PropertyType, serializer);
prop.SetValue(target, value, null);
}
}
return target;
}
// CanConvert is not called when [JsonConverter] attribute is used
public override bool CanConvert(Type objectType) => false;
public override bool CanWrite => false;
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) => throw new NotImplementedException();
}
}