Skip to content

Commit

Permalink
feat(view): 🚸 implement searching for result title and autocomplete
Browse files Browse the repository at this point in the history
  • Loading branch information
JamesNZL committed May 17, 2023
1 parent a766df3 commit 86d47c4
Showing 1 changed file with 22 additions and 5 deletions.
27 changes: 22 additions & 5 deletions src/TogglTrack.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1411,6 +1411,7 @@ internal async ValueTask<List<Result>> RequestViewReports(CancellationToken toke
Command = 0,
Span = 1,
Grouping = 2,
Name = 3,
};

if (query.SearchTerms.Length == ArgumentIndices.Span)
Expand Down Expand Up @@ -1596,10 +1597,14 @@ internal async ValueTask<List<Result>> RequestViewReports(CancellationToken toke
IcoPath = (project?.color is not null)
? new ColourIcon(this._context, project.color, "view.png").GetColourIcon()
: "view.png",
// TODO:
// AutoCompleteText =
AutoCompleteText = $"{query.ActionKeyword} {Settings.ViewCommand} {spanConfiguration.Argument} {groupingConfiguration.Argument} ",
Score = (int)group.seconds,
Action = c =>
{
// Action = c =>
this._context.API.ChangeQuery($"{query.ActionKeyword} {Settings.ViewCommand} {spanConfiguration.Argument} {groupingConfiguration.Argument} {project?.name?.Kebaberize() ?? "No Project"} ", true);
return false;
}
};
})
);
Expand Down Expand Up @@ -1681,9 +1686,14 @@ internal async ValueTask<List<Result>> RequestViewReports(CancellationToken toke
IcoPath = (highestProject?.color is not null)
? new ColourIcon(this._context, highestProject.color, "view.png").GetColourIcon()
: "view.png",
// AutoCompleteText =
AutoCompleteText = $"{query.ActionKeyword} {Settings.ViewCommand} {spanConfiguration.Argument} {groupingConfiguration.Argument} ",
Score = (int)group.seconds,
Action = c =>
{
// Action = c =>
this._context.API.ChangeQuery($"{query.ActionKeyword} {Settings.ViewCommand} {spanConfiguration.Argument} {groupingConfiguration.Argument} {client?.name?.Kebaberize() ?? "No Client"} ", true);
return false;
}
};
})
);
Expand Down Expand Up @@ -1773,8 +1783,9 @@ internal async ValueTask<List<Result>> RequestViewReports(CancellationToken toke
IcoPath = (project?.color is not null)
? new ColourIcon(this._context, project.color, "view.png").GetColourIcon()
: "view.png",
// AutoCompleteText =
AutoCompleteText = $"{query.ActionKeyword} {Settings.ViewCommand} {spanConfiguration.Argument} {groupingConfiguration.Argument} {((string.IsNullOrEmpty(subGroup.title)) ? "(no description)" : subGroup.title)}",
Score = (int)elapsed.TotalSeconds,
// TODO: RequestStartEntry
// Action = c =>
};
})
Expand All @@ -1784,7 +1795,13 @@ internal async ValueTask<List<Result>> RequestViewReports(CancellationToken toke
}
}

return results;
string nameQuery = Main.ExtractFromQuery(query, ArgumentIndices.Name);
return (string.IsNullOrWhiteSpace(nameQuery))
? results
: results.FindAll(result =>
{
return this._context.API.FuzzySearch(nameQuery, result.Title).Score > 0;
});
}
}
}

0 comments on commit 86d47c4

Please sign in to comment.