Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ export function FileViewer({
file={file}
workspaceId={workspaceId}
canEdit={canEdit}
previewMode={previewMode ?? (showPreview ? 'split' : 'editor')}
previewMode={previewMode ?? (showPreview ? 'preview' : 'editor')}
autoFocus={autoFocus}
onDirtyChange={onDirtyChange}
onSaveStatusChange={onSaveStatusChange}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export type { PreviewMode } from './file-viewer'
export { FileViewer, isPreviewable, isTextEditable } from './file-viewer'
export { PREVIEW_ONLY_EXTENSIONS, RICH_PREVIEWABLE_EXTENSIONS } from './preview-panel'
export { RICH_PREVIEWABLE_EXTENSIONS } from './preview-panel'
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,6 @@ const PREVIEWABLE_EXTENSIONS: Record<string, PreviewType> = {
svg: 'svg',
}

/** Extensions that should default to rendered preview (no raw editor). */
export const PREVIEW_ONLY_EXTENSIONS = new Set(['html', 'htm', 'svg'])

/** All extensions that have a rich preview renderer. */
export const RICH_PREVIEWABLE_EXTENSIONS = new Set(Object.keys(PREVIEWABLE_EXTENSIONS))

Expand Down
9 changes: 5 additions & 4 deletions apps/sim/app/workspace/[workspaceId]/files/files.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -476,10 +476,11 @@ export function Files() {
}, [closeListContextMenu])

useEffect(() => {
if (justCreatedFileIdRef.current && selectedFileId !== justCreatedFileIdRef.current) {
const isJustCreated = selectedFileId != null && justCreatedFileIdRef.current === selectedFileId
if (justCreatedFileIdRef.current && !isJustCreated) {
justCreatedFileIdRef.current = null
}
setShowPreview(true)
setShowPreview(!isJustCreated)
}, [selectedFileId])

useEffect(() => {
Expand Down Expand Up @@ -521,8 +522,8 @@ export function Files() {
...(canPreview
? [
{
label: showPreview ? 'Hide Preview' : 'Preview',
icon: Eye,
label: showPreview ? 'Edit' : 'Preview',
icon: showPreview ? Pencil : Eye,
onClick: handleTogglePreview,
},
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
useState,
} from 'react'
import { Button, Tooltip } from '@/components/emcn'
import { Columns3, Eye, PanelLeft, Rows3 } from '@/components/emcn/icons'
import { Columns3, Eye, PanelLeft, Pencil } from '@/components/emcn/icons'
import { cn } from '@/lib/core/utils/cn'
import type { PreviewMode } from '@/app/workspace/[workspaceId]/files/components/file-viewer'
import { AddResourceDropdown } from '@/app/workspace/[workspaceId]/home/components/mothership-view/components/add-resource-dropdown'
Expand Down Expand Up @@ -36,9 +36,9 @@ const EDGE_ZONE = 40
const SCROLL_SPEED = 8

const PREVIEW_MODE_ICONS = {
editor: Rows3,
split: Columns3,
preview: Eye,
editor: Columns3,
split: Eye,
preview: Pencil,
} satisfies Record<PreviewMode, (props: ComponentProps<typeof Eye>) => ReactNode>

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,7 @@ import { useCallback, useEffect, useState } from 'react'
import { cn } from '@/lib/core/utils/cn'
import { getFileExtension } from '@/lib/uploads/utils/file-utils'
import type { PreviewMode } from '@/app/workspace/[workspaceId]/files/components/file-viewer'
import {
PREVIEW_ONLY_EXTENSIONS,
RICH_PREVIEWABLE_EXTENSIONS,
} from '@/app/workspace/[workspaceId]/files/components/file-viewer'
import { RICH_PREVIEWABLE_EXTENSIONS } from '@/app/workspace/[workspaceId]/files/components/file-viewer'
import type {
MothershipResource,
MothershipResourceType,
Expand Down Expand Up @@ -49,12 +46,11 @@ export function MothershipView({
}: MothershipViewProps) {
const active = resources.find((r) => r.id === activeResourceId) ?? resources[0] ?? null

const [previewMode, setPreviewMode] = useState<PreviewMode>('split')
const [previewMode, setPreviewMode] = useState<PreviewMode>('preview')
const handleCyclePreview = useCallback(() => setPreviewMode((m) => PREVIEW_CYCLE[m]), [])

useEffect(() => {
const ext = active?.type === 'file' ? getFileExtension(active.title) : ''
setPreviewMode(PREVIEW_ONLY_EXTENSIONS.has(ext) ? 'preview' : 'split')
setPreviewMode('preview')
}, [active?.id])

const isActivePreviewable =
Expand Down
Loading