Skip to content

Commit

Permalink
better loader response
Browse files Browse the repository at this point in the history
  • Loading branch information
andreiggr committed Jan 12, 2023
1 parent 48219a3 commit d6f3c86
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 14 deletions.
22 changes: 9 additions & 13 deletions src/Tableau/View.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { toast } from 'react-toastify';
import { Toast } from '@plone/volto/components';
import { setTableauApi } from '@eeacms/volto-tableau/actions';
import cx from 'classnames';
import { isMyScriptLoaded, loadTableauScript } from '../helpers';
import { loadTableauScript } from '../helpers';

const Tableau = (props) => {
const ref = React.useRef(null);
Expand Down Expand Up @@ -35,20 +35,8 @@ const Tableau = (props) => {
const defaultUrl = data.url;
const url = props.url || defaultUrl;

const setTableauScript = (version) => {
switch (version) {
case '2.8.0':
console.log('Loading Tableau 2.8.0');
//import { tableau as tableau280 } from "tableau280"; && return tableau280
break;
default:
console.log(`Sorry, we don't support ${version} yet.`);
}
};

//load tableau from script tag
const tableau = loadTableauScript(() => {}, version);
//TODO: if using an importmap then there would be tableau1, tableau2, etc and ^^ would need a switch for each version. This way, the scripts needed are there, loaded dinamicaly

const onFilterChange = (filter) => {
const newFilters = { ...filters.current };
Expand Down Expand Up @@ -198,6 +186,7 @@ const Tableau = (props) => {
tableau,
toolbarPosition,
url,
version,
]);

React.useEffect(() => {
Expand All @@ -217,6 +206,13 @@ const Tableau = (props) => {
return (
<div id="tableau-wrap">
<div id="tableau-outer">
{loaded ? (
''
) : (
<div className="tableau-loader">
<span>Loading Tableau v{version}</span>
</div>
)}
<div
className={cx('tableau', version, {
'tableau-scale': autoScale,
Expand Down
1 change: 0 additions & 1 deletion src/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ const loadTableauScript = (callback, version) => {
if (existingScript && callback) callback();

const tableau = isMyScriptLoaded(version) && __CLIENT__ ? window.tableau : '';
console.log('loading the tableau script version:', version);
return tableau;
};

Expand Down
39 changes: 39 additions & 0 deletions src/less/tableau.less
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,43 @@
}
}

.tableau-loader {
margin: auto;
width: 100%;
height: 100%;
display: flex;
justify-content: center;
border-radius: 5px;
align-items: center;
height: 100%;
overflow: hidden;
background-size: 100px 100px;
background-image: linear-gradient(
-45deg,
#5ac5f1 25%,
#96bbde 25%,
#96bbde 50%,
#5ac5f1 50%,
#5ac5f1 75%,
#96bbde 75%
);
animation: anim 1s linear infinite;
}

.tableau-loader span {
margin: 6px auto;
text-align: center;
color: white;
font-weight: bold;
}

@keyframes anim {
0% {
background-position: 0 0;
}
100% {
background-position: 50px 50px;
}
}

.loadAddonOverrides();

0 comments on commit d6f3c86

Please sign in to comment.