Skip to content

Commit

Permalink
fix(web): synchronize the selected product (#1334)
Browse files Browse the repository at this point in the history
* The product context offers a function to select the product.
* The product is synchronized right after being selected.
* It prevents a wrong redirection to the product selection page.
  • Loading branch information
imobachgs authored Jun 14, 2024
2 parents f9c0c0d + 5c955c3 commit c045775
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 7 deletions.
6 changes: 6 additions & 0 deletions web/package/agama-web-ui.changes
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
-------------------------------------------------------------------
Fri Jun 14 05:34:52 UTC 2024 - Imobach Gonzalez Sosa <[email protected]>

- Do not redirect to the products selection page again after
selecting a product (gh#openSUSE/agama#1334).

-------------------------------------------------------------------
Thu Jun 13 10:52:22 UTC 2024 - David Diaz <[email protected]>

Expand Down
8 changes: 2 additions & 6 deletions web/src/components/product/ProductSelectionPage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ import styles from '@patternfly/react-styles/css/utilities/Text/text';
import { _ } from "~/i18n";
import { Page } from "~/components/core";
import { Loading, Center } from "~/components/layout";
import { useInstallerClient } from "~/context/installer";
import { useProduct } from "~/context/product";

const Label = ({ children }) => (
Expand All @@ -44,17 +43,14 @@ const Label = ({ children }) => (

function ProductSelectionPage() {
const navigate = useNavigate();
const { manager, product } = useInstallerClient();
const { products, selectedProduct } = useProduct();
const { products, selectedProduct, selectProduct } = useProduct();
const [nextProduct, setNextProduct] = useState(selectedProduct);

const onSubmit = async (e) => {
e.preventDefault();

if (nextProduct) {
// TODO: handle errors
await product.select(nextProduct.id);
manager.startProbing();
await selectProduct(nextProduct.id);
}

navigate("/");
Expand Down
8 changes: 7 additions & 1 deletion web/src/context/product.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,13 @@ function ProductProvider({ children }) {
return client.product.onRegistrationChange(setRegistration);
}, [client, setRegistration]);

const value = { products, selectedId, registration };
const selectProduct = async (id) => {
await client.product.select(id);
client.manager.startProbing();
setSelectedId(id);
};

const value = { products, selectedId, registration, selectProduct };
return <ProductContext.Provider value={value}>{children}</ProductContext.Provider>;
}

Expand Down

0 comments on commit c045775

Please sign in to comment.