Skip to content

Commit

Permalink
fix(ui): use sticky layout at mobile platform, fix chrome scroll bug
Browse files Browse the repository at this point in the history
  • Loading branch information
yzh990918 committed May 11, 2023
1 parent 96cc057 commit 463a280
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/components/Main.astro
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import '@/assets/transition.css'
import Conversation from './main/Conversation'
---

<main class="relative h-100vh flex-1 flex flex-col overflow-hidden bg-base">
<main class="relative h-full flex-1 flex flex-col overflow-hidden bg-base">
<Header client:load />
<main class="flex-1 mt-14 flex flex-col overflow-hidden">
<!-- <ConversationConfiguration /> -->
Expand Down
8 changes: 7 additions & 1 deletion src/components/Send.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { addConversation, conversationMap, currentConversationId } from '@/store
import { loadingStateMap, streamsMap } from '@/stores/streams'
import { handlePrompt } from '@/logics/conversation'
import { globalAbortController } from '@/stores/settings'
import { useMobileScreen } from '@/hooks'

export default () => {
let inputRef: HTMLTextAreaElement
Expand All @@ -18,6 +19,7 @@ export default () => {
const $globalAbortController = useStore(globalAbortController)

const [inputPrompt, setInputPrompt] = createSignal('')
const [footerClass, setFooterClass] = createSignal('')
const isEditing = () => inputPrompt() || $isSendBoxFocus()
const currentConversation = () => {
return $conversationMap()[$currentConversationId()]
Expand All @@ -29,6 +31,10 @@ export default () => {
createShortcut(['Control', 'Enter'], () => {
$isSendBoxFocus() && handleSend()
})

useMobileScreen(() => {
setFooterClass('sticky bottom-0 left-0 right-0 overflow-hidden')
})
})

const stateType = () => {
Expand Down Expand Up @@ -155,7 +161,7 @@ export default () => {
}

return (
<div class={`relative shrink-0 border-t border-base pb-[env(safe-area-inset-bottom)] transition transition-colors duration-300 ${stateRootClass()}`}>
<div class={`relative shrink-0 border-t border-base pb-[env(safe-area-inset-bottom)] transition transition-colors duration-300 ${stateRootClass()} ${footerClass()}`}>
<div class={`relative transition transition-height duration-240 ${stateHeightClass()}`}>
<Switch fallback={<EmptyState />}>
<Match when={stateType() === 'error'}>
Expand Down
1 change: 1 addition & 0 deletions src/hooks/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ export * from './useDark'
export * from './useCopy'
export * from './useClickOutside'
export * from './useLargeScreen'
export * from './useMobileScreen'
22 changes: 22 additions & 0 deletions src/hooks/useMobileScreen.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { createSignal, onCleanup, onMount } from 'solid-js'
import { throttle } from '@solid-primitives/scheduled'

export const useMobileScreen = (handler: (e: UIEvent) => void) => {
const [isMobileScreen, setIsMobileScreen] = createSignal(false)

const handleResize = throttle((e: UIEvent) => {
setIsMobileScreen(window.innerWidth < 640)
if (window.innerWidth < 640)
return handler(e)
}, 200)

onMount(() => {
window.addEventListener('resize', handleResize)
})

onCleanup(() => {
window.removeEventListener('resize', handleResize)
})

return isMobileScreen
}

0 comments on commit 463a280

Please sign in to comment.