diff --git a/packages/app/src/App.jsx b/packages/app/src/App.jsx index fabcf4a7..9e8a5537 100644 --- a/packages/app/src/App.jsx +++ b/packages/app/src/App.jsx @@ -60,6 +60,9 @@ import { Session, User } from "models" import config from "config" import { NotFound, RenderError, Crash, Settings, Navigation, Login, UserRegister, Creator, Searcher } from "components" +import { DOMWindow } from "components/RenderWindow" +import loadable from "@loadable/component" + import { Icons } from "components/Icons" import Layout from "./layout" @@ -326,6 +329,15 @@ class App extends React.Component { } return await StatusBar.show() }, + openDebugger: () => { + // create a new dom window + const win = new DOMWindow({ + id: "debug", + title: "Debug", + }) + + win.createDefaultWindow(loadable(() => import("./debug"))) + } } constructor(props) { diff --git a/packages/app/src/debugComponents/index.js b/packages/app/src/debug/components/index.js similarity index 100% rename from packages/app/src/debugComponents/index.js rename to packages/app/src/debug/components/index.js diff --git a/packages/app/src/debugComponents/theme/index.jsx b/packages/app/src/debug/components/theme/index.jsx similarity index 100% rename from packages/app/src/debugComponents/theme/index.jsx rename to packages/app/src/debug/components/theme/index.jsx diff --git a/packages/app/src/debugComponents/theme/index.less b/packages/app/src/debug/components/theme/index.less similarity index 100% rename from packages/app/src/debugComponents/theme/index.less rename to packages/app/src/debug/components/theme/index.less diff --git a/packages/app/src/debug/components/timeCalculation/index.jsx b/packages/app/src/debug/components/timeCalculation/index.jsx new file mode 100644 index 00000000..7ee8ae97 --- /dev/null +++ b/packages/app/src/debug/components/timeCalculation/index.jsx @@ -0,0 +1,113 @@ +import React from "react" +import * as antd from "antd" + +import momentTimezone from "moment-timezone" +import { DateTime } from "luxon" + +const timezones = momentTimezone.tz.names() + +import "./index.less" + +export default (props) => { + const [simulatedTime, setSimulatedTime] = React.useState(null) + const [simlatedTimezone, setSimlatedTimezone] = React.useState(null) + + const localTimezone = momentTimezone.tz.guess() + + const setSimulatedTimezoneAsLocal = () => { + setSimlatedTimezone(localTimezone) + } + + const handleSimulatedTimeChange = (moment) => { + // set with UTC time string and input simlatedTimezone + const value = momentTimezone.tz(Date.now(), simlatedTimezone).format() + + setSimulatedTime(value) + } + + const getTimezoneOfString = (value) => { + const timezone = momentTimezone.tz(value).tz() + + return timezone + } + + const calculateTimeAgo = (inputTime) => { + if (!inputTime) { + return "No time" + } + + // calculate the absolute time ago between the input time and the current time using luxon, and return a string + const inputTimezone = momentTimezone.tz(value).tz() + + const inputTimeInLocalTimezone = momentTimezone.tz(inputTime, inputTimezone).tz(localTimezone).format() + + const timeAgo = DateTime.fromISO(inputTimeInLocalTimezone).toRelative() + + return timeAgo + } + + return
+ Select a simulated a timezone +
++ value: {simlatedTimezone} +
++ Set a simulated time +
+ ++ value: {simulatedTime} +
++ Time ago from now (in your timezone {localTimezone}) +
+ ++ { + calculateTimeAgo(simulatedTime) + } +
+