Skip to content

Commit 65fd8a0

Browse files
committed
mobile improvements
1 parent 9338d1f commit 65fd8a0

File tree

4 files changed

+31
-24
lines changed

4 files changed

+31
-24
lines changed

app/components/CodeExplorer.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ export function CodeExplorer({
8686

8787
return (
8888
<div
89-
className={`flex flex-col min-h-[80dvh] border border-gray-200 dark:border-gray-700 rounded-lg overflow-hidden ${
89+
className={`flex flex-col min-h-[60dvh] sm:min-h-[80dvh] border border-gray-200 dark:border-gray-700 rounded-lg overflow-hidden ${
9090
isFullScreen ? 'fixed inset-0 z-50 bg-white dark:bg-gray-900 p-4' : ''
9191
}`}
9292
>
@@ -116,7 +116,9 @@ export function CodeExplorer({
116116
<div className="flex-1 overflow-auto relative">
117117
<CodeBlock
118118
isEmbedded
119-
className={`${isFullScreen ? 'max-h-[90dvh]' : 'max-h-[80dvh]'}`}
119+
className={`h-full ${
120+
isFullScreen ? 'max-h-[90dvh]' : 'max-h-[80dvh]'
121+
}`}
120122
>
121123
<code
122124
className={`language-${overrideExtension(

app/components/CodeExplorerTopBar.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@ export function CodeExplorerTopBar({
4343
: 'text-gray-500 hover:text-gray-700 dark:hover:text-gray-300'
4444
}`}
4545
>
46-
Code Explorer
46+
<span className="hidden sm:inline">Code Explorer</span>
47+
<span className="sm:hidden">Code</span>
4748
{activeTab === 'code' ? (
4849
<div className="absolute bottom-0 left-0 right-0 h-0.5 bg-blue-500" />
4950
) : (
@@ -58,7 +59,8 @@ export function CodeExplorerTopBar({
5859
: 'text-gray-500 hover:text-gray-700 dark:hover:text-gray-300'
5960
}`}
6061
>
61-
Interactive Sandbox
62+
<span className="hidden sm:inline">Interactive Sandbox</span>
63+
<span className="sm:hidden">Sandbox</span>
6264
{activeTab === 'sandbox' ? (
6365
<div className="absolute bottom-0 left-0 right-0 h-0.5 bg-blue-500" />
6466
) : (

app/components/FileExplorer.tsx

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -129,19 +129,20 @@ export function FileExplorer({
129129
startWidth: 0,
130130
})
131131

132-
const startResize = (e: React.MouseEvent) => {
132+
const startResize = (e: React.MouseEvent | React.TouchEvent) => {
133133
setIsResizing(true)
134134
startResizeRef.current = {
135-
startX: e.clientX,
135+
startX: 'touches' in e ? e.touches[0].clientX : e.clientX,
136136
startWidth: sidebarWidth,
137137
}
138138
}
139139

140140
React.useEffect(() => {
141-
const handleMouseMove = (e: MouseEvent) => {
141+
const handleMouseMove = (e: MouseEvent | TouchEvent) => {
142142
if (!isResizing) return
143143

144-
const diff = e.clientX - startResizeRef.current.startX
144+
const clientX = 'touches' in e ? e.touches[0].clientX : e.clientX
145+
const diff = clientX - startResizeRef.current.startX
145146
const newWidth = startResizeRef.current.startWidth + diff
146147

147148
if (newWidth >= MIN_SIDEBAR_WIDTH && newWidth <= 600) {
@@ -153,10 +154,8 @@ export function FileExplorer({
153154

154155
const handleMouseUp = () => {
155156
setIsResizing(false)
156-
// Check if we should close the sidebar
157157
if (sidebarWidth <= MIN_SIDEBAR_WIDTH) {
158-
setSidebarWidth(200) // Reset width to default
159-
// Find setIsSidebarOpen in parent scope
158+
setSidebarWidth(200)
160159
const event = new CustomEvent('closeSidebar')
161160
window.dispatchEvent(event)
162161
}
@@ -165,11 +164,15 @@ export function FileExplorer({
165164
if (isResizing) {
166165
document.addEventListener('mousemove', handleMouseMove)
167166
document.addEventListener('mouseup', handleMouseUp)
167+
document.addEventListener('touchmove', handleMouseMove)
168+
document.addEventListener('touchend', handleMouseUp)
168169
}
169170

170171
return () => {
171172
document.removeEventListener('mousemove', handleMouseMove)
172173
document.removeEventListener('mouseup', handleMouseUp)
174+
document.removeEventListener('touchmove', handleMouseMove)
175+
document.removeEventListener('touchend', handleMouseUp)
173176
}
174177
}, [isResizing, sidebarWidth])
175178

@@ -190,10 +193,13 @@ export function FileExplorer({
190193
return (
191194
<>
192195
<div
193-
style={{ width: isSidebarOpen ? sidebarWidth : 0 }}
194-
className={`flex-shrink-0 overflow-y-auto bg-gradient-to-r from-gray-50 via-gray-50 to-transparent dark:from-gray-800/50 dark:via-gray-800/50 dark:to-transparent lg:pr-2 shadow-sm ${
196+
style={{
197+
width: isSidebarOpen ? sidebarWidth : 0,
198+
paddingRight: isSidebarOpen ? '0.5rem' : 0,
199+
}}
200+
className={`flex-shrink-0 overflow-y-auto bg-gradient-to-r from-gray-50 via-gray-50 to-transparent dark:from-gray-800/50 dark:via-gray-800/50 dark:to-transparent shadow-sm ${
195201
isResizing ? '' : 'transition-all duration-300'
196-
} ${isSidebarOpen ? '' : 'w-0 pr-0'}`}
202+
}`}
197203
>
198204
{githubContents && isSidebarOpen ? (
199205
<div className="p-2">
@@ -214,6 +220,7 @@ export function FileExplorer({
214220
isResizing ? '' : 'transition-colors'
215221
} ${isSidebarOpen ? '' : 'hidden'}`}
216222
onMouseDown={startResize}
223+
onTouchStart={startResize}
217224
/>
218225
</>
219226
)

app/components/Markdown.tsx

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import * as React from 'react'
22
import { FaRegCopy } from 'react-icons/fa'
33
import { MarkdownLink } from '~/components/MarkdownLink'
44
import type { HTMLProps } from 'react'
5-
import { getHighlighter as shikiGetHighlighter } from 'shiki/bundle-web.mjs'
5+
import { createHighlighter as shikiGetHighlighter } from 'shiki/bundle-web.mjs'
66
import { transformerNotationDiff } from '@shikijs/transformers'
77
import parse, {
88
attributesToProps,
@@ -104,17 +104,10 @@ export function CodeBlock({
104104

105105
const [codeElement, setCodeElement] = React.useState(
106106
<>
107-
<pre
108-
ref={ref}
109-
className={`shiki github-light ${isEmbedded ? 'rounded-none' : ''}`}
110-
>
107+
<pre ref={ref} className={`shiki github-light`}>
111108
<code>{code}</code>
112109
</pre>
113-
<pre
114-
className={`shiki tokyo-night bg-gray-900 text-gray-400 ${
115-
isEmbedded ? 'rounded-none' : ''
116-
}`}
117-
>
110+
<pre className={`shiki tokyo-night bg-gray-900 text-gray-400`}>
118111
<code>{code}</code>
119112
</pre>
120113
</>
@@ -141,6 +134,9 @@ export function CodeBlock({
141134
setCodeElement(
142135
<div
143136
// className={`m-0 text-sm rounded-md w-full border border-gray-500/20 dark:border-gray-500/30`}
137+
className={`${
138+
isEmbedded ? 'h-full [&>pre]:h-full [&>pre]:rounded-none' : ''
139+
} `}
144140
dangerouslySetInnerHTML={{ __html: htmls.join('') }}
145141
ref={ref}
146142
/>

0 commit comments

Comments
 (0)