Skip to content

Commit b92bf21

Browse files
authored
Update to attempt to work with mobile (#498)
* Update to attempt to work with mobile * Update.
1 parent dd426e0 commit b92bf21

File tree

4 files changed

+90
-10
lines changed

4 files changed

+90
-10
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import React, { useState } from 'react';
2+
3+
export default function TradeCTA({ onClick, disabled }) {
4+
const [isSelected, setIsSelected] = useState(false);
5+
const initialButtonStyle = "bg-custom-gray-light";
6+
const selectedButtonStyle = "bg-neutral-btn";
7+
const buttonBaseStyle = "w-full px-4 py-2 text-white border rounded focus:outline-none";
8+
9+
const handleClick = () => {
10+
setIsSelected(!isSelected);
11+
onClick && onClick();
12+
};
13+
14+
return (
15+
<div
16+
className="md:hidden fixed inset-x-0 bottom-0 z-40 bg-primary-background/90 backdrop-blur p-3"
17+
style={{ paddingBottom: 'calc(env(safe-area-inset-bottom) + 80px)' }}
18+
data-testid="mobile-trade-cta"
19+
>
20+
<button
21+
type="button"
22+
onClick={handleClick}
23+
disabled={disabled}
24+
className={`${buttonBaseStyle} ${isSelected ? selectedButtonStyle : initialButtonStyle} min-w-32 text-xs sm:text-sm md:text-base disabled:opacity-50`}
25+
>
26+
TRADE
27+
</button>
28+
</div>
29+
);
30+
}

frontend/src/components/marketDetails/MarketDetailsLayout.jsx

Lines changed: 44 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ import MarketChart from '../charts/MarketChart';
44
import ActivityTabs from '../../components/tabs/ActivityTabs';
55
import ResolveModalButton from '../modals/resolution/ResolveModal';
66
import BetModalButton from '../modals/bet/BetModal';
7+
import TradeCTA from '../TradeCTA';
8+
import TradeTabs from '../../components/tabs/TradeTabs';
9+
import { BetButton } from '../buttons/trade/BetButtons';
710
import formatResolutionDate from '../../helpers/formatResolutionDate';
811

912
function MarketDetailsTable({
@@ -21,6 +24,18 @@ function MarketDetailsTable({
2124
refetchData,
2225
}) {
2326
const [showFullDescription, setShowFullDescription] = useState(false);
27+
const [showBetModal, setShowBetModal] = useState(false);
28+
29+
const toggleBetModal = () => setShowBetModal(prev => !prev);
30+
31+
const handleTransactionSuccess = () => {
32+
setShowBetModal(false); // Close modal
33+
if (refetchData) {
34+
refetchData(); // Trigger data refresh
35+
}
36+
};
37+
38+
const shouldShowTradeButtons = !market.isResolved && isLoggedIn && new Date(market.resolutionDateTime) > new Date();
2439

2540
return (
2641
<div className='bg-gray-900 text-gray-300 p-4 rounded-lg shadow-lg w-full'>
@@ -144,20 +159,40 @@ function MarketDetailsTable({
144159
className='text-xs px-4 py-2'
145160
/>
146161
)}
147-
{!market.isResolved && isLoggedIn && new Date(market.resolutionDateTime) > new Date() && (
148-
<BetModalButton
149-
marketId={marketId}
150-
token={token}
151-
disabled={!token}
152-
onTransactionSuccess={refetchData}
153-
className='text-xs px-4 py-2'
154-
/>
162+
{shouldShowTradeButtons && (
163+
<div className="hidden md:block">
164+
<BetButton onClick={toggleBetModal} className="text-xs px-4 py-2" />
165+
</div>
155166
)}
156167
</div>
157168

158-
<div className='mx-auto w-full'>
169+
<div className='mx-auto w-full mb-4'>
159170
<ActivityTabs marketId={marketId} />
160171
</div>
172+
173+
{/* Mobile floating CTA */}
174+
{shouldShowTradeButtons && (
175+
<TradeCTA onClick={toggleBetModal} disabled={!token} />
176+
)}
177+
178+
{/* Spacer so content doesn't sit under the CTA */}
179+
<div className="h-32 md:hidden" />
180+
181+
{/* Shared Trade Modal */}
182+
{showBetModal && (
183+
<div className="fixed inset-0 bg-gray-600 bg-opacity-50 flex justify-center items-center z-50">
184+
<div className="bet-modal relative bg-blue-900 p-6 rounded-lg text-white m-6 mx-auto" style={{ width: '350px' }}>
185+
<TradeTabs
186+
marketId={marketId}
187+
token={token}
188+
onTransactionSuccess={handleTransactionSuccess}
189+
/>
190+
<button onClick={toggleBetModal} className="absolute top-0 right-0 mt-4 mr-4 text-gray-400 hover:text-white">
191+
192+
</button>
193+
</div>
194+
</div>
195+
)}
161196
</div>
162197
);
163198
}

frontend/src/pages/marketDetails/MarketDetails.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ const MarketDetails = () => {
1414
}
1515

1616
return (
17-
<div className='flex flex-col h-full'>
17+
<div className='flex flex-col min-h-screen'>
1818
<div className='flex-grow overflow-y-auto'>
1919
<MarketDetailsTable
2020
market={details.market}

frontend/src/pages/style/Style.jsx

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import LoadingSpinner from '../../components/loaders/LoadingSpinner';
3030
import { SharesBadge } from '../../components/buttons/trade/SellButtons';
3131
import ExpandableText from '../../components/utils/ExpandableText';
3232
import ExpandableLink from '../../components/utils/ExpandableLink';
33+
import TradeCTA from '../../components/TradeCTA';
3334

3435
const Style = () => {
3536
const [isSelected, setIsSelected] = useState(false);
@@ -642,6 +643,20 @@ const Style = () => {
642643
<code>{`import ExpandableLink from '../../components/utils/ExpandableLink';`}</code>
643644
</td>
644645
</tr>
646+
<tr>
647+
<td className='px-6 py-4'>
648+
<div className='flex flex-wrap items-center gap-4'>
649+
<TradeCTA
650+
onClick={() => setIsSelected(!isSelected)}
651+
disabled={false}
652+
/>
653+
</div>
654+
</td>
655+
<td className='px-6 py-4 text-sm text-gray-500'>Mobile Trade CTA</td>
656+
<td className='px-6 py-4 text-sm font-mono text-gray-500'>
657+
<code>{`import TradeCTA from '../../components/TradeCTA';`}</code>
658+
</td>
659+
</tr>
645660
</tbody>
646661
</table>
647662
<table className='min-w-full divide-y divide-gray-200 bg-primary-background'>

0 commit comments

Comments
 (0)