-
-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
fa30c35
commit 6233f7e
Showing
13 changed files
with
285 additions
and
19 deletions.
There are no files selected for viewing
106 changes: 106 additions & 0 deletions
106
Valour/Client/Components/Menus/Modals/ChangeUsernameModal.razor
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
@inject ValourClient Client | ||
@inherits Modal<ChangeUsernameModal.Params> | ||
|
||
<div class="col-md-12"> | ||
<section class="modal-bg"> | ||
<h3>Change your username</h3> | ||
<h5>@_changeUsernameMessage</h5> | ||
|
||
<div class="form-group mt-2"> | ||
<label class="m-2">New Username</label> | ||
<input id="new-username-input" type="text" autocomplete="off" class="form-control" @bind-value="@_newUsername" /> | ||
<label class="m-2">Password</label> | ||
<input id="password-input" type="password" autocomplete="current-password" class="form-control" @bind-value="@_password" /> | ||
</div> | ||
<br /> | ||
|
||
<ResultLabel Result="@_result" /> | ||
|
||
<br /> | ||
<div @onclick="@OnCancel" class="btn v-btn d-inline-block">Cancel</div> | ||
@if (_canChangeUsername) | ||
{ | ||
<div @onclick="@OnConfirm" class="btn v-btn danger d-inline-block">Confirm</div> | ||
} | ||
</section> | ||
</div> | ||
|
||
@code { | ||
public class Params {} | ||
private string _changeUsernameMessage; | ||
private bool _canChangeUsername = false; | ||
|
||
private string _newUsername = ""; | ||
private string _password = ""; | ||
|
||
private ITaskResult _result; | ||
|
||
|
||
private void OnCancel() | ||
{ | ||
Close(); | ||
} | ||
|
||
private async Task OnConfirm() | ||
{ | ||
var toastData = new ProgressToastData<TaskResult>() | ||
{ | ||
ProgressTask = Client.UpdateMyUsernameAsync(_newUsername, _password), | ||
Title = "Changing Username", | ||
Message = "Updating...", | ||
SuccessMessage = "Username updated!", | ||
}; | ||
|
||
var result = await ToastContainer.Instance.WaitToastWithTaskResult(toastData); | ||
if (result.Success) | ||
{ | ||
Close(); | ||
} | ||
else | ||
{ | ||
_result = result; | ||
StateHasChanged(); | ||
} | ||
} | ||
|
||
private void SetChangeUsernameMessage() | ||
{ | ||
var user = Client.Me; | ||
double daysSinceLastChange = 0; | ||
if (user.NameChangeTime is not null) | ||
{ | ||
daysSinceLastChange = (DateTime.UtcNow - user.NameChangeTime.Value).TotalDays; | ||
} | ||
|
||
if (user.Subscription is null) | ||
{ | ||
if (daysSinceLastChange < 30) | ||
{ | ||
var daysLeft = 30 - daysSinceLastChange; | ||
_changeUsernameMessage = $"You can change your username again in {daysLeft.ToString("F0")} {(daysLeft > 1 ? "days" : "day")}.\nStargazers can change their username every 7 days!"; | ||
} | ||
else | ||
{ | ||
_canChangeUsername = true; | ||
} | ||
} | ||
else | ||
{ | ||
if (daysSinceLastChange < 7) | ||
{ | ||
var daysLeft = 7 - daysSinceLastChange; | ||
_changeUsernameMessage = $"You can change your username again in {daysLeft.ToString("F0")} {(daysLeft > 1 ? "days" : "day")}."; | ||
} | ||
else | ||
{ | ||
_canChangeUsername = true; | ||
} | ||
} | ||
} | ||
|
||
protected override void OnInitialized() | ||
{ | ||
base.OnInitialized(); | ||
SetChangeUsernameMessage(); | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
Valour/Client/Components/Menus/Modals/ChangeUsernameModal.razor.css
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
.modal-bg { | ||
background-color: var(--main-2); | ||
border-radius: 2em; | ||
text-align: center; | ||
padding: 30px; | ||
max-width: 400px | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.