Skip to content

Commit

Permalink
[#52711] Remove duplicated adjustToMode
Browse files Browse the repository at this point in the history
  • Loading branch information
MaciejWas committed Dec 21, 2023
1 parent 122c5e0 commit 9add354
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 17 deletions.
17 changes: 4 additions & 13 deletions src/components/CodeMirror.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,13 @@ import { basicSetup, EditorView } from "codemirror";
import { keymap } from "@codemirror/view";
import { indentWithTab } from "@codemirror/commands";
import { EditorState } from "@codemirror/state";
import styled, { css } from 'styled-components/macro';
import styled from 'styled-components/macro';
import { yCollab } from "y-codemirror.next";
import useCollaboration from '../hooks/useCollaboration'
import spellcheck from '../hooks/spellchecker';
import { adjustToMode } from './Preview';

const adjustToMode = (mode) => {
if (mode === "Both") {
return css`
display: block;
max-width: 50%;`
} else if (mode === "Source") {
return css`display: block;`
} else {
return css`display: none;`
}
}
const adjust = adjustToMode("Source")

const CodeEditor = styled.div`
border-radius: var(--border-radius);
Expand All @@ -31,7 +22,7 @@ const CodeEditor = styled.div`
padding: 20px;
min-height: 500px;
${props => adjustToMode(props.$mode)}
${props => adjust(props.$mode)}
flex: 1;
border: 1px solid var(--gray-400);
Expand Down
12 changes: 8 additions & 4 deletions src/components/Preview.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
import styled, { css } from 'styled-components/macro';

const adjustToMode = (mode) => {
export const adjustToMode = (mainMode) => (mode) => {
if (mode === "Both") {
return css`max-width: 50%;`
} else if (mode === "Preview") {
return css`
display: block;
max-width: 50%;`
} else if (mode === mainMode) {
return css``
} else {
return css`display: none;`
}
}

const adjust = adjustToMode("Preview");

const Preview = styled.div`
background-color: white;
padding: 20px;
Expand All @@ -23,7 +27,7 @@ const Preview = styled.div`
vertical-align: top;
color: var(--gray-900);
word-break: unset;
${props => adjustToMode(props.$mode)}
${props => adjust(props.$mode)}
@media print {
& {
Expand Down

0 comments on commit 9add354

Please sign in to comment.