Files
sbox-public/game/addons/menu/Code/Modals/ReviewModal.razor

115 lines
3.1 KiB
Plaintext

@namespace MenuProject.Modals
@inherits MenuProject.Modals.BaseModal
@using Sandbox;
@using Sandbox.UI;
@using Menu;
@using System;
@using Sandbox.Services;
@if (Package is null) return;
@if (_posting)
{
<root class="posting">
<i>outgoing_mail</i>
</root>
return;
}
<root>
<h1>What did you think of @(Package.Title)?</h1>
<div class="inner">
<div class="container">
<div class="ratings">
<div class="rating @( Score == Review.ReviewScore.Negative ? "active" : "" )" @onclick="@( () => SetRating( Review.ReviewScore.Negative ) )">
<div class="icon">💩</div>
<div class="text">Needs Work</div>
</div>
<div class="rating @( Score == Review.ReviewScore.Promise ? "active" : "" )" @onclick="@( () => SetRating( Review.ReviewScore.Promise ) )">
<div class="icon">😐</div>
<div class="text">Promising</div>
</div>
<div class="rating @( Score == Review.ReviewScore.Positive ? "active" : "" )" @onclick="@( () => SetRating( Review.ReviewScore.Positive ) )">
<div class="icon">😍</div>
<div class="text">Recommended</div>
</div>
</div>
<UserComment Player="@Sandbox.Services.Players.Profile.Local">
<Content>
<TextEntry @ref=_textEntry Value:bind=@ReviewText Multiline="@true" Placeholder="Enter Your Review.."></TextEntry>
</Content>
</UserComment>
<div class="footer">
<Button @onclick="@PostReview" Disabled="@( Score == Review.ReviewScore.None || string.IsNullOrWhiteSpace(ReviewText) )" Icon="send" Text="Post Review"></Button>
</div>
</div>
</div>
</root>
@code
{
public Package Package { get; set; }
string ReviewText{ get; set; }
Review.ReviewScore Score { get; set; }
TextEntry _textEntry = default;
bool _posting;
protected override int BuildHash() => System.HashCode.Combine(Package);
protected override async Task OnParametersSetAsync()
{
var oldReview = await Sandbox.Services.Review.Get(Package.FullIdent, Sandbox.Utility.Steam.SteamId);
ReviewText = oldReview?.Content;
Score = oldReview?.Score ?? Review.ReviewScore.None;
}
protected override void OnAfterTreeRender(bool firstTime)
{
if ( firstTime )
{
_textEntry?.Focus();
}
}
void SetRating(Review.ReviewScore score )
{
Score = score;
_textEntry?.SelectAllInChildren();
_textEntry?.Focus();
}
async Task PostReview()
{
if ( Score == Review.ReviewScore.None ) return;
if ( string.IsNullOrWhiteSpace( ReviewText ) ) return;
_posting = true;
StateHasChanged();
try
{
await MenuUtility.PostReview(Package.FullIdent, Score, ReviewText);
CloseModal(true);
}
finally
{
_posting = false;
}
}
}