-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Store content of open project sections, display project sections in sidebar with contenteditable div * Save section content in project file instead of separate md files to simplify application logic * Add scrolling to sidebar sections, add war and peace test project * Add content header instead of add section button * Cleaning up sidebar content scroll and styling, add auto-focus and edit content on add new section
- Loading branch information
1 parent
7a93667
commit 4b78be0
Showing
27 changed files
with
546 additions
and
165 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,32 @@ | ||
module.exports = { | ||
extends: 'erb', | ||
rules: { | ||
// A temporary hack related to IDE not resolving correct package.json | ||
'import/no-extraneous-dependencies': 'off', | ||
'import/no-unresolved': 'error', | ||
// Since React 17 and typescript 4.1 you can safely disable the rule | ||
'react/react-in-jsx-scope': 'off', | ||
'react/jsx-props-no-spreading': 'off', | ||
}, | ||
parserOptions: { | ||
ecmaVersion: 2020, | ||
sourceType: 'module', | ||
project: './tsconfig.json', | ||
tsconfigRootDir: __dirname, | ||
createDefaultProgram: true, | ||
}, | ||
settings: { | ||
'import/resolver': { | ||
// See https://github.com/benmosher/eslint-plugin-import/issues/1396#issuecomment-575727774 for line below | ||
node: {}, | ||
webpack: { | ||
config: require.resolve('./.erb/configs/webpack.config.eslint.ts'), | ||
}, | ||
typescript: {}, | ||
extends: 'erb', | ||
rules: { | ||
// A temporary hack related to IDE not resolving correct package.json | ||
'import/no-extraneous-dependencies': 'off', | ||
'import/no-unresolved': 'error', | ||
// Since React 17 and typescript 4.1 you can safely disable the rule | ||
'react/react-in-jsx-scope': 'off', | ||
'react/jsx-props-no-spreading': 'off', | ||
"prettier/prettier": ["error", { endOfLine: "off" }], | ||
}, | ||
'import/parsers': { | ||
'@typescript-eslint/parser': ['.ts', '.tsx'], | ||
parserOptions: { | ||
ecmaVersion: 2020, | ||
sourceType: 'module', | ||
project: './tsconfig.json', | ||
tsconfigRootDir: __dirname, | ||
createDefaultProgram: true, | ||
}, | ||
}, | ||
}; | ||
settings: { | ||
'import/resolver': { | ||
// See https://github.com/benmosher/eslint-plugin-import/issues/1396#issuecomment-575727774 for line below | ||
node: {}, | ||
webpack: { | ||
config: require.resolve('./.erb/configs/webpack.config.eslint.ts'), | ||
}, | ||
typescript: {}, | ||
}, | ||
'import/parsers': { | ||
'@typescript-eslint/parser': ['.ts', '.tsx'], | ||
}, | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,18 @@ | ||
import fs from 'fs'; | ||
import type { ProjectData } from '../../types/types'; | ||
import path from 'path'; | ||
import type { ProjectData } from 'types/types'; | ||
|
||
const saveProject = (projectData: ProjectData) => { | ||
const { projectContent, filePath } = projectData; | ||
fs.writeFile(filePath, JSON.stringify(projectContent), (err) => { | ||
if (err) { | ||
console.log(err); | ||
const { projectContent, folderPath, fileName } = projectData; | ||
fs.writeFile( | ||
path.join(folderPath, fileName), | ||
JSON.stringify(projectContent), | ||
(err) => { | ||
if (err) { | ||
console.log(err); | ||
} | ||
} | ||
}); | ||
); | ||
}; | ||
|
||
export default saveProject; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
import { useState, useRef, useEffect } from 'react'; | ||
import styled, { css } from 'styled-components'; | ||
import Color from 'color'; | ||
import { updateSectionName } from '../utils/projectUtils'; | ||
|
||
const StyledItem = styled.div` | ||
cursor: ${(p) => (p.contentEditable ? 'text' : 'pointer')}; | ||
color: ${(p) => p.theme.sidebarFgText}; | ||
font-size: 0.9em; | ||
width: 95%; | ||
box-sizing: border-box; | ||
padding: 3px 6px; | ||
border-radius: 5px; | ||
&:hover { | ||
background-color: ${(p) => | ||
p.contentEditable | ||
? Color(p.theme.sidebarBg).darken(0.2) | ||
: Color(p.theme.sidebarBg).lighten(0.3)}; | ||
} | ||
${(p) => | ||
p.contentEditable && | ||
css` | ||
background-color: ${(p) => Color(p.theme.sidebarBg).darken(0.2)}; | ||
:focus { | ||
outline: none; | ||
} | ||
`} | ||
transition: background-color 100ms ease-in-out; | ||
`; | ||
|
||
type SidebarProjectSectionItemProps = { | ||
value: string; | ||
addingNew: boolean; | ||
}; | ||
|
||
const SidebarProjectSectionItem = ({ | ||
value, | ||
addingNew, | ||
}: SidebarProjectSectionItemProps) => { | ||
const [isEditable, setIsEditable] = useState(false); | ||
const itemRef = useRef<HTMLDivElement>(null); | ||
useEffect(() => { | ||
if (addingNew) { | ||
setIsEditable(true); | ||
itemRef.current?.scrollTo({ behavior: 'smooth' }); | ||
setTimeout(() => { | ||
itemRef.current?.focus(); | ||
}); | ||
} | ||
}, []); | ||
const handleDoubleClick = () => { | ||
setIsEditable(true); | ||
setTimeout(() => { | ||
itemRef.current?.focus(); | ||
}, 10); | ||
}; | ||
const handleBlur = () => { | ||
setIsEditable(false); | ||
|
||
const newValue = itemRef.current?.innerText; | ||
if (newValue) updateSectionName(value, newValue); | ||
}; | ||
const handleKeyDown = (event: React.KeyboardEvent<HTMLDivElement>) => { | ||
if (event.code === 'Enter') { | ||
event.preventDefault(); | ||
handleBlur(); | ||
} else if (event.code === 'Escape') { | ||
event.preventDefault(); | ||
if (itemRef.current) itemRef.current.innerText = value; | ||
setIsEditable(false); | ||
} | ||
}; | ||
return ( | ||
<StyledItem | ||
ref={itemRef} | ||
contentEditable={isEditable} | ||
suppressContentEditableWarning | ||
onDoubleClick={handleDoubleClick} | ||
onBlur={handleBlur} | ||
onKeyDown={handleKeyDown} | ||
> | ||
{value} | ||
</StyledItem> | ||
); | ||
}; | ||
|
||
export default SidebarProjectSectionItem; |
Oops, something went wrong.