Skip to content

Commit a0c19d7

Browse files
committed
improve the compatibility of Safari and Firefox with the new style (#305, #371)
1 parent 75d92bc commit a0c19d7

File tree

2 files changed

+41
-10
lines changed

2 files changed

+41
-10
lines changed

src/components/ConversationCard/index.jsx

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import PropTypes from 'prop-types'
33
import Browser from 'webextension-polyfill'
44
import InputBox from '../InputBox'
55
import ConversationItem from '../ConversationItem'
6-
import { createElementAtPosition, isSafari } from '../../utils'
6+
import { createElementAtPosition, isFirefox, isMobile, isSafari } from '../../utils'
77
import {
88
LinkExternalIcon,
99
ArchiveIcon,
@@ -47,6 +47,8 @@ function ConversationCard(props) {
4747
const [session, setSession] = useState(props.session)
4848
const windowSize = useClampWindowSize([750, 1500], [250, 1100])
4949
const bodyRef = useRef(null)
50+
const [completeDraggable, setCompleteDraggable] = useState(false)
51+
5052
/**
5153
* @type {[ConversationItemData[], (conversationItemData: ConversationItemData[]) => void]}
5254
*/
@@ -73,6 +75,10 @@ function ConversationCard(props) {
7375
)
7476
const config = useConfig()
7577

78+
useEffect(() => {
79+
setCompleteDraggable(!isSafari() && !isFirefox() && !isMobile())
80+
}, [])
81+
7682
useEffect(() => {
7783
if (props.onUpdate) props.onUpdate(port, session, conversationItemData)
7884
}, [session, conversationItemData])
@@ -218,10 +224,18 @@ function ConversationCard(props) {
218224
return (
219225
<div className="gpt-inner">
220226
<div
221-
className={props.draggable ? 'gpt-header draggable' : 'gpt-header'}
222-
style="padding:15px;user-select:none;"
227+
className={
228+
props.draggable ? `gpt-header${completeDraggable ? ' draggable' : ''}` : 'gpt-header'
229+
}
230+
style="user-select:none;"
223231
>
224-
<span className="gpt-util-group" style={props.notClampSize ? {} : { flexGrow: 1 }}>
232+
<span
233+
className="gpt-util-group"
234+
style={{
235+
padding: '15px 0 15px 15px',
236+
...(props.notClampSize ? {} : { flexGrow: 1 }),
237+
}}
238+
>
225239
{props.closeable ? (
226240
<XLg
227241
className="gpt-util-icon"
@@ -278,7 +292,17 @@ function ConversationCard(props) {
278292
})}
279293
</select>
280294
</span>
281-
<span className="gpt-util-group" style={{ flexGrow: 1, justifyContent: 'flex-end' }}>
295+
{props.draggable && !completeDraggable && (
296+
<div className="draggable" style={{ flexGrow: 2, cursor: 'move', height: '55px' }} />
297+
)}
298+
<span
299+
className="gpt-util-group"
300+
style={{
301+
padding: '15px 15px 15px 0',
302+
justifyContent: 'flex-end',
303+
flexGrow: props.draggable && !completeDraggable ? 0 : 1,
304+
}}
305+
>
282306
{!config.disableWebModeHistory && session && session.conversationId && (
283307
<a
284308
title={t('Continue on official website')}

src/components/InputBox/index.jsx

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { useEffect, useRef, useState } from 'react'
22
import PropTypes from 'prop-types'
3-
import { updateRefHeight } from '../../utils'
3+
import { isFirefox, isMobile, isSafari, updateRefHeight } from '../../utils'
44
import { useTranslation } from 'react-i18next'
55
import { getUserConfig } from '../../config/index.mjs'
66

@@ -10,8 +10,15 @@ export function InputBox({ onSubmit, enabled, port, reverseResizeDir }) {
1010
const reverseDivRef = useRef(null)
1111
const inputRef = useRef(null)
1212
const resizedRef = useRef(false)
13+
const [internalReverseResizeDir, setInternalReverseResizeDir] = useState(reverseResizeDir)
1314

14-
const virtualInputRef = reverseResizeDir ? reverseDivRef : inputRef
15+
useEffect(() => {
16+
setInternalReverseResizeDir(
17+
!isSafari() && !isFirefox() && !isMobile() ? internalReverseResizeDir : false,
18+
)
19+
}, [])
20+
21+
const virtualInputRef = internalReverseResizeDir ? reverseDivRef : inputRef
1522

1623
useEffect(() => {
1724
inputRef.current.focus()
@@ -31,7 +38,7 @@ export function InputBox({ onSubmit, enabled, port, reverseResizeDir }) {
3138

3239
useEffect(() => {
3340
if (!resizedRef.current) {
34-
if (!reverseResizeDir) {
41+
if (!internalReverseResizeDir) {
3542
updateRefHeight(inputRef)
3643
virtualInputRef.current.h = virtualInputRef.current.offsetHeight
3744
virtualInputRef.current.style.maxHeight = '160px'
@@ -65,7 +72,7 @@ export function InputBox({ onSubmit, enabled, port, reverseResizeDir }) {
6572
<div
6673
ref={reverseDivRef}
6774
style={
68-
reverseResizeDir && {
75+
internalReverseResizeDir && {
6976
transform: 'rotateX(180deg)',
7077
resize: 'vertical',
7178
overflow: 'hidden',
@@ -79,7 +86,7 @@ export function InputBox({ onSubmit, enabled, port, reverseResizeDir }) {
7986
disabled={false}
8087
className="interact-input"
8188
style={
82-
reverseResizeDir
89+
internalReverseResizeDir
8390
? { transform: 'rotateX(180deg)', resize: 'none' }
8491
: { resize: 'vertical', minHeight: '70px' }
8592
}

0 commit comments

Comments
 (0)