Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
b7e0173
First draft adding typewriter sounds
robin-macpherson Nov 30, 2021
eaabe74
Build SwitchToggle Component
robin-macpherson Nov 30, 2021
a62f92d
Update SwitchToggle sizing & colors
robin-macpherson Nov 30, 2021
cb0221f
Implement typewriter sound mechanism to editor
robin-macpherson Nov 30, 2021
8742b10
Begin refactoring Toolbar to fix responsive issues
robin-macpherson Nov 30, 2021
8f428da
Translation files
robin-macpherson Nov 30, 2021
ace4274
Delete typewriter-sound.wav
robin-macpherson Nov 30, 2021
9aad8e8
Apply German Translation
robin-macpherson Nov 30, 2021
8cf3ebd
Merge branch 'master' into type-writer-sounds
robin-macpherson Dec 12, 2021
d5279b4
Revert "Delete typewriter-sound.wav"
robin-macpherson Dec 12, 2021
8c73a75
Create usePlayPolyphonicSound.ts
robin-macpherson Dec 12, 2021
26f7a5d
Refactor and make all the things beautiful
robin-macpherson Dec 12, 2021
fed99ac
Merge branch 'master' into type-writer-sounds
robin-macpherson Jan 3, 2022
8ec02cc
Hide typewriter sounds when toolbar floats & consolidate extra style …
robin-macpherson Jan 4, 2022
dbc978b
Fix spacing
robin-macpherson Jan 7, 2022
6338609
Add translation
robin-macpherson Jan 7, 2022
764b54d
Progress
robin-macpherson Jan 10, 2022
2258b1e
Debugging progress with position sticky
robin-macpherson Jan 10, 2022
7021b92
Merge remote-tracking branch 'origin' into type-writer-sounds
robin-macpherson Jan 15, 2022
c714e26
getWindowSize hook
robin-macpherson Jan 15, 2022
f717b8e
Remove hopefully obsolete rules to enable position sticky toolbar
robin-macpherson Jan 15, 2022
633131e
Create useIntersectionObserver hook
robin-macpherson Jan 15, 2022
94b6661
A very long and mostly failed day of playing with Intersection Observers
robin-macpherson Jan 15, 2022
2d0e208
Make things finally work
robin-macpherson Jan 15, 2022
92d3646
Address PR feedback
robin-macpherson Jan 21, 2022
581d489
Fix the build bay bayyyyy
robin-macpherson Jan 23, 2022
561422a
Merge branch 'master' into type-writer-sounds
robin-macpherson Jan 23, 2022
4a4662a
Add in German translations for TOS
robin-macpherson Jan 23, 2022
15dd203
A quick session to find a new approach
robin-macpherson May 2, 2022
a29b6f7
BIG PROGRESS WITH MOBILE KEYBOARD STICKY FINALLY!
robin-macpherson May 6, 2022
e72f316
Get floating toolbar working more nicely!
robin-macpherson May 12, 2022
b48960d
Refactor useAutosavedState to have optional opts
robin-macpherson May 12, 2022
546cc36
Wire up autosave for typewriter sounds
robin-macpherson May 12, 2022
46817a5
Merge branch 'master' into type-writer-sounds
robin-macpherson May 12, 2022
0de564f
Fix build errors
robin-macpherson May 12, 2022
471f71e
Update packages/web/components/JournalyEditor/Toolbar/Toolbar.tsx
robin-macpherson May 17, 2022
63ff8df
Clean up rootMargin calculation no longer needed for intersection obs…
robin-macpherson May 17, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions packages/web/components/Dashboard/Header/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,6 @@ const Header: React.FC<Props> = ({ onMenuClick }) => {
{showNotificationFeed && <NotificationFeed onClose={() => setShowNotificationFeed(false)} />}
<style jsx>{`
.header {
position: fixed;
top: 0;
left: 0;
right: 0;
display: flex;
justify-content: space-between;
align-items: center;
Expand Down
66 changes: 52 additions & 14 deletions packages/web/components/JournalyEditor/JournalyEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,9 @@ import PostBodyStyles from '@/components/PostBodyStyles'
import Toolbar from './Toolbar'
import RenderElement from './RenderElement'
import RenderLeaf from './RenderLeaf'
import {
withLinks,
withImages,
toggleMark,
options,
MarkType,
} from './helpers'
import { withLinks, withImages, toggleMark, options, MarkType } from './helpers'
import usePlayPolyphonicSound from '@/hooks/usePlayPolyphonicSound'
import useAutosavedState from '@/hooks/useAutosavedState'

/**
* The Journaly Rich Text Editor
Expand All @@ -33,6 +29,22 @@ const HOTKEYS: { [key in HotKey]: MarkType } = {
'mod+u': 'underline',
}

const KEY_BLACK_LIST = new Set([
'Shift',
'Tab',
'Meta',
'Control',
'Alt',
'ArrowUp',
'ArrowLeft',
'ArrowDown',
'ArrowRight',
'PageUp',
'PageDown',
'Home',
'End',
])

type JournalyEditorProps = {
value: Descendant[]
setValue: (value: Descendant[]) => void
Expand All @@ -52,10 +64,7 @@ const JournalyEditor = ({
const renderElement = useCallback((props) => <RenderElement {...props} />, [])
const renderLeaf = useCallback((props) => <RenderLeaf {...props} />, [])
const editor = useMemo(() => {
const withPlugins: ((ed: Editor) => Editor)[] = [
withHistory,
withLinks,
]
const withPlugins: ((ed: Editor) => Editor)[] = [withHistory, withLinks]

if (allowInlineImages) {
withPlugins.push(withImages)
Expand All @@ -64,6 +73,27 @@ const JournalyEditor = ({
return pipe(withReact(createEditor()), ...withPlugins)
}, [])

const [shouldPlayTypewriterSounds, setShouldPlayTypewriterSounds] = useAutosavedState(false, {
key: 'shouldPlayTypewriterSounds',
})

const playTypewriterSound = usePlayPolyphonicSound('/static/sounds/typewriter-key-sound.wav', 3)
const playTypewriterReturnSound = usePlayPolyphonicSound(
'/static/sounds/typewriter-return-sound.wav',
1,
)

const handlePlayTypewriterSound = (e: React.KeyboardEvent) => {
if (shouldPlayTypewriterSounds) {
if (KEY_BLACK_LIST.has(e.key)) return
else if (e.key === 'Enter') {
playTypewriterReturnSound()
} else {
playTypewriterSound()
}
}
}

useEffect(() => {
;(slateRef as React.MutableRefObject<Editor>).current = editor
}, [editor])
Expand All @@ -76,7 +106,13 @@ const JournalyEditor = ({
<div className="editor-wrapper">
<div className="editor-container">
<Slate editor={editor} value={value} onChange={(value) => setValue(value)}>
<Toolbar allowInlineImages={allowInlineImages} />
<Toolbar
allowInlineImages={allowInlineImages}
shouldPlayTypewriterSounds={shouldPlayTypewriterSounds}
onToggleShouldPlayTypewriterSounds={() =>
setShouldPlayTypewriterSounds(!shouldPlayTypewriterSounds)
}
/>
<EditablePlugins
plugins={plugins}
renderElement={[renderElement]}
Expand All @@ -85,15 +121,17 @@ const JournalyEditor = ({
spellCheck
onKeyDown={[
(event: React.KeyboardEvent) => {
handlePlayTypewriterSound(event)
Object.entries(HOTKEYS).forEach(([hotkey, mark]) => {
// Convert React keyboard event to native keyboard event
if (isHotkey(hotkey, (event as unknown) as KeyboardEvent)) {
if (isHotkey(hotkey, event as unknown as KeyboardEvent)) {
event.preventDefault()
toggleMark(editor, mark)
}
})
},
]}
onKeyDownDeps={[shouldPlayTypewriterSounds]}
data-testid="post-body"
/>
</Slate>
Expand All @@ -112,7 +150,7 @@ const JournalyEditor = ({
min-height: 200px;
}

.editor-container > :global([contenteditable="true"]) {
.editor-container > :global([contenteditable='true']) {
flex: 1;
padding-top: 15px;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ const BaseToolbarButton = ({ onClick, active, children }: ButtonProps) => {
height: 100%;
padding: 1px;
border: none;
margin-right: 10px;
border-radius: 5px;
background-color: ${theme.colors.gray800};
cursor: pointer;
Expand Down
Loading