Skip to content

Commit

Permalink
Fix: issue-1089 - Change variable names and some cleanups
Browse files Browse the repository at this point in the history
  • Loading branch information
yuanLeeMidori committed Nov 17, 2020
1 parent 22b0124 commit 449a45f
Showing 1 changed file with 17 additions and 10 deletions.
27 changes: 17 additions & 10 deletions src/frontend/src/components/Post/Post.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useRef } from 'react';
import React, { useRef, useState } from 'react';
import PropTypes from 'prop-types';
import useSWR from 'swr';
import 'highlight.js/styles/github.css';
Expand Down Expand Up @@ -28,6 +28,14 @@ const useStyles = makeStyles((theme) => ({
position: 'static',
},
},
expandHeader: {
whiteSpace: 'normal',
cursor: 'pointer',
},
collapseHeader: {
whiteSpace: 'nowrap',
cursor: 'pointer',
},
title: {
fontSize: '3.5em',
fontWeight: 'bold',
Expand Down Expand Up @@ -92,9 +100,9 @@ const Post = ({ postUrl }) => {
const sectionEl = useRef(null);
// Grab the post data from our backend so we can render it
const { data: post, error } = useSWR(postUrl, (url) => fetch(url).then((r) => r.json()));
const [expandToggle, setToggle] = React.useState(true);
const expandTitleOrNot = () => {
setToggle(!expandToggle);
const [expandHeader, setExpandHeader] = useState(true);
const toggleExpandHeader = () => {
setExpandHeader(!expandHeader);
};

if (error) {
Expand Down Expand Up @@ -144,12 +152,11 @@ const Post = ({ postUrl }) => {
<ListSubheader className={classes.header}>
<AdminButtons />
<Typography variant="h1" title={post.title} id={post.id} className={classes.title}>
<span onClick={expandTitleOrNot} style={{ cursor: 'pointer' }}>
{expandToggle ? (
<span style={{ 'white-space': 'nowrap' }}>{post.title}</span>
) : (
<span style={{ 'white-space': 'normal' }}>{post.title}</span>
)}
<span
onClick={toggleExpandHeader}
className={expandHeader ? classes.collapseHeader : classes.expandHeader}
>
{post.title}
</span>
</Typography>
<Typography variant={'p'} className={classes.author}>
Expand Down

0 comments on commit 449a45f

Please sign in to comment.