Skip to content

Commit

Permalink
Add session storage to token snippet
Browse files Browse the repository at this point in the history
  • Loading branch information
DaemonLoki committed Jun 14, 2023
1 parent f040cf4 commit eb4f655
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions shared/_tokenSnippet.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import './tokenSnippet.css';

const BASE_URL = 'https://stream-calls-dogfood.vercel.app/api/call/sample?';

const STORAGE_KEY = 'tokenSnippetData';

async function callAPI(sampleApp) {
const constructedUrl = constructUrl(sampleApp);
const response = await fetch(constructedUrl);
Expand Down Expand Up @@ -37,13 +39,23 @@ export class TokenSnippet extends React.Component {
}

componentDidMount() {
callAPI(this.state.sampleApp).then((result) => {
const storedData = sessionStorage.getItem(STORAGE_KEY);
if (storedData) {
this.setState({
...this.state,
loadingFinished: true,
...result,
...JSON.parse(storedData),
});
} else {
callAPI(this.state.sampleApp).then((result) => {
sessionStorage.setItem(STORAGE_KEY, JSON.stringify(result));
this.setState({
...this.state,
loadingFinished: true,
...result,
});
});
});
}
}

render() {
Expand Down

0 comments on commit eb4f655

Please sign in to comment.