diff options
author | nea <romangraef@gmail.com> | 2021-08-19 23:41:53 +0200 |
---|---|---|
committer | nea <romangraef@gmail.com> | 2021-08-19 23:41:53 +0200 |
commit | bb6202dcc3e96a97853a36e65da361c5a32d6dd4 (patch) | |
tree | 345127b3da4c8c8d1eb977307087ac9b8fccdb0b /popup.jsx | |
parent | dc20f2ccb947b5bb2898a9989e8d38c937f97061 (diff) | |
download | powercord-timezone-master.tar.gz powercord-timezone-master.tar.bz2 powercord-timezone-master.zip |
Diffstat (limited to 'popup.jsx')
-rw-r--r-- | popup.jsx | 82 |
1 files changed, 82 insertions, 0 deletions
diff --git a/popup.jsx b/popup.jsx new file mode 100644 index 0000000..2844f75 --- /dev/null +++ b/popup.jsx @@ -0,0 +1,82 @@ +const { + React, + getModule +} = require('powercord/webpack'); +const { Modal } = require('powercord/components/modal'); +const { + FormTitle, + FormNotice +} = require('powercord/components'); +const { + close, + open +} = require('powercord/modal'); +const { SETTINGS_TIMEZONE } = require('./constants'); +const { + lookup, + timezones +} = require('./tz'); +const { SelectInput } = require('powercord/components/settings'); + +class TimezoneConverterPopup extends React.PureComponent { + constructor (props) { + super(props); + this.state = { timezone: props.toTimezone }; + } + + render () { + console.log(this.state, this.props); + return <Modal size={Modal.Sizes.LARGE} className={'vrmodal'}> + <Modal.Header> + <FormTitle tag={'h4'}> + Time converter + </FormTitle> + <Modal.CloseButton onClick={close}/> + </Modal.Header> + <Modal.Content> + <p><SelectInput + searchable={true} + onChange={(e) => { + this.setState({ timezone: lookup(e.value) }); + }} + value={this.state.timezone.code} + options={[ + ...timezones.map(it => ({ + value: it.code, + label: `${it.name} (${it.offset})` + })) + ]} + > + Convert to timezone + </SelectInput></p> + <p>{text(this.props.time, this.props.fromTimezone, this.state.timezone)}</p> + <br/><br/><br/><br/><br/><br/><br/><br/><br/><br/> + </Modal.Content> + </Modal>; + } +} + +function a (time) { + return ((time / 60) | 0) + ':' + (time % 60); +} + +function text (time, fromTimezone, toTimezone) { + let offset = toTimezone.offsetminutes - fromTimezone.offsetminutes; + let adjusted = (time + offset) % (24 * 60); + return `${a(time)} ${fromTimezone.code} -> ${a(adjusted)} ${toTimezone.code}`; +} + +function getLabel (time, fromTimezone, toTimezone) { + return <span + onClick={() => open(() => <TimezoneConverterPopup + time={time} + fromTimezone={fromTimezone} + toTimezone={toTimezone}/>)}> + {text(time, fromTimezone, toTimezone)} + </span>; +} + +module.exports = { + TimezoneConverterPopup, + getLabel +}; |