Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[UX] Wait until winetricks lists before allowing the user to search #4226

Merged
merged 1 commit into from
Jan 2, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions public/locales/en/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -919,6 +919,8 @@
"installed": "Installed components:",
"installing": "Installation in progress: {{component}}",
"loading": "Loading",
"loading-available": "Loading available components ...",
"no-components": "No available components",
"nothingYet": "Nothing was installed by Winetricks yet",
"openGUI": "Open Winetricks GUI",
"search": "Search fonts or components"
Expand Down
33 changes: 25 additions & 8 deletions src/frontend/components/UI/Winetricks/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,13 @@ export default function Winetricks({ onClose, runner }: Props) {
const { appName } = useContext(SettingsContext)
const { t } = useTranslation()

const [loading, setLoading] = useState(true)
const [loadingInstalled, setLoadingInstalled] = useState(true)
const [loadingAvailable, setLoadingAvailable] = useState(true)

// keep track of all installed components for a game/app
const [installed, setInstalled] = useState<string[]>([])
async function listInstalled() {
setLoading(true)
setLoadingInstalled(true)
try {
const components = await window.api.winetricksListInstalled(
runner,
Expand All @@ -30,7 +31,7 @@ export default function Winetricks({ onClose, runner }: Props) {
} catch {
setInstalled([])
}
setLoading(false)
setLoadingInstalled(false)
}
useEffect(() => {
listInstalled()
Expand All @@ -39,6 +40,7 @@ export default function Winetricks({ onClose, runner }: Props) {
const [allComponents, setAllComponents] = useState<string[]>([])
useEffect(() => {
async function listComponents() {
setLoadingAvailable(true)
try {
const components = await window.api.winetricksListAvailable(
runner,
Expand All @@ -48,7 +50,9 @@ export default function Winetricks({ onClose, runner }: Props) {
} catch {
setAllComponents([])
}
setLoadingAvailable(false)
}

listComponents()
}, [])

Expand Down Expand Up @@ -108,9 +112,9 @@ export default function Winetricks({ onClose, runner }: Props) {

const dialogContent = (
<>
{!loading && (
{!loadingInstalled && (
<div className="installWrapper">
{!installing && (
{!installing && allComponents.length !== 0 && (
<div className="actions">
<WinetricksSearchBar
allComponents={allComponents}
Expand All @@ -126,6 +130,19 @@ export default function Winetricks({ onClose, runner }: Props) {
</button>
</div>
)}
{loadingAvailable && (
<span>
{t(
'winetricks.loading-available',
'Loading available components ...'
)}
</span>
)}
{!loadingAvailable && allComponents.length === 0 && (
<span>
{t('winetricks.no-components', 'No available components')}
</span>
)}
{installing && (
<p>
{t(
Expand All @@ -140,16 +157,16 @@ export default function Winetricks({ onClose, runner }: Props) {

<div className="installedWrapper">
<b>{t('winetricks.installed', 'Installed components:')}</b>
{loading && <span>{t('winetricks.loading', 'Loading')}</span>}
{!loading && installed.length === 0 && (
{loadingInstalled && <span>{t('winetricks.loading', 'Loading')}</span>}
{!loadingInstalled && installed.length === 0 && (
<span>
{t(
'winetricks.nothingYet',
'Nothing was installed by Winetricks yet'
)}
</span>
)}
{!loading && <span>{installed.join(', ')}</span>}
{!loadingInstalled && <span>{installed.join(', ')}</span>}
</div>
</>
)
Expand Down
Loading