Fix/entry-title-responsive-comments (#922)

* Make `EntryTitle` component responsive

* useRequetTextByWidth added

* renamed

Co-authored-by: M. Mert Yildiran <mehmet@up9.com>
Co-authored-by: Leon <>
This commit is contained in:
leon-up9
2022-03-24 12:09:28 +02:00
committed by GitHub
parent a2595afd5e
commit 11a2246cb9
2 changed files with 54 additions and 7 deletions

View File

@@ -0,0 +1,43 @@
import { useState, useEffect } from 'react';
function getWindowDimensions() {
const { innerWidth: width, innerHeight: height } = window;
return {
width,
height
};
}
export function useRequestTextByWidth(windowWidth){
let requestText = "Request: "
let responseText = "Response: "
let elapsedTimeText = "Elapsed Time: "
if (windowWidth < 1078) {
requestText = ""
responseText = ""
elapsedTimeText = ""
} else if (windowWidth < 1356) {
requestText = "Req: "
responseText = "Res: "
elapsedTimeText = "ET: "
}
return {requestText, responseText, elapsedTimeText}
}
export default function useWindowDimensions() {
const [windowDimensions, setWindowDimensions] = useState(getWindowDimensions());
useEffect(() => {
function handleResize() {
setWindowDimensions(getWindowDimensions());
}
window.addEventListener('resize', handleResize);
return () => window.removeEventListener('resize', handleResize);
}, []);
return windowDimensions;
}