Skip to content

Commit

Permalink
refactor(view): ♻️ refactor CommandArgument configuration class
Browse files Browse the repository at this point in the history
  • Loading branch information
JamesNZL committed May 15, 2023
1 parent e2f4286 commit 5d663a7
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 35 deletions.
56 changes: 26 additions & 30 deletions src/Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,28 +19,28 @@ public class Settings
internal const string EditProjectFlag = "-p";
internal const string TimeSpanFlag = "-t";

internal static readonly List<ViewDuration> ViewDurationArguments = new List<ViewDuration>
internal static readonly List<CommandArgument> ViewDurationArguments = new List<CommandArgument>
{
new ViewDuration
(
"day",
"today's"
),
new ViewDuration
(
"week",
"this week's"
),
new ViewDuration
(
"month",
"this month's"
),
new ViewDuration
(
"year",
"this year's"
),
new CommandArgument
{
Argument = "day",
Interpolation = "today's",
},
new CommandArgument
{
Argument = "week",
Interpolation = "this week's",
},
new CommandArgument
{
Argument = "month",
Interpolation = "this month's",
},
new CommandArgument
{
Argument = "year",
Interpolation = "this year's",
},
};

/// <Summary>
Expand All @@ -49,15 +49,11 @@ public class Settings
public string ApiToken { get; set; } = string.Empty;
}

public class ViewDuration
public class CommandArgument
{
public string argument;
public string spanString;

public ViewDuration(string argument, string spanString)
{
this.argument = argument;
this.spanString = spanString;
}
#nullable disable
public string Argument { get; set; }
public string Interpolation { get; set; }
#nullable enable
}
}
13 changes: 8 additions & 5 deletions src/TogglTrack.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1336,20 +1336,23 @@ internal async ValueTask<List<Result>> RequestViewReports(CancellationToken toke
};
}

if (query.SearchTerms.Length == 1 || !Settings.ViewDurationArguments.Exists(duration => duration.argument == query.SearchTerms[1]))
/*
* Report duration selection --- tgl view [day | week | month | year]
*/
if (query.SearchTerms.Length == 1 || !Settings.ViewDurationArguments.Exists(duration => duration.Argument == query.SearchTerms[1]))
{
var results = Settings.ViewDurationArguments.ConvertAll(duration =>
{
return new Result
{
Title = duration.argument,
SubTitle = $"View {duration.spanString} tracked time report",
Title = duration.Argument,
SubTitle = $"View {duration.Interpolation} tracked time report",
IcoPath = "view.png",
AutoCompleteText = $"{query.ActionKeyword} {Settings.ViewCommand} {duration.argument} ",
AutoCompleteText = $"{query.ActionKeyword} {Settings.ViewCommand} {duration.Argument} ",
Score = Settings.ViewDurationArguments.Count - Settings.ViewDurationArguments.IndexOf(duration),
Action = c =>
{
this._context.API.ChangeQuery($"{query.ActionKeyword} {Settings.ViewCommand} {duration.argument} ", true);
this._context.API.ChangeQuery($"{query.ActionKeyword} {Settings.ViewCommand} {duration.Argument} ", true);
return false;
},
};
Expand Down

0 comments on commit 5d663a7

Please sign in to comment.