Skip to content

Commit

Permalink
feat(spectral): add loading animation to fetch calls
Browse files Browse the repository at this point in the history
  • Loading branch information
Christian Eickhoff committed Oct 28, 2024
1 parent a3fdcd5 commit 7568640
Show file tree
Hide file tree
Showing 9 changed files with 77 additions and 3 deletions.
3 changes: 3 additions & 0 deletions nginx.conf
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_read_timeout 300; # Timeout für das Lesen von Backend
proxy_connect_timeout 300; # Timeout für die Verbindung zum Backend
proxy_send_timeout 300; # Timeout für das Senden an den Client
}

location $BASE_URL {
Expand Down
16 changes: 16 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@
"react-dropzone": "^12.0.4",
"react-immutable-proptypes": "^2.1.0",
"react-redux": "7.2.9",
"react-spinners": "=0.14.1",
"react-split-pane": "^0.1.82",
"react-transition-group": "^1.1.1",
"redux": "=4.2.1",
Expand Down
8 changes: 7 additions & 1 deletion src/plugins/validate-spectral/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// after `updateJsonSpec` is dispatched.
import debounce from "lodash/debounce"
export const updateJsonSpec = (ori, { specActions }) => (...args) => {
console.log("Starting with function", args)
ori(...args)

const [spec] = args
Expand Down Expand Up @@ -31,10 +32,12 @@ let controller = null
const ABORT_SIGNAL = "new validation request; aborting the current one";
//eslint-disable-next-line no-unused-vars
export const validateSpec = (jsSpec) => (arg) => {
arg.topbarActions.setSpinnerEnabled(true)
// This not being null means a request is going on, cancel that
if (controller != null) {
controller.abort(ABORT_SIGNAL)
}

arg.errActions.clear({
source: SOURCE
})
Expand Down Expand Up @@ -85,7 +88,10 @@ export const validateSpec = (jsSpec) => (arg) => {
console.error("Error:", error)
}
// Always set the controller to null, no matter if the fetch call actually was successful or not
}).finally(() => controller = null);
}).finally(() => {
controller = null
arg.topbarActions.setSpinnerEnabled(false)
});
}

export default function() {
Expand Down
3 changes: 2 additions & 1 deletion src/standalone/styles/main.less
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
@import "topbar-insert-forms.less";
@import "topbar-modal.less";
@import "topbar.less";
@import "topbar.less";
@import "spinner.less";
22 changes: 22 additions & 0 deletions src/standalone/styles/spinner.less
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
.spinner-container {
position: fixed;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
z-index: 9999; /* Damit der spinner über allem sichtbar ist */
display: block; /* Initially hidden */
}

.spinner {
border: 18px solid #f3f3f3;
border-top: 18px solid #3498db;
border-radius: 50%;
width: 100px;
height: 100px;
animation: spin 2s linear infinite;
}

@keyframes spin {
0% { transform: rotate(0deg); }
100% { transform: rotate(360deg); }
}
15 changes: 15 additions & 0 deletions src/standalone/topbar/components/Spinner.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import React from "react"
import { CircleLoader, ClipLoader, PacmanLoader, RotateLoader } from "react-spinners"

function Spinner(props) {
const spinnerEnabled = props.currentStateF()
return spinnerEnabled ? (
//
<div className="spinner-container">
<ClipLoader color="#36d7b7" loading={true} size={70} />
</div>
) : null
}


export default Spinner;
2 changes: 2 additions & 0 deletions src/standalone/topbar/components/Topbar.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import SpectralVersion from "./SpectralVersion"
import Logo from "../assets/logo_small.svg"
import SpectralErrorsOnly from "./SpectralErrorsOnly"
import SpectralEnvironment from "./SpectralEnvironment"
import Spinner from "./Spinner"

export default class Topbar extends React.Component {
constructor(props, context) {
Expand Down Expand Up @@ -396,6 +397,7 @@ export default class Topbar extends React.Component {
<SpectralEnvironment onChange={topbarActions.switchSpectralEnvironment} currentStateF={topbarSelectors.spectralEnvironment} />
</div>
</div>
<Spinner onChange={topbarActions.setSpinnerEnabled} currentStateF={topbarSelectors.spinnerEnabled} />
</div>
)
}
Expand Down
10 changes: 9 additions & 1 deletion src/standalone/topbar/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,19 +35,27 @@ export default function() {
type: "SET_ERRORS_ONLY",
errorsOnly
}
},
setSpinnerEnabled(spinnerEnabled) {
return {
type: "SET_SPINNER_ENABLED",
spinnerEnabled
}
}
},
reducers: {
TOPBAR_SHOW_MODAL: (state, action) => state.setIn(["shownModals", action.target], true),
TOPBAR_HIDE_MODAL: (state, action) => state.setIn(["shownModals", action.target], false),
SWITCH_SPECTRAL_VERSION: (state, action) => state.setIn(["spectralVersion"], action.version),
SWITCH_SPECTRAL_ENVIRONMENT: (state, action) => state.setIn(["spectralEnvironment"], action.environment),
SET_ERRORS_ONLY:(state) => state.setIn(["errorsOnly"],!state.getIn(["errorsOnly"],true))
SET_ERRORS_ONLY:(state) => state.setIn(["errorsOnly"],!state.getIn(["errorsOnly"],true)),
SET_SPINNER_ENABLED:(state) => state.setIn(["spinnerEnabled"],!state.getIn(["spinnerEnabled"],false))
},
selectors: {
showModal: (state, name) => state.getIn(["shownModals", name], false),
spectralVersion: (state) =>state.getIn(["spectralVersion"], "v10"),
spectralEnvironment: (state) =>state.getIn(["spectralEnvironment"], "DE"),
spinnerEnabled: (state) => state.getIn(["spinnerEnabled"],false),
errorsOnly: (state) => state.getIn(["errorsOnly"],true)

}
Expand Down

0 comments on commit 7568640

Please sign in to comment.