show new words this week instead of this month
This commit is contained in:
parent
e09f3b7d14
commit
1a3d89f63f
|
@ -203,7 +203,7 @@ class App extends Component<RouteComponentProps, State> {
|
||||||
}
|
}
|
||||||
if (this.props.location.pathname === "/new-entries") {
|
if (this.props.location.pathname === "/new-entries") {
|
||||||
this.setState({
|
this.setState({
|
||||||
results: dictionary.getNewWordsThisMonth(),
|
results: dictionary.getNewWords("week"),
|
||||||
page: 1,
|
page: 1,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -335,7 +335,7 @@ class App extends Component<RouteComponentProps, State> {
|
||||||
}
|
}
|
||||||
if (this.props.location.pathname === "/new-entries") {
|
if (this.props.location.pathname === "/new-entries") {
|
||||||
this.setState({
|
this.setState({
|
||||||
results: dictionary.getNewWordsThisMonth(),
|
results: dictionary.getNewWords("week"),
|
||||||
page: 1,
|
page: 1,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -647,7 +647,7 @@ class App extends Component<RouteComponentProps, State> {
|
||||||
to="/new-entries"
|
to="/new-entries"
|
||||||
className="plain-link font-weight-light"
|
className="plain-link font-weight-light"
|
||||||
>
|
>
|
||||||
<div className="my-4">New words this month</div>
|
<div className="my-4">New words this week</div>
|
||||||
</Link>
|
</Link>
|
||||||
<div className="my-4 pt-3">
|
<div className="my-4 pt-3">
|
||||||
<Link
|
<Link
|
||||||
|
|
|
@ -83,7 +83,8 @@ function getExpForInflections(input: string, index: "p" | "f"): RegExp {
|
||||||
return new RegExp(`^${base}[و|ې|ه]?`);
|
return new RegExp(`^${base}[و|ې|ه]?`);
|
||||||
}
|
}
|
||||||
|
|
||||||
function tsOneMonthBack(): number {
|
function tsBack(period: "month" | "week"): number {
|
||||||
|
if (period === "month") {
|
||||||
// https://stackoverflow.com/a/24049314/8620945
|
// https://stackoverflow.com/a/24049314/8620945
|
||||||
const d = new Date();
|
const d = new Date();
|
||||||
const m = d.getMonth();
|
const m = d.getMonth();
|
||||||
|
@ -98,6 +99,12 @@ function tsOneMonthBack(): number {
|
||||||
// Get the time value in milliseconds and convert to seconds
|
// Get the time value in milliseconds and convert to seconds
|
||||||
return d.getTime();
|
return d.getTime();
|
||||||
}
|
}
|
||||||
|
const currentDate = new Date();
|
||||||
|
const lastWeekDate = new Date(
|
||||||
|
currentDate.getTime() - 7 * 24 * 60 * 60 * 1000
|
||||||
|
);
|
||||||
|
return lastWeekDate.getTime();
|
||||||
|
}
|
||||||
|
|
||||||
function alphabeticalLookup({
|
function alphabeticalLookup({
|
||||||
searchString,
|
searchString,
|
||||||
|
@ -575,10 +582,12 @@ export const dictionary: DictionaryAPI = {
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
exactPashtoSearch: pashtoExactLookup,
|
exactPashtoSearch: pashtoExactLookup,
|
||||||
getNewWordsThisMonth: function (): T.DictionaryEntry[] {
|
getNewWords: function (period: "week" | "month"): T.DictionaryEntry[] {
|
||||||
return dictDb.collection
|
return dictDb.collection
|
||||||
.chain()
|
.chain()
|
||||||
.find({ ts: { $gt: tsOneMonthBack() } })
|
.find({
|
||||||
|
ts: { $gt: tsBack(period) },
|
||||||
|
})
|
||||||
.simplesort("ts")
|
.simplesort("ts")
|
||||||
.data()
|
.data()
|
||||||
.reverse();
|
.reverse();
|
||||||
|
|
|
@ -40,7 +40,9 @@ export type DictionaryAPI = {
|
||||||
exactPashtoSearch: (
|
exactPashtoSearch: (
|
||||||
search: string
|
search: string
|
||||||
) => import("@lingdocs/ps-react").Types.DictionaryEntry[];
|
) => import("@lingdocs/ps-react").Types.DictionaryEntry[];
|
||||||
getNewWordsThisMonth: () => import("@lingdocs/ps-react").Types.DictionaryEntry[];
|
getNewWords: (
|
||||||
|
period: "month" | "week"
|
||||||
|
) => import("@lingdocs/ps-react").Types.DictionaryEntry[];
|
||||||
findOneByTs: (
|
findOneByTs: (
|
||||||
ts: number
|
ts: number
|
||||||
) => import("@lingdocs/ps-react").Types.DictionaryEntry | undefined;
|
) => import("@lingdocs/ps-react").Types.DictionaryEntry | undefined;
|
||||||
|
|
Loading…
Reference in New Issue