Skip to content

Commit b7c48f1

Browse files
committed
[devtools] port devtools-indicator position to dispatcher
1 parent ca90cd0 commit b7c48f1

File tree

2 files changed

+20
-5
lines changed

2 files changed

+20
-5
lines changed

packages/next/src/next-devtools/dev-overlay/components/devtools-indicator/devtools-indicator.tsx

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ import {
1515
ACTION_ERROR_OVERLAY_CLOSE,
1616
STORAGE_KEY_POSITION,
1717
ACTION_DEVTOOLS_PANEL_CLOSE,
18+
ACTION_DEVTOOLS_INDICATOR_POSITION,
1819
} from '../../shared'
19-
import { getInitialPosition } from '../errors/dev-tools-indicator/dev-tools-info/preferences'
2020
import { Draggable } from '../errors/dev-tools-indicator/draggable'
2121

2222
export const INDICATOR_PADDING = 20
@@ -35,9 +35,8 @@ export function DevToolsIndicator({
3535
scale: DevToolsScale
3636
}) {
3737
const [open, setOpen] = useState(false)
38-
const [position, setPosition] = useState(getInitialPosition())
3938

40-
const [vertical, horizontal] = position.split('-', 2)
39+
const [vertical, horizontal] = state.indicatorPosition.split('-', 2)
4140

4241
const toggleErrorOverlay = () => {
4342
dispatch({ type: ACTION_DEVTOOLS_PANEL_CLOSE })
@@ -67,10 +66,13 @@ export function DevToolsIndicator({
6766
<Draggable
6867
padding={INDICATOR_PADDING}
6968
onDragStart={() => setOpen(false)}
70-
position={position}
69+
position={state.indicatorPosition}
7170
setPosition={(p) => {
71+
dispatch({
72+
type: ACTION_DEVTOOLS_INDICATOR_POSITION,
73+
indicatorPosition: p,
74+
})
7275
localStorage.setItem(STORAGE_KEY_POSITION, p)
73-
setPosition(p)
7476
}}
7577
>
7678
{/* Trigger */}

packages/next/src/next-devtools/dev-overlay/shared.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ export interface OverlayState {
3232
routerType: 'pages' | 'app'
3333
isErrorOverlayOpen: boolean
3434
isDevToolsPanelOpen: boolean
35+
indicatorPosition: Corners
3536
}
3637
export type OverlayDispatch = React.Dispatch<DispatcherEvent>
3738

@@ -59,6 +60,8 @@ export const ACTION_DEVTOOLS_PANEL_OPEN = 'devtools-panel-open'
5960
export const ACTION_DEVTOOLS_PANEL_CLOSE = 'devtools-panel-close'
6061
export const ACTION_DEVTOOLS_PANEL_TOGGLE = 'devtools-panel-toggle'
6162

63+
export const ACTION_DEVTOOLS_INDICATOR_POSITION = 'dev-tools-indicator-position'
64+
6265
export const STORAGE_KEY_THEME = '__nextjs-dev-tools-theme'
6366
export const STORAGE_KEY_POSITION = '__nextjs-dev-tools-position'
6467
export const STORAGE_KEY_DEVTOOLS_PANEL_POSITION =
@@ -142,6 +145,11 @@ export interface DevToolsPanelToggleAction {
142145
type: typeof ACTION_DEVTOOLS_PANEL_TOGGLE
143146
}
144147

148+
export interface DevToolsIndicatorPositionAction {
149+
type: typeof ACTION_DEVTOOLS_INDICATOR_POSITION
150+
indicatorPosition: Corners
151+
}
152+
145153
export type DispatcherEvent =
146154
| BuildOkAction
147155
| BuildErrorAction
@@ -163,6 +171,7 @@ export type DispatcherEvent =
163171
| DevToolsPanelOpenAction
164172
| DevToolsPanelCloseAction
165173
| DevToolsPanelToggleAction
174+
| DevToolsIndicatorPositionAction
166175

167176
const REACT_ERROR_STACK_BOTTOM_FRAME_REGEX =
168177
// 1st group: v8
@@ -202,6 +211,7 @@ export const INITIAL_OVERLAY_STATE: Omit<
202211
versionInfo: { installed: '0.0.0', staleness: 'unknown' },
203212
debugInfo: { devtoolsFrontendUrl: undefined },
204213
isDevToolsPanelOpen: false,
214+
indicatorPosition: 'bottom-left',
205215
}
206216

207217
function getInitialState(
@@ -373,6 +383,9 @@ export function useErrorOverlayReducer(
373383
case ACTION_DEVTOOLS_PANEL_TOGGLE: {
374384
return { ...state, isDevToolsPanelOpen: !state.isDevToolsPanelOpen }
375385
}
386+
case ACTION_DEVTOOLS_INDICATOR_POSITION: {
387+
return { ...state, indicatorPosition: action.indicatorPosition }
388+
}
376389
default: {
377390
return state
378391
}

0 commit comments

Comments
 (0)