From 20c7427877b81fd25c5d3a904281572ae86c651f Mon Sep 17 00:00:00 2001 From: Miguel Mota Date: Sun, 21 Jun 2020 23:37:16 -0700 Subject: [PATCH] Fix output container resizing --- src/components/channel/Channel.tsx | 97 +++++++++++++++++++++++------- src/components/global/Footer.tsx | 2 +- src/components/global/Header.tsx | 5 +- src/components/home/Home.tsx | 29 ++++----- src/config/config.ts | 16 +++++ src/config/index.ts | 1 + src/index.css | 37 +----------- 7 files changed, 110 insertions(+), 77 deletions(-) create mode 100644 src/config/config.ts create mode 100644 src/config/index.ts diff --git a/src/components/channel/Channel.tsx b/src/components/channel/Channel.tsx index 051aa42..b4dcc92 100644 --- a/src/components/channel/Channel.tsx +++ b/src/components/channel/Channel.tsx @@ -19,6 +19,7 @@ import Header from 'src/components/global/Header' import Clipboard from 'src/components/functional/Clipboard' import DragAndDrop from 'src/components/functional/DragAndDrop' import Tag from 'src/components/functional/Tag' +import { getShareUrl } from 'src/config' Terminal.applyAddon(fit) Terminal.applyAddon(fullscreen) @@ -98,6 +99,8 @@ function genRandString() { const UI = { SiteContainer: styled.main` + display: flex; + flex-direction: column; `, Header: styled.header` display: flex; @@ -107,6 +110,42 @@ const UI = { position: relative; padding-right: 35px; `, + OutputContainer: styled.div` + display: flex; + flex-direction: column; + flex: 2; + `, + Output: styled.output` + width: 100%; + max-height: 300px; + overflow-x: hidden; + overflow-y: auto; + padding: 1rem; + width: 100%; + position: relative; + display: flex; + flex: 2; + flex-direction: column; + box-shadow: 0 1px 10px rgba(151,164,175,0.1); + + @media (max-width: 500px) { + padding: 0; + } + + textarea { + font-size: 12px; + } + + .item footer .copy { + margin-left: 0.5rem; + } + + video { + width: 100%; + height: auto; + max-width: 500px; + } + `, Form: styled.form` display: flex; justify-content: space-between; @@ -220,9 +259,19 @@ const UI = { } `, NoMessages: styled.div` - font-style: italic; - color: #7b7b7b; - font-size: 1rem; + display: flex; + align-items: flex-end; + flex: 1; + span { + display: inline-block; + font-style: italic; + color: #7b7b7b; + font-size: 1rem; + } + + @media (max-width: 500px) { + padding: 2em; + } `, /* background: #293238; */ TerminalContainer: styled.div` @@ -328,7 +377,7 @@ class Channel extends Component { text: '', file: null, messages: [], - shareUrl: this.getShareUrl(channel), + shareUrl: getShareUrl(channel), fullScreen: false, queuedFiles: [], fullScreenUrl: '', @@ -359,18 +408,6 @@ class Channel extends Component { this.terminalResizerRef = React.createRef() } - getShareUrl (channel: string) { - let protocol = window.location.protocol - let host = window.location.host - let pathname = `s/${channel}` - if (host === 'streamhut.io') { - host = 'stream.ht' - pathname = channel - } - - return `${protocol}//${host}/${pathname}` - } - setFullScreen () { document.body.classList.add('fullscreen') } @@ -689,6 +726,8 @@ class Channel extends Component { container.style.height = newHeight + 'px' terminal.style.height = (newHeight - this.borderSize) + 'px' this.term.fit() + + this.resizeOutputContainer() }, 20) setupTerminalResizer () { @@ -703,11 +742,25 @@ class Channel extends Component { document.addEventListener('mouseup', event => { document.removeEventListener('mousemove', this.resizeTerminal, false) }, false) + + // TODO: fix resizing on mobile // document.addEventListener('touchstart', event => { // document.removeEventListener('touchmove', this.resizeTerminal, false) // }, false) } + resizeOutputContainer () { + const outputContainer = document.getElementById('output-container') as HTMLElement + const output = document.getElementById('output') as HTMLElement + const form = document.getElementById('form') as HTMLElement + + const terminalContainer = this.terminalContainerRef.current + const maxHeightAllowed = window.outerHeight - terminalContainer.offsetHeight - terminalContainer.offsetTop - form.offsetHeight - 25 + const maxHeight = outputContainer.offsetHeight - form.offsetHeight + + output.style.maxHeight = `${Math.min(maxHeight, maxHeightAllowed)}px` + } + sendArrayBuffer (arrayBuffer, mime) { const abWithMime = arrayBufferWithMime(arrayBuffer, mime) try { @@ -947,7 +1000,9 @@ class Channel extends Component { } render () { - let messages: any = no messages + let messages: any = + no messages + if (this.state.messages.length) { messages = this.state.messages.map(x => this.renderMessage(x)) } @@ -1041,12 +1096,12 @@ class Channel extends Component { >☰ -
- + {messages} - + this.handleSubmit(event)}> @@ -1095,7 +1150,7 @@ class Channel extends Component { Send
- + this.handleDrop(files)} /> diff --git a/src/components/global/Footer.tsx b/src/components/global/Footer.tsx index 605ab3f..ec3b3ad 100644 --- a/src/components/global/Footer.tsx +++ b/src/components/global/Footer.tsx @@ -8,7 +8,7 @@ import MaxWidthContainer from 'src/components/functional/MaxWidthContainer' const UI = { Footer: styled.footer` align-items: start; - padding: 2rem; + padding: 4em 2rem; width: 100%; font-size: 1rem; text-align: right; diff --git a/src/components/global/Header.tsx b/src/components/global/Header.tsx index 37fd83e..0369090 100644 --- a/src/components/global/Header.tsx +++ b/src/components/global/Header.tsx @@ -6,6 +6,7 @@ import ClipboardJS from 'clipboard' import Clipboard from 'src/components/functional/Clipboard' import HelpTooltip from 'src/components/functional/HelpTooltip' import MaxWidthContainer from 'src/components/functional/MaxWidthContainer' +import { streamHostname, streamPort } from 'src/config' const UI = { Header: styled.header` @@ -189,8 +190,8 @@ class Header extends Component { super(props) this.state = { - hostname: window.location.hostname, - port: 1337, + hostname: streamHostname, + port: streamPort, showExampleWithChannel: false, channel: window.location.pathname.substr(3) } diff --git a/src/components/home/Home.tsx b/src/components/home/Home.tsx index 0570ee0..e4c410b 100644 --- a/src/components/home/Home.tsx +++ b/src/components/home/Home.tsx @@ -3,6 +3,7 @@ import styled from 'styled-components' import GithubIcon from 'mdi-material-ui/GithubCircle' import MaxWidthContainer from 'src/components/functional/MaxWidthContainer' import SubscribeForm from './SubscribeForm' +import { streamHostname, streamPort } from 'src/config' const UI = { Main: styled.div` @@ -15,9 +16,6 @@ const UI = { justify-content: center; flex-direction: column; padding: 6rem 3rem; - @media (max-width: 500px) { - padding: 3rem 1rem; - } `, HeroImage: styled.div` display: block; @@ -33,7 +31,7 @@ const UI = { max-width: 500px; height: auto; @media (max-width: 500px) { - max-width: 200px; + max-width: 320px; } } `, @@ -69,7 +67,6 @@ const UI = { max-width: 345px; } @media (max-width: 500px) { - padding: 3rem 1rem; small { max-width: 100%; } @@ -214,9 +211,6 @@ const UI = { text-align: center; color: #fff; font-size: 1.5rem; - @media (max-width: 500px) { - padding: 3rem 1rem; - } h3 { font-size: 1.8rem; font-weight: 700; @@ -262,9 +256,6 @@ const UI = { padding: 5rem 2rem; text-align: center; font-size: 1.2rem; - @media (max-width: 500px) { - font-size: 1rem; - } h3 { font-size: 1.8rem; font-weight: 700; @@ -291,9 +282,6 @@ const UI = { font-size: 1.2rem; background: #fff url('https://s3.amazonaws.com/assets.streamhut.io/background-pattern-round.png') repeat 0 0; border-top: 1px solid #f4f4f5; - @media (max-width: 500px) { - font-size: 1rem; - } h3 { font-size: 1.8rem; font-weight: 700; @@ -345,8 +333,8 @@ class Home extends Component { constructor (props) { super(props) this.state = { - hostname: window.location.hostname, - port: 1337 + hostname: streamHostname, + port: streamPort } } @@ -399,9 +387,14 @@ class Home extends Component {
- screencast + alt="screencast" />
diff --git a/src/config/config.ts b/src/config/config.ts new file mode 100644 index 0000000..9ca0be6 --- /dev/null +++ b/src/config/config.ts @@ -0,0 +1,16 @@ +const windowHostname = window.location.hostname +export const streamHostname = /^streamhut.(io|net|org|co|me|sh)$/gi.test(windowHostname) ? 'stream.ht' +: windowHostname +export const streamPort = 1337 + +export const getShareUrl = (channel: string) => { + let protocol = window.location.protocol + let host = window.location.host + let pathname = `s/${channel}` + if (host === 'streamhut.io') { + host = 'stream.ht' + pathname = channel + } + + return `${protocol}//${host}/${pathname}` +} diff --git a/src/config/index.ts b/src/config/index.ts new file mode 100644 index 0000000..f934b01 --- /dev/null +++ b/src/config/index.ts @@ -0,0 +1 @@ +export * from './config' diff --git a/src/index.css b/src/index.css index 4a82d75..98b4677 100644 --- a/src/index.css +++ b/src/index.css @@ -203,29 +203,6 @@ input[type="text"]:focus { } } -#output { - width: 100%; - max-height: 300px; - overflow-x: hidden; - overflow-y: auto; - padding: 1rem; - width: 100%; - position: relative; - display: flex; - flex-direction: column; - box-shadow: 0 1px 10px rgba(151,164,175,.1); -} - -@media (max-width: 500px) { - #output { - padding: 0; - } -} - -#output textarea { - font-size: 12px; -} - .copy { text-decoration: none; -webkit-appearance: none; @@ -248,21 +225,11 @@ input[type="text"]:focus { text-decoration: none; } -#output .item footer .copy { - margin-left: 0.5rem; -} - -#output video { - width: 100%; - height: auto; - max-width: 500px; -} - /* sticky footer */ #site-container { min-height: 100%; - margin-bottom: -10rem; + margin-bottom: -15rem; } #site-container:after { @@ -271,7 +238,7 @@ input[type="text"]:focus { } #footer, #site-container:after { - height: 10rem; + height: 15rem; } /* end sticky footer */