Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix alerts bug when using non-full-width position #19

Merged
merged 5 commits into from
Jan 27, 2023

Conversation

cronin4392
Copy link
Contributor

@cronin4392 cronin4392 commented Jan 12, 2023

Fixes #1.

  • Got rid of <table>.
  • Added a max-width around the alerts.
  • Added some CSS to elegantly animate the alerts across the bottom.

MMM-MBTA.css Outdated Show resolved Hide resolved
margin-top: 6px;
}

.MMM-MBTA .alerts {
overflow: hidden;
max-width: 300px;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

300px felt like a good max-width

MMM-MBTA.js Outdated
alertHeader.innerHTML = "Alerts";
wrapper.appendChild(alertHeader);

var alertTable = document.createElement("table");
alertTable.className = "small";
var alertTable = document.createElement("div");
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are tables common with MagicMirror modules? Got rid of it as it can cause annoying css behavior.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure. It's been so long since I've written this. I'll just take your word for it, and it was probably the primary reason it's been so buggy as well?

@cronin4392
Copy link
Contributor Author

Need to check CSS is good when more than 1 alert.

var row = document.createElement("tr");
alertTable.appendChild(row);
alertTable.style.cssText = "width: inherit";
if (hasAlerts) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need for else since length checks are inverse of each other.

MMM-MBTA.js Outdated
Comment on lines 288 to 304
alertHeader.className = "module-header alerts-header";
alertHeader.innerHTML = "Alerts";
wrapper.appendChild(alertHeader);

var alertTable = document.createElement("table");
alertTable.className = "small";
var alertsDiv = document.createElement("div");
alertsDiv.className = "alerts small";

if (showEmptyAlerts) {
var alertsWrapper = document.createElement("div");
alertsWrapper.className = "alerts-wrapper";
alertsDiv.appendChild(alertsWrapper);

for (let alert of uniqueAlerts) {
var alertText = alert;
var alertDiv = document.createElement("div");
alertDiv.innerHTML = "No alerts";
alertDiv.className = "light small alert";
alertsWrapper.appendChild(alertDiv);
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved common dom updates so it's easier to discern and make changes

/* start the alert off screen */
padding-left: 100%;
transform: translateX(0%);
animation: alert calc(0.075s * var(--char-count, 100)) linear infinite;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Set a CSS variable in JS with the number of characters the alerts are and use it in the animation timing.

@edward-shen
Copy link
Owner

Hey @cronin4392, thank you so much for the pull request. It means a lot to me to see this still get some love and care. Unfortunately I don't have the dev environment for a Magic mirror right now, so reviewing this code is a little tricky for me right now. Your changes look solid though from a review standpoint, so I'm inclined to merge.

Do you mind providing some before/after images? I'd really like to see the effects of this change visually, just to add a little more confident in merging.

@cronin4392
Copy link
Contributor Author

Hey @edward-shen sorry for the delay, lost track of this and didn't see your comment until now!

Before:
image

After:
image

@edward-shen edward-shen merged commit 71e34a3 into edward-shen:master Jan 27, 2023
@edward-shen
Copy link
Owner

Thanks! Merged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Alerts are not properly formatted when in non-full-width position
2 participants