Skip to content

Commit

Permalink
Revert "Reduce number of react component re-renders and extra API calls"
Browse files Browse the repository at this point in the history
  • Loading branch information
JakePost authored Nov 24, 2024
1 parent 9ff3968 commit 0ee6762
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 35 deletions.
38 changes: 15 additions & 23 deletions src/api/blocklist.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,43 +4,35 @@ import { unwrapShortHandle, v1APIPrefix, xAPIKey } from '.';
import { parseNumberWithCommas, unwrapClearSkyURL } from './core';
import { resolveHandleOrDID } from './resolve-handle-or-did';

const blocklistFetchQueued = new Map();
let blocklistDebounce = 0;

/**
* @param {string} handleOrDID
*/
export function blocklist(handleOrDID) {
if (blocklistFetchQueued.has(handleOrDID)) return blocklistFetchQueued.get(handleOrDID);

let generator = blocklistCall(handleOrDID, 'blocklist');
blocklistFetchQueued.set(handleOrDID, generator);

clearTimeout(blocklistDebounce);
blocklistDebounce = setTimeout(() => blocklistFetchQueued.delete(handleOrDID), 1000);
if (!otherSideFetchQueued.has(handleOrDID)) {
otherSideFetchQueued.add(handleOrDID)
clearTimeout(debounceOtherSideFetch);
debounceOtherSideFetch = setTimeout(() => singleBlocklist(handleOrDID).next(), 600);
}

return generator;
return blocklistCall(handleOrDID, 'blocklist');
}

const singleBlocklistFetchQueued = new Map();
let singleBlocklistDebounce = 0;

/**
* @param {string} handleOrDID
*/
export function singleBlocklist(handleOrDID) {
if (singleBlocklistFetchQueued.has(handleOrDID)) return singleBlocklistFetchQueued.get(handleOrDID);

let generator = blocklistCall(handleOrDID, 'single-blocklist');

singleBlocklistFetchQueued.set(handleOrDID, generator);

clearTimeout(singleBlocklistDebounce);
singleBlocklistDebounce = setTimeout(() => singleBlocklistFetchQueued.delete(handleOrDID), 1000);
if (!otherSideFetchQueued.has(handleOrDID)) {
otherSideFetchQueued.add(handleOrDID)
clearTimeout(debounceOtherSideFetch);
debounceOtherSideFetch = setTimeout(() => blocklist(handleOrDID).next(), 600);
}

return generator;
return blocklistCall(handleOrDID, 'single-blocklist');
}

const otherSideFetchQueued = new Set();
let debounceOtherSideFetch = 0;

/**
* @typedef {{
* shortDID: string,
Expand Down
21 changes: 10 additions & 11 deletions src/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,17 +91,16 @@ function showApp() {

console.log('React createRoot/render');
ReactDOM.createRoot(root).render(
<React.StrictMode>
<ThemeProvider theme={theme}>
<>
<RouterProvider router={router}/>
<div className='bluethernal-llc-watermark'>
© 2024 Bluethernal LLC
</div>
</>
</ThemeProvider>
</React.StrictMode>

<React.StrictMode>
<ThemeProvider theme={theme}>
<>
<RouterProvider router={router} />
<div className='bluethernal-llc-watermark'>
© 2024 Bluethernal LLC
</div>
</>
</ThemeProvider>
</React.StrictMode>
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,6 @@ class PanelHeader extends React.Component {
/** @param {typeof singleBlocklist} fetch */
async function* fetchAccountBlocking(shortHandle, fetch) {
try {
console.log('fetching account blocking');
for await (const block of fetch(unwrapShortHandle(shortHandle))) {
yield block;
}
Expand Down

0 comments on commit 0ee6762

Please sign in to comment.