Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
15 changes: 13 additions & 2 deletions apps/web/src/components/Files.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ interface Props {
visible: boolean
onHide: () => void
yDoc?: Y.Doc
scrollToBottom?: () => void
}
export default function Files(props: Props) {
const { startedAt: environmentStartedAt } = useEnvironmentStatus(
Expand Down Expand Up @@ -87,8 +88,13 @@ file`
}

requestRun(pythonBlock, blocks, layout, environmentStartedAt, true)
if (props.scrollToBottom) {
setTimeout(() => {
props.scrollToBottom?.()
}, 200)
}
},
[props.yDoc, environmentStartedAt]
[props.yDoc, environmentStartedAt, props.scrollToBottom]
)

const onUseInSQL = useCallback(
Expand Down Expand Up @@ -132,8 +138,13 @@ file`
}

requestRun(sqlBlock, blocks, layout, environmentStartedAt, true)
if (props.scrollToBottom) {
setTimeout(() => {
props.scrollToBottom?.()
}, 200)
}
},
[props.yDoc, environmentStartedAt]
[props.yDoc, environmentStartedAt, props.scrollToBottom]
)

const [
Expand Down
10 changes: 9 additions & 1 deletion apps/web/src/components/PrivateDocumentPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import dynamic from 'next/dynamic'

import { useDataSources } from '@/hooks/useDatasources'
import useDocument from '@/hooks/useDocument'
import { useCallback, useMemo, useState } from 'react'
import { useCallback, useMemo, useRef, useState } from 'react'
import { useRouter } from 'next/router'
import type { ApiDocument, ApiUser, UserWorkspaceRole } from '@briefer/database'
import { isNil } from 'ramda'
Expand Down Expand Up @@ -81,6 +81,7 @@ function PrivateDocumentPageInner(
publishing: boolean
}
) {
const [shouldScroll, setShouldScroll] = useState(false)
const documentTitle = useMemo(
() => props.document.title || 'Untitled',
[props.document.title]
Expand Down Expand Up @@ -324,6 +325,10 @@ function PrivateDocumentPageInner(
</div>
)

const scrollToBottom = useCallback(() => {
setShouldScroll(true)
}, [setShouldScroll])

return (
<Layout
topBarClassname={props.isApp ? 'bg-gray-50' : undefined}
Expand All @@ -332,6 +337,8 @@ function PrivateDocumentPageInner(
<div className="w-full relative flex">
<EditorAwarenessProvider awareness={provider.awareness}>
<V2Editor
shouldScroll={shouldScroll}
setShouldScroll={setShouldScroll}
document={props.document}
dataSources={dataSources}
isPublicViewer={false}
Expand Down Expand Up @@ -401,6 +408,7 @@ function PrivateDocumentPageInner(
visible={selectedSidebar?._tag === 'files'}
onHide={onHideSidebar}
yDoc={yDoc}
scrollToBottom={scrollToBottom}
/>
<ReusableComponents
workspaceId={props.workspaceId}
Expand Down
9 changes: 9 additions & 0 deletions apps/web/src/components/v2Editor/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1175,6 +1175,8 @@ const V2EditorRow = (props: {
}

type V2EditorProps = {
shouldScroll: boolean
setShouldScroll: (shouldScroll: boolean) => void
isPublicViewer: boolean
document: ApiDocument
dataSources: APIDataSources
Expand Down Expand Up @@ -1269,6 +1271,13 @@ const V2Editor = (props: V2EditorProps) => {
}
}, [interactionState, scrollViewRef])

useEffect(() => {
if (props.shouldScroll && scrollViewRef.current) {
scrollViewRef.current.scrollTo({ top: scrollViewRef.current.scrollHeight, behavior: 'smooth' })
props.setShouldScroll(false)
}
}, [props.shouldScroll, scrollViewRef, props.setShouldScroll])

const onAddBlock = useCallback(
(type: BlockType, index: number) => {
return props.yDoc.transact(() => {
Expand Down