Skip to content

Commit

Permalink
feat(ux): 🚸 implement -l list flag for continue (#98)
Browse files Browse the repository at this point in the history
  • Loading branch information
JamesNZL committed Jul 6, 2023
1 parent 10dab82 commit 1f57cd9
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
1 change: 1 addition & 0 deletions src/Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public class Settings
internal const string ClearDescriptionFlag = "-C";
internal const string TimeSpanFlag = "-t";
internal const string TimeSpanEndFlag = "-T";
internal const string ListPastFlag = "-l";
internal const string ShowStopFlag = "-S";

internal const string NoProjectName = "No Project";
Expand Down
19 changes: 10 additions & 9 deletions src/TogglTrack.cs
Original file line number Diff line number Diff line change
Expand Up @@ -569,9 +569,7 @@ internal List<Result> NotifyUnknownError()

internal async ValueTask<List<Result>> RequestResults(CancellationToken token, Query query)
{
bool emptyQuery = (string.IsNullOrEmpty(query.Search));

if (emptyQuery)
if (string.IsNullOrEmpty(query.Search))
{
this.RefreshCache(force: false);

Expand Down Expand Up @@ -606,11 +604,6 @@ internal async ValueTask<List<Result>> RequestResults(CancellationToken token, Q
// Add results to start time entry
results.AddRange(await this._GetStartResults(token, query));

if (emptyQuery)
{
return results;
}

// Add previously matching time entries
results.AddRange(await this._GetContinueResults(token, query));

Expand Down Expand Up @@ -1579,6 +1572,11 @@ private async ValueTask<List<Result>> _GetStopResults(CancellationToken token, Q

private async ValueTask<List<Result>> _GetContinueResults(CancellationToken token, Query query)
{
if (string.IsNullOrEmpty(query.Search))
{
return new List<Result>();
}

var me = (await this._GetMe(token))?.ToMe();
if (me is null)
{
Expand All @@ -1592,8 +1590,11 @@ private async ValueTask<List<Result>> _GetContinueResults(CancellationToken toke
}

string entriesQuery = new TransformedQuery(query)
.RemoveAll(Settings.ListPastFlag)
.ToString(TransformedQuery.Escaping.Unescaped);

bool emptyQuery = string.IsNullOrEmpty(entriesQuery);

return timeEntries.Groups.Values.SelectMany(project =>
{
if (project.SubGroups is null)
Expand All @@ -1602,7 +1603,7 @@ private async ValueTask<List<Result>> _GetContinueResults(CancellationToken toke
}
return project.SubGroups.Values
.Where(timeEntry => (
.Where(timeEntry => emptyQuery || (
(
project.Project?.Id != this._state.SelectedIds.Project ||
timeEntry.GetRawTitle() != entriesQuery
Expand Down

0 comments on commit 1f57cd9

Please sign in to comment.