mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-21 20:47:08 -05:00
Merge pull request #16138 from overleaf/ii-ide-page-prototype-review-panel-overview-loading
[web] React ide page overview switch GitOrigin-RevId: 9a24a8ba9ed8e86d486a12a65259d25c1352c864
This commit is contained in:
parent
ffb24e061e
commit
c3689ca6f3
5 changed files with 60 additions and 17 deletions
|
@ -139,9 +139,8 @@ function useReviewPanelState(): ReviewPanelStateReactIde {
|
||||||
|
|
||||||
const [subView, setSubView] =
|
const [subView, setSubView] =
|
||||||
useState<ReviewPanel.Value<'subView'>>('cur_file')
|
useState<ReviewPanel.Value<'subView'>>('cur_file')
|
||||||
const [loading] = useScopeValue<ReviewPanel.Value<'loading'>>(
|
const [isOverviewLoading, setIsOverviewLoading] =
|
||||||
'reviewPanel.overview.loading'
|
useState<ReviewPanel.Value<'isOverviewLoading'>>(false)
|
||||||
)
|
|
||||||
// All selected changes. If an aggregated change (insertion + deletion) is selected, the two ids
|
// All selected changes. If an aggregated change (insertion + deletion) is selected, the two ids
|
||||||
// will be present. The length of this array will differ from the count below (see explanation).
|
// will be present. The length of this array will differ from the count below (see explanation).
|
||||||
const selectedEntryIds = useRef<ThreadId[]>([])
|
const selectedEntryIds = useRef<ThreadId[]>([])
|
||||||
|
@ -844,9 +843,9 @@ function useReviewPanelState(): ReviewPanelStateReactIde {
|
||||||
if (!trackChangesVisible) {
|
if (!trackChangesVisible) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
setReviewPanelOpen(value => !value)
|
setReviewPanelOpen(!reviewPanelOpen)
|
||||||
sendMB('rp-toggle-panel', {
|
sendMB('rp-toggle-panel', {
|
||||||
value: reviewPanelOpen,
|
value: !reviewPanelOpen,
|
||||||
})
|
})
|
||||||
}, [reviewPanelOpen, setReviewPanelOpen, trackChangesVisible])
|
}, [reviewPanelOpen, setReviewPanelOpen, trackChangesVisible])
|
||||||
|
|
||||||
|
@ -1404,6 +1403,52 @@ function useReviewPanelState(): ReviewPanelStateReactIde {
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const openSubView = useRef<typeof subView>('cur_file')
|
||||||
|
useEffect(() => {
|
||||||
|
if (!reviewPanelOpen) {
|
||||||
|
// Always show current file when not open, but save current state
|
||||||
|
setSubView(prevState => {
|
||||||
|
openSubView.current = prevState
|
||||||
|
return 'cur_file'
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
// Reset back to what we had when previously open
|
||||||
|
setSubView(openSubView.current)
|
||||||
|
}
|
||||||
|
handleLayoutChange({ async: true, animate: false })
|
||||||
|
}, [reviewPanelOpen])
|
||||||
|
|
||||||
|
const canRefreshRanges = useRef(false)
|
||||||
|
useEffect(() => {
|
||||||
|
if (subView === 'overview' && canRefreshRanges.current) {
|
||||||
|
canRefreshRanges.current = false
|
||||||
|
|
||||||
|
setIsOverviewLoading(true)
|
||||||
|
refreshRanges().finally(() => {
|
||||||
|
setIsOverviewLoading(false)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}, [subView, refreshRanges])
|
||||||
|
|
||||||
|
const prevSubView = useRef(subView)
|
||||||
|
const initializedPrevSubView = useRef(false)
|
||||||
|
useEffect(() => {
|
||||||
|
// Prevent setting a computed value for `prevSubView` on mount
|
||||||
|
if (!initializedPrevSubView.current) {
|
||||||
|
initializedPrevSubView.current = true
|
||||||
|
return
|
||||||
|
}
|
||||||
|
prevSubView.current = subView === 'cur_file' ? 'overview' : 'cur_file'
|
||||||
|
// Allow refreshing ranges once for each `subView` change
|
||||||
|
canRefreshRanges.current = true
|
||||||
|
}, [subView])
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (subView === 'cur_file' && prevSubView.current === 'overview') {
|
||||||
|
dispatchReviewPanelEvent('overview-closed', subView)
|
||||||
|
}
|
||||||
|
}, [subView])
|
||||||
|
|
||||||
const values = useMemo<ReviewPanelStateReactIde['values']>(
|
const values = useMemo<ReviewPanelStateReactIde['values']>(
|
||||||
() => ({
|
() => ({
|
||||||
collapsed,
|
collapsed,
|
||||||
|
@ -1421,7 +1466,7 @@ function useReviewPanelState(): ReviewPanelStateReactIde {
|
||||||
toolbarHeight,
|
toolbarHeight,
|
||||||
subView,
|
subView,
|
||||||
wantTrackChanges,
|
wantTrackChanges,
|
||||||
loading,
|
isOverviewLoading,
|
||||||
openDocId,
|
openDocId,
|
||||||
lineHeight,
|
lineHeight,
|
||||||
trackChangesState,
|
trackChangesState,
|
||||||
|
@ -1448,7 +1493,7 @@ function useReviewPanelState(): ReviewPanelStateReactIde {
|
||||||
toolbarHeight,
|
toolbarHeight,
|
||||||
subView,
|
subView,
|
||||||
wantTrackChanges,
|
wantTrackChanges,
|
||||||
loading,
|
isOverviewLoading,
|
||||||
openDocId,
|
openDocId,
|
||||||
lineHeight,
|
lineHeight,
|
||||||
trackChangesState,
|
trackChangesState,
|
||||||
|
|
|
@ -1,8 +1,6 @@
|
||||||
import { ReactScopeValueStore } from '@/features/ide-react/scope-value-store/react-scope-value-store'
|
import { ReactScopeValueStore } from '@/features/ide-react/scope-value-store/react-scope-value-store'
|
||||||
|
|
||||||
export default function populateReviewPanelScope(store: ReactScopeValueStore) {
|
export default function populateReviewPanelScope(store: ReactScopeValueStore) {
|
||||||
store.set('reviewPanel.overview.loading', false)
|
|
||||||
store.set('reviewPanel.nVisibleSelectedChanges', 0)
|
|
||||||
store.set('users', {})
|
store.set('users', {})
|
||||||
store.set('reviewPanel.layoutToLeft', false)
|
store.set('reviewPanel.layoutToLeft', false)
|
||||||
store.set('gotoEntry', () => {})
|
store.set('gotoEntry', () => {})
|
||||||
|
|
|
@ -9,7 +9,7 @@ import { useFileTreeData } from '@/shared/context/file-tree-data-context'
|
||||||
import { MainDocument } from '../../../../../../types/project-settings'
|
import { MainDocument } from '../../../../../../types/project-settings'
|
||||||
|
|
||||||
function OverviewContainer() {
|
function OverviewContainer() {
|
||||||
const { loading } = useReviewPanelValueContext()
|
const { isOverviewLoading } = useReviewPanelValueContext()
|
||||||
const docs: MainDocument[] = useFileTreeData().docs
|
const docs: MainDocument[] = useFileTreeData().docs
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
@ -23,7 +23,7 @@ function OverviewContainer() {
|
||||||
tabIndex={0}
|
tabIndex={0}
|
||||||
aria-labelledby="review-panel-tab-overview"
|
aria-labelledby="review-panel-tab-overview"
|
||||||
>
|
>
|
||||||
{loading ? (
|
{isOverviewLoading ? (
|
||||||
<div className="rp-loading">
|
<div className="rp-loading">
|
||||||
<Icon type="spinner" spin />
|
<Icon type="spinner" spin />
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -14,9 +14,9 @@ function useAngularReviewPanelState(): ReviewPanelState {
|
||||||
const [subView, setSubView] = useScopeValue<ReviewPanel.Value<'subView'>>(
|
const [subView, setSubView] = useScopeValue<ReviewPanel.Value<'subView'>>(
|
||||||
'reviewPanel.subView'
|
'reviewPanel.subView'
|
||||||
)
|
)
|
||||||
const [loading] = useScopeValue<ReviewPanel.Value<'loading'>>(
|
const [isOverviewLoading] = useScopeValue<
|
||||||
'reviewPanel.overview.loading'
|
ReviewPanel.Value<'isOverviewLoading'>
|
||||||
)
|
>('reviewPanel.overview.loading')
|
||||||
const [nVisibleSelectedChanges] = useScopeValue<
|
const [nVisibleSelectedChanges] = useScopeValue<
|
||||||
ReviewPanel.Value<'nVisibleSelectedChanges'>
|
ReviewPanel.Value<'nVisibleSelectedChanges'>
|
||||||
>('reviewPanel.nVisibleSelectedChanges')
|
>('reviewPanel.nVisibleSelectedChanges')
|
||||||
|
@ -170,7 +170,7 @@ function useAngularReviewPanelState(): ReviewPanelState {
|
||||||
toolbarHeight,
|
toolbarHeight,
|
||||||
subView,
|
subView,
|
||||||
wantTrackChanges,
|
wantTrackChanges,
|
||||||
loading,
|
isOverviewLoading,
|
||||||
openDocId,
|
openDocId,
|
||||||
lineHeight,
|
lineHeight,
|
||||||
trackChangesState,
|
trackChangesState,
|
||||||
|
@ -197,7 +197,7 @@ function useAngularReviewPanelState(): ReviewPanelState {
|
||||||
toolbarHeight,
|
toolbarHeight,
|
||||||
subView,
|
subView,
|
||||||
wantTrackChanges,
|
wantTrackChanges,
|
||||||
loading,
|
isOverviewLoading,
|
||||||
openDocId,
|
openDocId,
|
||||||
lineHeight,
|
lineHeight,
|
||||||
trackChangesState,
|
trackChangesState,
|
||||||
|
|
|
@ -30,7 +30,7 @@ export interface ReviewPanelState {
|
||||||
toolbarHeight: number
|
toolbarHeight: number
|
||||||
subView: SubView
|
subView: SubView
|
||||||
wantTrackChanges: boolean
|
wantTrackChanges: boolean
|
||||||
loading: boolean
|
isOverviewLoading: boolean
|
||||||
openDocId: DocId | null
|
openDocId: DocId | null
|
||||||
lineHeight: number
|
lineHeight: number
|
||||||
trackChangesState:
|
trackChangesState:
|
||||||
|
|
Loading…
Reference in a new issue