-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Fix] 20 Autocomplete Bug (alternative solution) (#155)
* Fix the problem * Rename file --------- Co-authored-by: Vincent Wilms <[email protected]>
- Loading branch information
1 parent
f25775a
commit 0b1ef48
Showing
5 changed files
with
65 additions
and
59 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
// MIT License | ||
// Copyright (c) [2024] [nexus-main] | ||
|
||
using MudBlazor; | ||
|
||
namespace Nexus.UI.Core; | ||
|
||
public record Period | ||
{ | ||
internal const string SINGLE_FILE_LABEL = "Single File"; | ||
|
||
public Period(TimeSpan value) | ||
{ | ||
Value = value; | ||
} | ||
|
||
public TimeSpan Value { get; } | ||
|
||
public override string ToString() | ||
{ | ||
return Value.Equals(default) | ||
? SINGLE_FILE_LABEL | ||
: Utilities.ToUnitString(Value); | ||
} | ||
} | ||
|
||
public static class PeriodHelper | ||
{ | ||
public static Converter<Period> CreateConverter(Func<Period> getCurrentValue) | ||
{ | ||
return new() | ||
{ | ||
SetFunc = value => value != null ? value.ToString() : "", | ||
GetFunc = text => GetFunc(text, getCurrentValue()) | ||
}; | ||
} | ||
|
||
private static Period GetFunc(string? text, Period currentValue) | ||
{ | ||
/* Whenever the input is invalid, the current value of the | ||
* autocomplete input this converter belongs to is returned. | ||
* This ensures that the input's current value does not change | ||
* which in turn allows the user to continue typing until a | ||
* valid value is entered. A valid value is a number + unit, | ||
* e.g. "10 min". | ||
*/ | ||
|
||
if (text is null) | ||
return currentValue; | ||
|
||
try | ||
{ | ||
return text == Period.SINGLE_FILE_LABEL | ||
? new Period(TimeSpan.Zero) | ||
: new Period(Utilities.ToPeriod(text)); | ||
} | ||
|
||
catch | ||
{ | ||
return currentValue; | ||
} | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.