mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2025-05-23 11:37:02 -04:00
Reorganize redux types to avoid unnecessary type casting
Signed-off-by: Tilman Vatteroth <git@tilmanvatteroth.de>
This commit is contained in:
parent
a221ce4255
commit
6a43d0c5fb
27 changed files with 113 additions and 153 deletions
|
@ -6,8 +6,8 @@
|
|||
|
||||
import { Editor, Hint, Hints, Pos } from 'codemirror'
|
||||
import { DateTime } from 'luxon'
|
||||
import { getUser } from '../../../../redux/user/methods'
|
||||
import { findWordAtCursor, Hinter } from './index'
|
||||
import { store } from '../../../../redux'
|
||||
|
||||
const wordRegExp = /^(\[(.*])?)$/
|
||||
const allSupportedLinks = [
|
||||
|
@ -24,6 +24,11 @@ const allSupportedLinks = [
|
|||
'[color=#FFFFFF]'
|
||||
]
|
||||
|
||||
const getUserName = (): string => {
|
||||
const user = store.getState().user
|
||||
return user ? user.name : 'Anonymous'
|
||||
}
|
||||
|
||||
const linkAndExtraTagHint = (editor: Editor): Promise<Hints | null> => {
|
||||
return new Promise((resolve) => {
|
||||
const searchTerm = findWordAtCursor(editor)
|
||||
|
@ -39,13 +44,11 @@ const linkAndExtraTagHint = (editor: Editor): Promise<Hints | null> => {
|
|||
} else {
|
||||
resolve({
|
||||
list: suggestions.map((suggestion: string): Hint => {
|
||||
const user = getUser()
|
||||
const userName = user ? user.name : 'Anonymous'
|
||||
switch (suggestion) {
|
||||
case 'name':
|
||||
// Get the user when a completion happens, this prevents to early calls resulting in 'Anonymous'
|
||||
return {
|
||||
text: `[name=${userName}]`
|
||||
text: `[name=${getUserName()}]`
|
||||
}
|
||||
case 'time':
|
||||
// show the current time when the autocompletion is opened and not when the function is loaded
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue