Skip to content

Commit

Permalink
add spinner logic to be hidden by default
Browse files Browse the repository at this point in the history
  • Loading branch information
horeaporutiu committed Sep 20, 2023
1 parent 17ca2d6 commit eba4909
Showing 1 changed file with 17 additions and 14 deletions.
31 changes: 17 additions & 14 deletions examples/ai-image-generator/pages/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,18 @@ export const getServerSideProps = async function getServerSideProps({ req }) {
};

export default function Main({ authUrl }) {
// Shows spinner while API calls are in progress / image is being dragged & dropped
const showSpinner = () => {
const spinner = document.getElementById("spinner");
spinner.style.visibility = "visible";
};

// Removes spinner when API calls are finished and data is returned / image has been dropped
const removeSpinner = () => {
const spinner = document.getElementById("spinner");
spinner.style.visibility = "hidden";
};
useEffect(() => {
removeSpinner();
// Opens the panel for our app UI when we click on icon in the left sidebar
if (new URLSearchParams(window.location.search).has("panel")) return;
window.miro.board.ui.on("icon:click", async () => {
Expand Down Expand Up @@ -58,18 +68,6 @@ export default function Main({ authUrl }) {
setInputValue(newValue);
};

// Shows spinner while API calls are in progress / image is being dragged & dropped
const showSpinner = () => {
const spinner = document.getElementById("spinner");
spinner.style.visibility = "visible";
};

// Removes spinner when API calls are finished and data is returned / image has been dropped
const removeSpinner = () => {
const spinner = document.getElementById("spinner");
spinner.style.visibility = "hidden";
};

const handleButtonClick = async () => {
//setting the image source to be a transparent color, otherwise we have a border which looks bad
document.querySelector("#image").src =
Expand Down Expand Up @@ -128,7 +126,12 @@ export default function Main({ authUrl }) {
id="generateImgBtn"
/>

<div className="spinner" id="spinner"></div>
{/* Spinner needs to be hidden by default, otherwise will spin when opening app first time */}
<div
className="spinner"
id="spinner"
style={{ visibility: "hidden" }}
></div>
<div className="image-container">
{/* Img which needs to be draggable */}
<img
Expand Down

0 comments on commit eba4909

Please sign in to comment.