Skip to content

Commit

Permalink
address feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
snqb committed Jan 3, 2025
1 parent ce82e0a commit 01b8c52
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 18 deletions.
4 changes: 1 addition & 3 deletions src/actions/formatLetterCase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@ export const formatLetterCaseActionCreator =
const cursor = state.cursor
if (!cursor) return

const thought = pathToThought(state, cursor)
const originalThoughtValue = thought?.value

const originalThoughtValue = pathToThought(state, cursor)?.value
if (originalThoughtValue === undefined) return

const updatedThoughtValue = applyLetterCase(command, originalThoughtValue)
Expand Down
19 changes: 11 additions & 8 deletions src/hooks/useDragAndDropSubThought.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,16 +125,19 @@ const drop = (props: DroppableSubthoughts, monitor: DropTargetMonitor) => {
return
}

if (thoughtTo) {
store.dispatch(
moveThought({
oldPath: thoughtsFrom,
newPath: pathTo,
newRank: (dropTop ? getPrevRank : getNextRank)(state, thoughtTo.id),
}),
)
if (!thoughtTo) {
console.warn(`Cannot drop ${thoughtFrom} on itself. Aborting drop.`)
return
}

store.dispatch(
moveThought({
oldPath: thoughtsFrom,
newPath: pathTo,
newRank: (dropTop ? getPrevRank : getNextRank)(state, thoughtTo.id),
}),
)

// alert user of move to another context
if (!sameContext && thoughtTo && thoughtFrom) {
// wait until after MultiGesture has cleared the error so this alert does no get cleared
Expand Down
2 changes: 1 addition & 1 deletion src/initialize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ const windowEm = {
return contexts
.map(id => getThoughtById(state, id))
.filter(Boolean)
.map(context => context.parentId)
.map(thought => thoughtToContext(state, thought.parentId))
}),
getAllChildrenByContext: withState((state: State, context: Context) =>
getAllChildren(state, contextToThoughtId(state, context) || null),
Expand Down
7 changes: 4 additions & 3 deletions src/selectors/prevSibling.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,11 @@ export const prevSibling = (
const showContexts = showContextsForced ?? isContextViewActive(state, parentPath)

// siblings, including the current thought
const siblings =
showContexts && parent
const siblings = showContexts
? parent
? getContextsSortedAndRanked(state, parent.value)
: getChildrenSorted(state, thought.parentId)
: []
: getChildrenSorted(state, thought.parentId)

// in context view, we need to match the context's parentId, since all context's ids refer to lexeme instances
const index = siblings.findIndex(child => (showContexts ? child.parentId : child.id) === id)
Expand Down
4 changes: 2 additions & 2 deletions src/test-helpers/contextToThought.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ import getThoughtById from '../selectors/getThoughtById'
/**
* Converts a Context to a Thought. If more than one thought has the same value in the same context, traveerses the first.
*/
const contextToThought = (state: State, context: Context): Thought | null => {
const contextToThought = (state: State, context: Context): Thought | undefined => {
const id = contextToThoughtId(state, context)
return id ? (getThoughtById(state, id) ?? null) : null
return id ? getThoughtById(state, id) : undefined
}

export default contextToThought
2 changes: 1 addition & 1 deletion src/util/importJSON.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ const insertThought = (
},
) => {
const thoughtOld = getThoughtById(state, id)
if (!thoughtOld) return
if (!thoughtOld) return null
const childLastUpdated = block.children[0]?.lastUpdated
const childCreated = block.children[0]?.created
const lastUpdatedInherited =
Expand Down

0 comments on commit 01b8c52

Please sign in to comment.