Skip to content

Commit

Permalink
Improve mobile view on scene list (#2176)
Browse files Browse the repository at this point in the history
  • Loading branch information
Pierre-Gilles authored Dec 2, 2024
1 parent 6a1779d commit dfff5d2
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 9 deletions.
54 changes: 53 additions & 1 deletion front/src/routes/scene/SceneCard.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,52 @@ class SceneCard extends Component {
await this.setState({ saving: false });
};

render(props, { saving }) {
getMobileView = (props, { saving }) => {
return (
<div class="list-group-item">
<div class="row align-items-center">
<a
href={`/dashboard/scene/${props.scene.selector}`}
class={cx('col-auto', {
[style.disabledSceneRow]: !props.scene.active
})}
>
<i class={`fe fe-${props.scene.icon}`} />
</a>
<a
href={`/dashboard/scene/${props.scene.selector}`}
class={cx('col', {
[style.disabledSceneRow]: !props.scene.active
})}
>
<div class="text-reset d-block">{props.scene.name}</div>
<div class="d-block text-secondary mt-n1">{props.scene.description}</div>
<div>
{props.scene.tags &&
props.scene.tags.map(tag => (
<span class="badge badge-secondary mr-1">
{tag.name.length > MAX_LENGTH_TAG ? `${tag.name.substring(0, MAX_LENGTH_TAG - 3)}...` : tag.name}
</span>
))}
</div>
</a>
<div class="col-auto">
<button
onClick={this.startScene}
type="button"
class={cx('btn', 'btn-outline-success', 'btn-sm', style.btnLoading, {
'btn-loading': saving
})}
>
<i class="fe fe-play" />
</button>
</div>
</div>
</div>
);
};

getDesktopView = (props, { saving }) => {
return (
<div class="col-lg-3 p-2">
<div
Expand Down Expand Up @@ -84,6 +129,13 @@ class SceneCard extends Component {
</div>
</div>
);
};

render(props, state) {
if (props.showMobileView) {
return this.getMobileView(props, state);
}
return this.getDesktopView(props, state);
}
}

Expand Down
21 changes: 16 additions & 5 deletions front/src/routes/scene/SceneCards.jsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,22 @@
import SceneCard from './SceneCard';

const SceneCards = ({ children, ...props }) => (
<div class="row row-cards p-3 align-items-stretch">
{props.scenes.map((scene, index) => (
<SceneCard {...props} scene={scene} index={index} />
))}
</div>
<>
<div class="d-block d-lg-none list-group list-group-flush">
{/* Only visible on small screens */}
{props.scenes.map((scene, index) => (
<SceneCard {...props} scene={scene} index={index} showMobileView />
))}
</div>
<div class="d-none d-lg-block ">
<div class="row row-cards p-3 align-items-stretch">
{/* Only visible on bigger screens */}
{props.scenes.map((scene, index) => (
<SceneCard {...props} scene={scene} index={index} showMobileView={false} />
))}
</div>
</div>
</>
);

export default SceneCards;
4 changes: 2 additions & 2 deletions front/src/routes/scene/ScenePage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const ScenePage = ({ children, ...props }) => (
<div class="page-main">
<div class="my-3 my-md-5">
<div class="container">
<div class="page-header">
<div class={cx('page-header', style.pageHeaderResponsive)}>
<h1 class="page-title">
<Text id="scene.title" />
</h1>
Expand Down Expand Up @@ -43,7 +43,7 @@ const ScenePage = ({ children, ...props }) => (
>
<div class="loader" />
<div class={cx('dimmer-content', style.sceneListContainer)}>
<div class="row">
<div class="row mt-2">
<div class="col-lg-12">
{props.scenes && <SceneCards {...props} />}
{props.scenes && props.scenes.length === 0 && <EmptyState />}
Expand Down
2 changes: 1 addition & 1 deletion front/src/routes/scene/SceneTagFilter.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ class SceneTagFilter extends Component {
show: tagFilterDropdownOpened
})}
>
<button className="btn btn-secondary btn-sm dropdown-toggle ml-2" onClick={this.toggleTagFilterDropdown}>
<button className="btn btn-secondary btn-sm dropdown-toggle" onClick={this.toggleTagFilterDropdown}>
<Text id="scene.filterTagsName" />
</button>
<div
Expand Down
10 changes: 10 additions & 0 deletions front/src/routes/scene/style.css
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
@media (max-width: 992px) {
.pageHeaderResponsive {
margin-top: 0rem;
}
}

.disabledSceneRow {
color: #868e96 !important;
}

.scene_icon {
font-size: 4rem !important;
margin: 0;
Expand Down

0 comments on commit dfff5d2

Please sign in to comment.