@@ -15,6 +15,7 @@ import CustomKeyboard from "../../components/keypad/index.js";
1515import BalanceView from "../../components/balanceView/index.js" ;
1616import displayCorrectDenomination from "../../functions/displayCorrectDenomination.js" ;
1717import { formatBalanceAmount } from "../../functions/formatNumber.js" ;
18+ import ItemsList from "../../components/itemsList/index.js" ;
1819function POSPage ( ) {
1920 const User = getCurrentUser ( ) ;
2021 const {
@@ -33,6 +34,8 @@ function POSPage() {
3334 errorScreen : false ,
3435 serverName : false ,
3536 } ) ;
37+ const [ activeInput , setActiveInput ] = useState ( "keypad" ) ;
38+ const [ inputTextWidths , setInputTextWidths ] = useState ( [ ] ) ;
3639 const [ hasError , setHasError ] = useState ( "" ) ;
3740 const [ addedItems , setAddedItems ] = useState ( [ ] ) ;
3841 const didInitialRender = useRef ( true ) ;
@@ -129,6 +132,37 @@ function POSPage() {
129132 } ) ;
130133 } , [ currentUserSession ] ) ;
131134
135+ useEffect ( ( ) => {
136+ // Loading widths for inut text elemtns to use for slider
137+ setTimeout (
138+ ( ) => {
139+ const sliderTexts = document . querySelectorAll ( ".inputText" ) ;
140+ const widths = Array . from ( sliderTexts ) . map ( ( item ) => {
141+ return item . getBoundingClientRect ( ) . width ;
142+ } ) ;
143+ setInputTextWidths ( widths ) ;
144+ } ,
145+ currentUserSession ?. account ? 0 : 500
146+ ) ;
147+ } , [ currentUserSession ] ) ;
148+
149+ const handleSlider = ( event ) => {
150+ const targetElement = event . target ;
151+
152+ if ( ! Array . from ( targetElement . classList ) . includes ( "inputText" ) ) return ;
153+ const children = targetElement . parentElement . children ;
154+ const element = targetElement . innerHTML ;
155+
156+ Array . from ( children ) . forEach ( ( child ) => {
157+ child . classList . remove ( "active" ) ;
158+ if ( child . innerHTML === element ) {
159+ child . classList . add ( "active" ) ;
160+ }
161+ } ) ;
162+
163+ setActiveInput ( element . toLowerCase ( ) ) ;
164+ } ;
165+
132166 return (
133167 < div className = "POS-Container" >
134168 < PosNavbar
@@ -197,7 +231,6 @@ function POSPage() {
197231 } }
198232 balance = { chargeAmount }
199233 />
200-
201234 < p className = "POS-AmountError" >
202235 { convertedSatAmount > 1000
203236 ? "\u00A0"
@@ -214,7 +247,32 @@ function POSPage() {
214247 ) } `}
215248 </ p >
216249
217- < CustomKeyboard customFunction = { addNumToBalance } />
250+ < div className = "POS-savedItemsContainer" onClick = { handleSlider } >
251+ < p className = "active inputText" > Keypad</ p >
252+ < p className = "inputText" > Library</ p >
253+ < div
254+ style = { {
255+ width : inputTextWidths [ activeInput === "keypad" ? 0 : 1 ] ,
256+ left :
257+ activeInput === "keypad"
258+ ? 0
259+ : `calc(100% - ${ inputTextWidths [ 1 ] } px)` ,
260+ } }
261+ className = "selectedInputBar"
262+ />
263+ </ div >
264+
265+ { activeInput === "keypad" ? (
266+ < CustomKeyboard customFunction = { addNumToBalance } />
267+ ) : (
268+ < ItemsList
269+ dollarSatValue = { dollarSatValue }
270+ currentSettings = { currentSettings }
271+ currentUserSession = { currentUserSession }
272+ setAddedItems = { setAddedItems }
273+ listElements = { currentUserSession . account ?. items }
274+ />
275+ ) }
218276
219277 < button
220278 onClick = { handleInvoice }
0 commit comments