mirror of
https://github.com/ToolJet/ToolJet
synced 2026-05-24 09:28:31 +00:00
added lazyload to template model images (#1847)
This commit is contained in:
parent
efca1f32ba
commit
cffb3a0882
3 changed files with 22 additions and 15 deletions
|
|
@ -1,4 +1,4 @@
|
||||||
import React, { useCallback } from 'react'
|
import React, { useCallback } from 'react';
|
||||||
import { SearchBox } from '@/_components/SearchBox';
|
import { SearchBox } from '@/_components/SearchBox';
|
||||||
import { Button, ButtonGroup, Dropdown } from 'react-bootstrap';
|
import { Button, ButtonGroup, Dropdown } from 'react-bootstrap';
|
||||||
import { debounce } from 'lodash';
|
import { debounce } from 'lodash';
|
||||||
|
|
@ -14,9 +14,7 @@ export default function Header({
|
||||||
showTemplateLibraryModal,
|
showTemplateLibraryModal,
|
||||||
fileInput,
|
fileInput,
|
||||||
}) {
|
}) {
|
||||||
const debouncedChangeHandler = useCallback(
|
const debouncedChangeHandler = useCallback(debounce(onSearchSubmit, 300), []);
|
||||||
debounce(onSearchSubmit, 300)
|
|
||||||
, []);
|
|
||||||
return (
|
return (
|
||||||
<div className="row">
|
<div className="row">
|
||||||
<div className="col-4">
|
<div className="col-4">
|
||||||
|
|
|
||||||
|
|
@ -1,12 +1,21 @@
|
||||||
import React from 'react';
|
import React, { useEffect, useRef, useState } from 'react';
|
||||||
import { Container, Row, Badge } from 'react-bootstrap';
|
import { Container, Row, Badge } from 'react-bootstrap';
|
||||||
|
import LazyLoad from 'react-lazyload';
|
||||||
import { getSvgIcon } from '@/_helpers/appUtils';
|
import { getSvgIcon } from '@/_helpers/appUtils';
|
||||||
|
|
||||||
export default function TemplateDisplay(props) {
|
export default function TemplateDisplay(props) {
|
||||||
const { id, name, description, sources } = props?.app ?? {};
|
const { id, name, description, sources } = props?.app ?? {};
|
||||||
|
const componentRef = useRef(null);
|
||||||
|
const [isloaded, setLoaded] = useState(false);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (componentRef.current) {
|
||||||
|
setLoaded(true);
|
||||||
|
}
|
||||||
|
}, [componentRef]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="template-display">
|
<div className="template-display" ref={componentRef}>
|
||||||
<Container fluid className="pt-2">
|
<Container fluid className="pt-2">
|
||||||
<Row style={{ height: '10%' }}>
|
<Row style={{ height: '10%' }}>
|
||||||
<h3 className="title">{name}</h3>
|
<h3 className="title">{name}</h3>
|
||||||
|
|
@ -40,7 +49,14 @@ export default function TemplateDisplay(props) {
|
||||||
</span>
|
</span>
|
||||||
</Row>
|
</Row>
|
||||||
<Row className="align-items-center justify-content-center" style={{ height: '88%' }}>
|
<Row className="align-items-center justify-content-center" style={{ height: '88%' }}>
|
||||||
<img className="template-image" src={`/assets/images/templates/${id}${props.darkMode ? '-dark' : ''}.png`} />
|
{isloaded && (
|
||||||
|
<LazyLoad>
|
||||||
|
<img
|
||||||
|
className="template-image"
|
||||||
|
src={`/assets/images/templates/${id}${props.darkMode ? '-dark' : ''}.png`}
|
||||||
|
/>
|
||||||
|
</LazyLoad>
|
||||||
|
)}
|
||||||
</Row>
|
</Row>
|
||||||
</Container>
|
</Container>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,6 @@ export function SearchBox({ onSubmit }) {
|
||||||
const handleChange = (e) => {
|
const handleChange = (e) => {
|
||||||
setSearchText(e.target.value);
|
setSearchText(e.target.value);
|
||||||
onSubmit(e.target.value);
|
onSubmit(e.target.value);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|
@ -31,13 +30,7 @@ export function SearchBox({ onSubmit }) {
|
||||||
<line x1="21" y1="21" x2="15" y2="15" />
|
<line x1="21" y1="21" x2="15" y2="15" />
|
||||||
</svg>
|
</svg>
|
||||||
</span>
|
</span>
|
||||||
<input
|
<input type="text" value={searchText} onChange={handleChange} className="form-control" placeholder="Search" />
|
||||||
type="text"
|
|
||||||
value={searchText}
|
|
||||||
onChange={handleChange}
|
|
||||||
className="form-control"
|
|
||||||
placeholder="Search"
|
|
||||||
/>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue