[Glitch] Postpone scroll-to-detailed status after react components are loaded
Port 70801b850c to glitch-soc
			
			
This commit is contained in:
		@@ -12,6 +12,17 @@ function main() {
 | 
				
			|||||||
  const Rellax = require('rellax');
 | 
					  const Rellax = require('rellax');
 | 
				
			||||||
  const createHistory = require('history').createBrowserHistory;
 | 
					  const createHistory = require('history').createBrowserHistory;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  const scrollToDetailedStatus = () => {
 | 
				
			||||||
 | 
					    const history = createHistory();
 | 
				
			||||||
 | 
					    const detailedStatuses = document.querySelectorAll('.public-layout .detailed-status');
 | 
				
			||||||
 | 
					    const location = history.location;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if (detailedStatuses.length === 1 && (!location.state || !location.state.scrolledToDetailedStatus)) {
 | 
				
			||||||
 | 
					      detailedStatuses[0].scrollIntoView();
 | 
				
			||||||
 | 
					      history.replace(location.pathname, { ...location.state, scrolledToDetailedStatus: true });
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					  };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  ready(() => {
 | 
					  ready(() => {
 | 
				
			||||||
    const locale = document.documentElement.lang;
 | 
					    const locale = document.documentElement.lang;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -54,8 +65,14 @@ function main() {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
          ReactDOM.render(<MediaContainer locale={locale} components={reactComponents} />, content);
 | 
					          ReactDOM.render(<MediaContainer locale={locale} components={reactComponents} />, content);
 | 
				
			||||||
          document.body.appendChild(content);
 | 
					          document.body.appendChild(content);
 | 
				
			||||||
 | 
					          scrollToDetailedStatus();
 | 
				
			||||||
        })
 | 
					        })
 | 
				
			||||||
        .catch(error => console.error(error));
 | 
					        .catch(error => {
 | 
				
			||||||
 | 
					          console.error(error);
 | 
				
			||||||
 | 
					          scrollToDetailedStatus();
 | 
				
			||||||
 | 
					        });
 | 
				
			||||||
 | 
					    } else {
 | 
				
			||||||
 | 
					      scrollToDetailedStatus();
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    const parallaxComponents = document.querySelectorAll('.parallax');
 | 
					    const parallaxComponents = document.querySelectorAll('.parallax');
 | 
				
			||||||
@@ -63,15 +80,6 @@ function main() {
 | 
				
			|||||||
    if (parallaxComponents.length > 0 ) {
 | 
					    if (parallaxComponents.length > 0 ) {
 | 
				
			||||||
      new Rellax('.parallax', { speed: -1 });
 | 
					      new Rellax('.parallax', { speed: -1 });
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					 | 
				
			||||||
    const history = createHistory();
 | 
					 | 
				
			||||||
    const detailedStatuses = document.querySelectorAll('.public-layout .detailed-status');
 | 
					 | 
				
			||||||
    const location = history.location;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    if (detailedStatuses.length === 1 && (!location.state || !location.state.scrolledToDetailedStatus)) {
 | 
					 | 
				
			||||||
      detailedStatuses[0].scrollIntoView();
 | 
					 | 
				
			||||||
      history.replace(location.pathname, { ...location.state, scrolledToDetailedStatus: true });
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
  });
 | 
					  });
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user