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

Add ability for teams test app to remember scroll position on reload #2276

Open
wants to merge 29 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
5e4d0fa
Add ability for teams test app to remember scroll position on reload
alexneyman-MSFT Apr 17, 2024
d9da09d
Merge branch 'main' into alexneyman/add-scroll-handler-new
AE-MS Apr 19, 2024
3e5fe0f
Refactor ScrollToTopButton component to use TypeScript arrow function…
alexneyman-MSFT May 6, 2024
93a595c
Change IOSSdkScheme to IOSSdkSchemeForTest to resolve future variable…
KangxuanYe Apr 22, 2024
ac30827
Split iOS E2E Testing pipeline to two (#2278)
KangxuanYe Apr 22, 2024
6112942
Removing beta tag - Vikramtha/update pages current app (#2283)
vikramtha Apr 23, 2024
22a1c8a
Private MessageChannels: split capability and add dataLayer.getDataLa…
kerrynf Apr 23, 2024
4889353
Exported Const Enum Backout (#2285)
noahdarveau-MSFT Apr 23, 2024
59cb1b1
Add release yaml (#2274)
jekloudaMSFT Apr 24, 2024
a520940
Add description for pop-up auth window. (#2291)
shrshindeMSFT Apr 24, 2024
47c8f46
Adding API to support external app authenticate with Power Platform C…
ndangudubiyyam Apr 24, 2024
6d06e6e
Turn webStorage capability into a "real" capability (#2289)
AE-MS Apr 25, 2024
cc5d830
Send `validMessageOrigins` to `parentWindow` for verification. (#2293)
shrshindeMSFT Apr 25, 2024
b460f1f
Update webStorage.json to not be blank, but almost blank (#2294)
AE-MS Apr 25, 2024
c693eaa
Add webstorage E2E tests (#2295)
AE-MS Apr 25, 2024
b826989
Publish android artifacts (#2284)
jekloudaMSFT Apr 26, 2024
2020fc0
Cleanup configuration files (#2296)
AE-MS Apr 26, 2024
576d54b
Added in new valid domains for Copilot Chat (#2287)
jadahiya-MSFT Apr 27, 2024
68fcfc9
Trharris/authenticate https (#2270)
TrevorJoelHarris Apr 29, 2024
f0591c8
Fixed incorrect API telemetry label for Pages_NavigateToApp API (#2299)
KangxuanYe Apr 29, 2024
075b450
Update sdf-release.yml for Azure Pipelines (#2292)
jekloudaMSFT Apr 30, 2024
4da7264
Update custom API test (#2282)
cloudtx May 1, 2024
fb81c45
Upgrade `pnpm` to v9 (#2301)
shrshindeMSFT May 3, 2024
db6296d
Update .npmrc location in release helper scripts (#2303)
jekloudaMSFT May 6, 2024
36cd8d9
Add ability for teams test app to remember scroll position on reload
alexneyman-MSFT Apr 17, 2024
b6774c0
Refactor ScrollToTopButton component to use TypeScript arrow function…
alexneyman-MSFT May 6, 2024
4fec2d5
update lock file
alexneyman-MSFT May 6, 2024
d88deeb
Merge branch 'main' into alexneyman/add-scroll-handler-new
alexneyman-MSFT May 6, 2024
14d6634
use const instead of hard coded value for scroll position
alexneyman-MSFT May 9, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions apps/teams-test-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"start:local": "webpack serve --config webpack.local.config.js"
},
"dependencies": {
"lodash.throttle": "^4.1.1",
"react": "^17.0.1",
"react-dom": "^17.0.1"
},
Expand Down
4 changes: 4 additions & 0 deletions apps/teams-test-app/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ import Version from './components/Version';
import VideoAPIs from './components/VideoEffectsApis';
import VisualMediaAPIs from './components/VisualMediaAPIs';
import WebStorageAPIs from './components/WebStorageAPIs';
import RememberScrollToggle from './components/RememberScrollToggle';
import ScrollToTopButton from './components/ScrollToTop';

const urlParams = new URLSearchParams(window.location.search);

Expand Down Expand Up @@ -131,6 +133,8 @@ const App = (): ReactElement => {
return (
<div>
<div className="App-container">
<RememberScrollToggle />
<ScrollToTopButton />
<AppAPIs />
<AppInitializationAPIs />
<AppInstallDialogAPIs />
Expand Down
54 changes: 54 additions & 0 deletions apps/teams-test-app/src/components/RememberScrollToggle.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import throttle from 'lodash.throttle';
alexneyman-MSFT marked this conversation as resolved.
Show resolved Hide resolved
import React, { useEffect, useState } from 'react';

const RememberScrollToggle = () => {
// Initialize the toggle state from sessionStorage
const [isScrollFeatureActive, setIsScrollFeatureActive] = useState(
() => JSON.parse(sessionStorage.getItem('isScrollFeatureActive') || '{}') ?? true,
);

useEffect(() => {
// Save the toggle state to sessionStorage whenever it changes
sessionStorage.setItem('isScrollFeatureActive', JSON.stringify(isScrollFeatureActive));

console.log('scrolling');
alexneyman-MSFT marked this conversation as resolved.
Show resolved Hide resolved

if (!isScrollFeatureActive) {
return;
}

const handleScroll = throttle(() => {
const scrollPosition = window.scrollY;
sessionStorage.setItem('iframeScrollPosition', JSON.stringify(scrollPosition));
console.log('scrolling');
Copy link
Contributor

Choose a reason for hiding this comment

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

Same for here

}, 2000);
alexneyman-MSFT marked this conversation as resolved.
Show resolved Hide resolved

window.addEventListener('scroll', handleScroll);

const savedScrollPosition = sessionStorage.getItem('iframeScrollPosition');
if (savedScrollPosition) {
setTimeout(() => {
window.scrollTo(0, JSON.parse(savedScrollPosition));
}, 100);
}

return () => {
window.removeEventListener('scroll', handleScroll);
};
}, [isScrollFeatureActive]);
return (
<div style={{ marginTop: '2em', marginLeft: '1em' }}>
<label>
remember scroll position
<input
type="checkbox"
checked={isScrollFeatureActive}
aria-label="remember scroll position"
onChange={(e) => setIsScrollFeatureActive(e.target.checked)}
/>
</label>
</div>
);
};

export default RememberScrollToggle;
59 changes: 59 additions & 0 deletions apps/teams-test-app/src/components/ScrollToTop.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import React, { useEffect, useState } from 'react';

const ScrollToTopButton = () => {
const [isVisible, setIsVisible] = useState(false);

// Function to check scroll position and set visibility
const toggleVisibility = () => {
if (window.scrollY > 500) {
alexneyman-MSFT marked this conversation as resolved.
Show resolved Hide resolved
// Adjust 500 to the scroll position you deem appropriate
alexneyman-MSFT marked this conversation as resolved.
Show resolved Hide resolved
setIsVisible(true);
} else {
setIsVisible(false);
}
};

// Function to scroll to the top
const scrollToTop = () => {
window.scrollTo({
top: 0,
behavior: 'smooth', // Smooth scroll
alexneyman-MSFT marked this conversation as resolved.
Show resolved Hide resolved
});
};

useEffect(() => {
window.addEventListener('scroll', toggleVisibility);

return () => {
window.removeEventListener('scroll', toggleVisibility);
};
}, []);

return (
<div>
{isVisible && (
<button
onClick={scrollToTop}
style={{
position: 'fixed',
top: '20px',
right: '20px',
height: '50px',
width: '50px',
fontSize: '25px',
zIndex: 1000,
cursor: 'pointer',
borderRadius: '50%',
border: 'none',
backgroundColor: '#3498db',
color: 'white',
}}
>
</button>
)}
</div>
);
};

export default ScrollToTopButton;
7 changes: 7 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.