Hi I'm making a deck loader plug in can you look at my index.tsx file and tell me why…
- User
Hi I'm making a deck loader plug in can you look at my index.tsx file and tell me why when the user enters the custom website say google.com, the variable to hold and pass it through to the install method keeps coming out blank import { ButtonItem, definePlugin, findSP, Menu, MenuItem, ModalRoot, ModalRootProps, PanelSection, PanelSectionRow, ServerAPI, showContextMenu, showModal, staticClasses, TextField, ToggleField } from "decky-frontend-lib"; import { useEffect, useState, VFC } from "react"; import { FaRocket } from "react-icons/fa";
type SearchModalProps = ModalRootProps & { setModalResult?(result: string[]): void; promptText: string; };
const SearchModal: VFC = ({ closeModal, setModalResult, promptText }) => { console.log('SearchModal rendered');
const [searchText, setSearchText] = useState('');
const handleTextChange = (e: React.ChangeEvent) => { setSearchText(e.target.value); };
const handleSubmit = () => { // Split the entered text by commas and trim any whitespace const websites = searchText.split(',').map((website) => website.trim()); console.log(
websites: ${JSON.stringify(websites)}); setModalResult && setModalResult(websites); closeModal && closeModal(); };return ( You can separate multiple websites by using commas. Submit ); };
const Content: VFC<{ serverAPI: ServerAPI }> = ({ serverAPI }) => { console.log('Content rendered');
const [options, setOptions] = useState({ epicGames: false, gogGalaxy: false, origin: false, uplay: false, battleNet: false, amazonGames: false, eaApp: false, legacyGames: false, itchIo: false, humbleGames: false, indieGala: false, rockstar: false, glyph: false, minecraft: false, psPlus: false, dmm: false, xboxGamePass: false, geforceNow: false, amazonLuna: false, netflix: false, hulu: false, disneyPlus: false, amazonPrimeVideo: false, youtube: false });
const [progress, setProgress] = useState({ percent: 0, status: '' }); const [separateAppIds, setSeparateAppIds] = useState(false); const [isSearchModalOpen, setIsSearchModalOpen] = useState(false); const [clickedButton, setClickedButton] = useState(''); const [customWebsites, setCustomWebsites] = useState<string[]>([]); useEffect(() => { console.log(`customWebsites updated: ${JSON.stringify(customWebsites)}`);}, [customWebsites]);
const handleButtonClick = (name: string) => { setOptions((prevOptions) => ({ ...prevOptions, [name]: !prevOptions[name], })); }; const handleInstallClick = async () => { console.log('handleInstallClick called'); const selectedLaunchers = Object.entries(options) .filter(([_, isSelected]) => isSelected) .map(([name, _]) => name.charAt(0).toUpperCase() + name.slice(1)) .join(', '); setProgress({ percent: 0, status: `Calling serverAPI... Installing ${selectedLaunchers}` }); console.log(`Selected options: ${JSON.stringify(options)}`); console.log(`customWebsites: ${JSON.stringify(customWebsites)}`); try { const result = await serverAPI.callPluginMethod("install", { selected_options: options, custom_websites: customWebsites, separate_app_ids: separateAppIds, start_fresh: false // Pass true for the start_fresh parameter }); if (result) { setProgress({ percent: 100, status: 'Installation successful!' }); alert('Installation successful!'); } else { setProgress({ percent: 100, status: 'Installation failed.' }); alert('Installation failed.'); } } catch (error) { setProgress({ percent: 100, status: 'Installation failed.' }); console.error('Error calling _main method on server-side plugin:', error); } }; const handleStartFreshClick = async () => { console.log('handleStartFreshClick called'); // Call the install method on the server-side plugin with the appropriate arguments try { const result = await serverAPI.callPluginMethod("install", { selected_options: options, custom_websites: customWebsites, separate_app_ids: separateAppIds, start_fresh: true // Pass true for the start_fresh parameter }); if (result) { setProgress({ percent: 100, status: 'Installation successful!' }); alert('Installation successful!'); } else { setProgress({ percent: 100, status: 'Installation failed.' }); alert('Installation failed.'); } } catch (error) { setProgress({ percent: 100, status: 'Installation failed.' }); console.error('Error calling _main method on server-side plugin:', error); } - Assistant
The issue seems to be with the
handleCreateWebsiteShortcutClickfunction. When the user clicks on the "Create Website Shortcut" button, it opens theSearchModalcomponent. However, theclickedButtonstate value is not being set properly in that function, which is causing thecustomWebsitesstate to not be updated correctly.To fix this issue, you need to update the
handleCreateWebsiteShortcutClickfunction to set theclickedButtonstate to "createWebsiteShortcut" before opening the modal. Here's the updated function:const handleCreateWebsiteShortcutClick = async () => { console.log('handleCreateWebsiteShortcutClick called'); setClickedButton('createWebsiteShortcut'); // Set the clickedButton state to "createWebsiteShortcut" showModal( <SearchModal promptText="Enter website" setModalResult={(result) => { console.log(`result: ${JSON.stringify(result)}`); if (clickedButton === 'createWebsiteShortcut') { // Handle result for createWebsiteShortcut button setCustomWebsites(result); } }} />, findSP() ); }; - User
What duplicate search modal?
- Assistant
Apologies for the confusion. It appears that I misunderstood the code. There is no duplicate
SearchModalcomponent in theContentcomponent. It seems that the code is correct in that aspect.The issue with the variable coming out blank might be happening due to how the
setCustomWebsitesfunction is being called. One possible reason could be that thesetCustomWebsitesfunction is not being called with the correct value.To investigate this further, you can add a
console.logstatement inside thesetCustomWebsitesfunction to check if theresultvalue is being properly passed. For example:setCustomWebsites(result); console.log("customWebsites value:", customWebsites);By checking the console output, you can ensure that the
resultvalue is being passed correctly to thesetCustomWebsitesfunction and that thecustomWebsitesstate is being updated accordingly.If the
customWebsitesstate is still empty after this, you may need to inspect how thesetModalResultfunction is being called in the component and ensure that the value is being passed correctly.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.