fix and create constant setting for new words period

This commit is contained in:
adueck 2024-03-16 14:10:17 -04:00
parent 0a710fcc06
commit ecb269cb85
2 changed files with 24 additions and 16 deletions

View File

@ -11,6 +11,7 @@
import { Component } from "react";
import {
capitalizeFirstLetter,
defaultTextOptions,
revertSpelling,
standardizePashto,
@ -73,6 +74,8 @@ import { searchAllInflections } from "./lib/search-all-inflections";
import { addToWordlist } from "./lib/wordlist-database";
import ScriptToPhonetics from "./screens/ScriptToPhonetics";
const newWordsPeriod: "week" | "month" = "month";
// to allow Moustrap key combos even when input fields are in focus
Mousetrap.prototype.stopCallback = function () {
return false;
@ -203,7 +206,7 @@ class App extends Component<RouteComponentProps, State> {
}
if (this.props.location.pathname === "/new-entries") {
this.setState({
results: dictionary.getNewWords("week"),
results: dictionary.getNewWords(newWordsPeriod),
page: 1,
});
}
@ -335,7 +338,7 @@ class App extends Component<RouteComponentProps, State> {
}
if (this.props.location.pathname === "/new-entries") {
this.setState({
results: dictionary.getNewWords("week"),
results: dictionary.getNewWords(newWordsPeriod),
page: 1,
});
}
@ -647,7 +650,7 @@ class App extends Component<RouteComponentProps, State> {
to="/new-entries"
className="plain-link font-weight-light"
>
<div className="my-4">New words this week</div>
<div className="my-4">New words this {newWordsPeriod}</div>
</Link>
<div className="my-4 pt-3">
<Link
@ -694,7 +697,9 @@ class App extends Component<RouteComponentProps, State> {
/>
</Route>
<Route path="/new-entries">
<h4 className="mb-3">New Words This Month</h4>
<h4 className="mb-3">
New Words This {capitalizeFirstLetter(newWordsPeriod)}
</h4>
{this.state.results.length ? (
<Results
state={this.state}
@ -702,7 +707,7 @@ class App extends Component<RouteComponentProps, State> {
handleInflectionSearch={this.handleInflectionSearch}
/>
) : (
<div>No new words added this month 😓</div>
<div>No new words added this {newWordsPeriod}</div>
)}
</Route>
<Route path="/account">

View File

@ -1,16 +1,19 @@
import * as AT from "../types/account-types";
export function objIsEqual(obj1: any, obj2: any): boolean {
if (!obj1 || !obj2) return false;
return JSON.stringify(obj1) === JSON.stringify(obj2);
if (!obj1 || !obj2) return false;
return JSON.stringify(obj1) === JSON.stringify(obj2);
}
export function userObjIsEqual(u1: AT.LingdocsUser | undefined, u2: AT.LingdocsUser | undefined): boolean {
if (!u1 || !u2) return false;
function removeFrills(u: AT.LingdocsUser) {
if (!("_rev" in u)) return u;
const { lastActive, _rev, ...rest } = u;
return rest;
}
return objIsEqual(removeFrills(u1), removeFrills(u2));
}
export function userObjIsEqual(
u1: AT.LingdocsUser | undefined,
u2: AT.LingdocsUser | undefined
): boolean {
if (!u1 || !u2) return false;
function removeFrills(u: AT.LingdocsUser) {
if (!("_rev" in u)) return u;
const { lastActive, _rev, ...rest } = u;
return rest;
}
return objIsEqual(removeFrills(u1), removeFrills(u2));
}