Prevent initial redirect unless the user navigates

This commit is contained in:
Quantum 2022-03-13 01:39:16 -05:00
parent 2d4125654e
commit 50f8443605
3 changed files with 18 additions and 5 deletions

View file

@ -1,6 +1,16 @@
import React, {FormEvent} from 'react';
import {Calendar} from './Calendar';
import {endGregorian, endJD, frSupportedYear, gregorianJDN, jdnFrench, Month, startGregorian, startJD} from './dates';
import {
dateJDN,
endGregorian,
endJD,
frSupportedYear,
gregorianJDN,
jdnFrench,
Month,
startGregorian,
startJD
} from './dates';
import {TimeOfDay} from './TimeOfDay';
type YearMonth = {
@ -33,7 +43,7 @@ class App extends React.Component<{}, AppState> {
constructor(props: {}) {
super(props);
const today = new Date();
const todayJDN = gregorianJDN(today.getFullYear(), today.getMonth() + 1, today.getDate());
const todayJDN = dateJDN(today);
const {year, month} = jdnFrench(todayJDN);
this.state = {
@ -43,7 +53,6 @@ class App extends React.Component<{}, AppState> {
goMonth: (today.getMonth() + 1).toString(),
goDay: today.getDate().toString(),
};
this.updateURL();
this.updateStateFromURL = this.updateStateFromURL.bind(this);
}

View file

@ -1,6 +1,6 @@
import React from 'react';
import './TimeOfDay.scss';
import {gregorianJDN} from './dates';
import {dateJDN, gregorianJDN} from './dates';
type TimeStamp = {
hour: number,
@ -52,7 +52,7 @@ export class TimeOfDay extends React.Component<TimeOfDayProps, TimeOfDayState> {
decimalTimer: 0,
normal: zero,
normalTimer: 0,
jdn: 0,
jdn: dateJDN(new Date()),
};
}

View file

@ -88,6 +88,10 @@ export function gregorianJDN(year: number, month: number, day: number): number {
return J + dg;
}
export function dateJDN(date: Date) {
return gregorianJDN(date.getFullYear(), date.getMonth() + 1, date.getDate());
}
export function frJDN(year: number, month: Month, day: Day): number {
const dy = year - startYear;
const dd = month * 30 + day - 31;