How to hide logo if there is no logo? - reactjs

I am using react-bootstrap Thumbnails to show a bunch of logo.
If there is no logo then I am setting a default logo.
But now I want the default logo also should not show.
So,if I remove the default logo, then I am getting the breakup image.
Here is the code -->
function ExpoCard({
data
}) {
const {logo} = data;
let defaultLogo = 'defaultLogo.png';
const URL = `${CLOUDINARYURL}/${isDisplayPage ? displayImgConfig : imgConfig}/${IMAGE_URL}${logo || defaultLogo}`;
<Thumbnail
src={URL}
alt={name}
onClick={() => setData && setData(data)}
className={cx('expo-card-thumbnail', setData && !isDisplayPage && 'cursor exhibitor-logo-portal-page')}
>
{!hideBoothName && (
<div
className={cx(
boothSize === 'LARGE' || boothSize === 'MEDIUM' ? 'expo-title-large' : 'expo-title-small',
'ex-title-name',
)}
style={{ color: nameColor || '#000000' }}
>
<LinkWithTooltip isText tooltip={name} placement="top">
{name}
</LinkWithTooltip>
</div>
)}
{categoryName && <div className="ex-tag-line">{categoryName}</div>}
<div>
{shortDescription && (
<>
<LinkWithTooltip isText tooltip={shortDescription} placement="top">
<div className="expo-card-desc-container m-t-5">
<div
className={cx(
boothSize === 'LARGE'
? 'expo-card-desc-large'
: boothSize === 'MEDIUM'
? 'expo-card-desc-medium'
: 'expo-card-desc-small',
'expo-card-desc',
)}
style={{ color: shortDescriptionColor || '#000000' }}
>
{shortDescription}
</div>
</div>
</LinkWithTooltip>
</>
)}
</div>
<div className="card-footer">
{isShowAvailability && !isDisplayPage && !disableChat && !isSearching && status && (
<span className={cx('ex-status-label', status)} style={{ position: 'absolute' }}>
{status}
</span>
)}
{!isDisplayPage
? data.sponsorUrl !== '' && (
<a
className="viewExpoBtn"
role="button"
tabIndex="0"
aria-label={name}
onKeyPress={(e) => e.key === 'Enter' && setData && setData(data)}
>
<i className="ac-icon-arrow-right pull-right btn" />
</a>
)
: (data.linkToSite || data.sponsorUrl) && (
<a
className="viewExpoBtn"
role="button"
tabIndex="0"
aria-label={name}
onKeyPress={(e) => e.key === 'Enter' && setData && setData(data)}
>
<i className="ac-icon-arrow-right pull-right btn" />
</a>
)}
</div>
</Thumbnail>
}
I was thinking of creating a class display-none and when there is no logo, Thumbnail should add display-none class but if I do so,everything gets hidden including name.

There are a few options:
Instead of hiding the Thumbnail itself just hide the IMG element inside with CSS child selectors.
You can do something like:
.hide-thumbnail >img{
display:none;
}
Add this hide-thumbnail class to Thumbnail when you don't want a picture to show up.
Set a 0 size picture as the default logo:
You can create an empty picture in paint on Windows and use that as the default picture
Move everything out of Thumbnail into a different Component and show Thumbnail along the new component only when you need it.
Option 1 and 2 are not great but can work as a quick solution.

Related

In react-table I want to apply sorting only on arrow icon not on whole table header

I am new to react-table.Currently,My sorting is working fine,but it is apply in whole header..But i Want to apply it only on arrow.
My code is like this:-
<th
{...headerProps}
{...attributes}
ref={setNodeRef}
style={{...headerProps.style, ...style}}
>
{id !== 'row-drag-handle' && id !== 'expander' && allowColumnReorder && (
<div {...listeners} className='columnDragHandle'>
<DragHandle />
</div>
)}{' '}
<div style={{padding: '0.4em'}}>
{render('Header')}
{canResize && onColumnResize && (
<div {...getResizerProps()} className='resizer' />
)}
{Boolean(onSortChange) && canSort && (
<span>
{isSorted ? (
<Arrow
fill='white'
width='10px'
/>
) : (
''
)}
</span>
)}
</div>
</th>

Radio Button clicked value get the previous clicked value React

I have MUI radio buttons which I use to get filter criteria and I filter an object. Then i render the filtered object in an owl carousal to show. But when I click on a radio button it always takes the previously clicked value of the radio button. I have used ternary conditions to check but it keeps happening I couldb't figure out following is my code.
<FormControl>
<RadioGroup
row
aria-labelledby="demo-row-radio-buttons-group-label"
name="row-radio-buttons-group"
value={movieType}
onChange={movieTypeChange}
>
<FormControlLabel
value="1"
control={<Radio color="error" />}
label="All"
/>
<FormControlLabel
value="2"
control={<Radio color="error" />}
label="Now Showing"
/>
<FormControlLabel
value="3"
control={<Radio color="error" />}
label="Upcoming"
/>
</RadioGroup>
</FormControl>
{filterdMovie.length > 0 ? (
<OwlCarousel
className="owl-theme"
loop={movieCount}
center={movieCount}
margin={1}
autoplay={true}
dots={false}
items={3}
touchDrag={true}
lazyLoad={true}
responsive={state.responsive}
// responsive={"0:{items:1,},600:{items:3,},1000:{items:5,}"}
animateOut={"fadeOut"}
>
{filterdMovie.map((movieBannertop, idx) => {
return (
<div key={idx}>
<div className="item">
<div className="prs_upcom_movie_box_wrapper">
<div className="prs_upcom_movie_img_box">
<img
src={
movieBannertop.thumbnail
// HTMLImageElement.complete
// ?
// `${process.env.REACT_APP_DEV_BASE_URL_IMAGE}/movie/${movieBannertop.id}/thumbnail.jpg`
// : placeholder
}
alt="movie_img"
/>
<div className="prs_upcom_movie_img_overlay"></div>
<div className="prs_upcom_movie_img_btn_wrapper">
<ul>
<li>
{movieBannertop.bookingOpen ? (
<a
href
onClick={() => viewMovie(movieBannertop)}
style={{ textDecoration: "none" }}
>
More Info
</a>
) : null}
</li>
<li>
{!movieBannertop.upcoming ? (
<a
href
onClick={() => viewMovie(movieBannertop)}
style={{ textDecoration: "none" }}
>
Now Showing
</a>
) : (
<a
href
style={{
textDecoration: "none",
backgroundColor: "#2488ed",
}}
onClick={() => viewMovie(movieBannertop)}
>
Coming Soon
</a>
)}
</li>
</ul>
</div>
</div>
<div className="prs_upcom_movie_content_box">
<div className="prs_upcom_movie_content_box_inner">
<Tooltip title={movieBannertop.name}>
<h2>
<a
href
onClick={() => viewMovie(movieBannertop)}
style={{ textDecoration: "none" }}
>
{" "}
{movieBannertop.name.length > 10
? `${movieBannertop.name.substring(0, 10)}...`
: movieBannertop.name}
</a>
</h2>
</Tooltip>
<p>{movieBannertop.genre}</p>
</div>
<div className="prs_upcom_movie_content_box_inner_icon">
{/* <ul>
<li>
<a href="movie_booking.html">
<i className="flaticon-cart-of-ecommerce"></i>
</a>
</li>
</ul> */}
</div>
</div>
</div>
</div>
</div>
);
})}
</OwlCarousel>
) : (
<>
<Stack
direction="column"
justifyContent="center"
alignItems="center"
>
<img src={notFound} alt="" width="50%" />
<h4>No Movies Found</h4>
</Stack>
</>
)}
const movieTypeChange = (e) => {
e.preventDefault();
setMovieType(e.target.value);
const value = e.target.value;
if (value === "1") {
setFileredMovies(onlineMovies);
}
if (value === "2") {
let shows = [];
onlineMovies.forEach((element) => {
if (!element.upcoming) {
shows.push(element);
}
});
setFileredMovies(shows);
console.log(shows);
}
if (value === "3") {
console.log("3");
let shows = [];
onlineMovies.forEach((element) => {
if (element.upcoming) {
shows.push(element);
}
});
setFileredMovies(shows);
}
};
const movieTypeChange = (e) => {
var shows = [];
const value = e.target.value;
if (value === "1") {
setFileredMovies(onlineMovies);
}
if (value === "2") {
onlineMovies.forEach((element) => {
if (!element.upcoming) {
shows.push(element);
}
});
setFileredMovies(shows);
}
if (value === "3") {
onlineMovies.forEach((element) => {
if (element.upcoming) {
shows.push(element);
}
});
setFileredMovies(shows);
}
setMovieType(value);
};

Bootstrap carousel: sets active item to first when data changes (Reactjs)

My carousel with data.img is an array of link img
<div
id="carouselExampleControls"
className="codeinfo__carousel carousel slide"
data-bs-ride="carousel"
>
<div className="carousel-inner">
<div className="carousel-item active">
<img
src={data.img[0]}
className="codeinfo__img d-block w-100"
alt="..."
/>
</div>
{data.img.map(
(e, i) =>
i > 1 && (
<div className="carousel-item">
<img
src={e}
className="codeinfo__img d-block w-100"
alt="..."
/>
{i}
</div>
)
)}
</div>
<button
className="carousel-control-prev"
type="button"
data-bs-target="#carouselExampleControls"
data-bs-slide="prev"
>
<span className="carousel-control-prev-icon" aria-hidden="true" />
<span className="visually-hidden">Previous</span>
</button>
<button
className="carousel-control-next"
type="button"
data-bs-target="#carouselExampleControls"
data-bs-slide="next"
>
<span className="carousel-control-next-icon" aria-hidden="true" />
<span className="visually-hidden">Next</span>
</button>
</div>
When the data has changed, the active item does not return to the first item, but to the number of the previous active item. So if the length of the previous data.img is bigger than the length of the current data.img there will be nothing to display and the carousel will crash.(sorry for my english, I use google translate)
Like the example below. How to make class "active" return first item?
carousel1 > Change data > carousel2
I solved the problem myself. I removed all bootstrap actions and select active item using react code. I use useState to select active item, setInterval to autoPlay, useEffect to reset activity to 0. Here is my code:
const Carousel = (props) => {
const data = props.data;
const [nowActive, setNowActive] = useState(0);
const [onHover, setOnHover] = useState(false);
// autoplay (stop in hover)
useEffect(() => {
if (!onHover && data !== null) {
let i = nowActive;
const timer = setInterval(() => {
if (i >= data.img.length - 1) {
setNowActive(0);
i = 1;
} else {
setNowActive((prev) => prev + 1);
i = i + 1;
}
}, 3000);
return () => {
clearTimeout(timer);
};
}
}, [onHover, data]);
// change data >> return active = 0
useEffect(() => {
setNowActive(0);
}, [data]);
const carousel = () => {
return (
<div
id="carouselExampleControls"
className="codeinfo__carousel carousel slide"
data-bs-ride="carousel"
onMouseOver={() => setOnHover(true)}
onMouseLeave={() => setOnHover(false)}
>
<div className="carousel-inner">
{data.img.map((e, i) => (
<div className={"carousel-item " + (nowActive === i && "active")}>
<img src={e} className="codeinfo__img d-block w-100" alt="..." />
</div>
))}
</div>
<button
className="carousel-control-prev"
type="button"
onClick={() => {
nowActive === 0
? setNowActive(data.img.length - 1)
: setNowActive(nowActive - 1);
}}
>
<span className="carousel-control-prev-icon" aria-hidden="true" />
<span className="visually-hidden">Previous</span>
</button>
<button
className="carousel-control-next"
type="button"
onClick={() => {
nowActive === data.img.length - 1
? setNowActive(0)
: setNowActive(nowActive + 1);
}}
>
<span className="carousel-control-next-icon" aria-hidden="true" />
<span className="visually-hidden">Next</span>
</button>
</div>
);
};
return data !== null ?
<div>{carousel()}</div> :
<div>Null data</div>
Note: Although the problem has been solved, but this carousel does not have any Animation Effect when changing slides:
Carousel has a property called defaultActiveIndex, which is the initial value of activeIndex. You can use it to focus on the correct CarouselItem
Create a new State:
const [activeIndex, setActiveIndex] = useState(0);
Set the defaultActiveIndex to the newly created state:
Change the activeIndex whenever an item in the carousel is clicked:
onClick={(e) => { setActiveIndex(i); }}
Honestly they should just make this default behavior, not sure why we have to hack it.

How can I make my div tab to disabled cannot click in

I am trying to make my some of my tab disable when editable is set to false:
Here is my following code:
const tabs = [
"Mission",
"Agreement",
"Calendar",
"Managers",
"Members",
"Invitees",
"Applicants",
];
<div className="team-management">
<div className="team-management-tabs-header">
<div className="team-management-tab-items">
{tabs.map((tab, index) => (
<div
className={
activeTab === index
? "team-management-tab-item selected"
: "team-management-tab-item"
}
key={tab}
role="button"
tabIndex={tab}
onKeyPress={() => {
return;
}}
onClick={() => setActiveTab(index)}
>
<span className="tab-item-text">{tab}</span>
<span className="tab-item-indicator" />
</div>
))}
</div>
</div>
<div className="team-management-tab-panes">
{tabs[activeTab] === "Mission" && (
<Mission
editable={editable}
teamId={teamId}
teamData={teamData}
fetchTeamData={fetchTeamData}
/>
)}
...
</div>
Here is how my page look like:
How can I add disabled to my div in this situation?
thank you for helping.
If editable was a state then you can conditionally choose to fire the setActiveTab() function (considering that is the function that enables your tab and you want it disabled ) based on the state of editable.
onClick={() => if(editable)setActiveTab(index)}

Currently I am working on React(Frontend Part), I have bookmark folder list, users able to select one or more bookmark files from the above list

Actual UI:-
Expecting UI:-
<BlockUI tag="div" blocking={foldersLoading}>
<main id="candidates-list-container">
{/* ref={(ref) => { mainBottom = ref; }} */}
<ul>
{folders.map((folder) => {
const folderID = folder.id;
console.log(folderID);
const folderName = folder.name;
console.log(folderName);
return (
<li key={folderID}>
<button
type="button"
className={`job ${
selectedFolders.indexOf(folderID) > -1 ? 'selected' : ''
}`}
disabled={
bookmarkedCandidate.is_bookmarked
&& selectedFolders.indexOf(folderID) === -1
}
onClick={() => {
selectFolder(folderID, folderName);
}}
>
<h2
className={`${
selectedFolders.indexOf(folderID) > -1 ? 'selected' : ''
}`}
>
<input type="checkbox" className="jss1042" value="" />
{folderName}
</h2>
</button>
</li>
);
})}
</ul>
</main>
</BlockUI>
In the image, Selected bookmark files are there. how can I show checkboxes instead of that folder icon () so that the user can select the check box. This is my code it doesn't work for me. Please help me, guys.
As I understand you want to display checkboxes instead of folder icon. Well you can simply remove the button and h2 code above the checkbox code. It should cause only the checkboxes to show.

Resources