ability to delete ALL words in wordlist

This commit is contained in:
lingdocs 2022-07-19 15:25:58 -05:00
parent 71abfd286c
commit bfc884b07b
2 changed files with 14 additions and 4 deletions

View File

@ -163,6 +163,9 @@ export function searchWordlist(search: string, wordlist: WordlistWord[], textOpt
}
export function calculateWordsToDelete(wordlist: WordlistWord[], monthsBackToKeep: number): string[] {
if (monthsBackToKeep === 0) {
return [...wordlist].map((word) => word._id);
}
const now = Date.now();
const cutoffDate = now - getMillisecondsPeriod("months", monthsBackToKeep);
return wordlist.filter((word) => {

View File

@ -75,6 +75,9 @@ function paginate<T>(arr: T[], page: number): T[] {
}
function amountOfWords(number: number): string {
if (number === 0) {
return "ALL your words";
}
return `${number} word${number !== 1 ? "s" : ""}`;
}
@ -378,19 +381,23 @@ function Wordlist({ options, wordlist, isolateEntry, optionsDispatch }: {
</Modal.Header>
<Modal.Body>
<p>You have {amountOfWords(wordlist.length)} in your wordlist.</p>
<p>Delete words older than:</p>
<p>Delete:</p>
<ButtonSelect
options={[
{
label: "1 Month",
label: "ALL words",
value: "0",
},
{
label: "Older than 1 Month",
value: "1",
},
{
label: "6 Months",
label: "Older than 6 Months",
value: "6",
},
{
label: "1 Year",
label: "Orlder than 1 Year",
value: "12",
},
]}