Skip to content

Commit

Permalink
move static data processing out of main
Browse files Browse the repository at this point in the history
a
  • Loading branch information
marcustyphoon committed Aug 20, 2024
1 parent d5ee3b9 commit 3b2e2e6
Showing 1 changed file with 12 additions and 14 deletions.
26 changes: 12 additions & 14 deletions src/features/quick_reblog.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@ import { dom } from '../utils/dom.js';
import { showErrorModal } from '../utils/modals.js';
import { keyToCss } from '../utils/css_map.js';

const blogSelector = dom('select');
const blogSelector = dom('select', null, null, [
...userBlogs.map(({ name, uuid }) => dom('option', { value: uuid }, null, [name])),
...(joinedCommunities.length ? [dom('hr')] : []),
...joinedCommunities.map(({ title, uuid, blog: { name } }) => dom('option', { value: uuid }, null, [`${title} (${name})`]))
]);
const blogAvatar = dom('div', { class: 'avatar' });
const blogSelectorContainer = dom('div', { class: 'select-container' }, null, [
blogAvatar,
Expand Down Expand Up @@ -65,7 +69,13 @@ const alreadyRebloggedStorageKey = 'quick_reblog.alreadyRebloggedList';
const rememberedBlogStorageKey = 'quick_reblog.rememberedBlogs';
const quickTagsStorageKey = 'quick_tags.preferences.tagBundles';
const blogHashes = new Map();
const avatarUrls = new Map();
const avatarUrls = new Map(
[...userBlogs, ...joinedCommunities].map(data => {
const avatar = data.avatarImage ?? data.avatar;
const { url } = avatar.at(-1);
return [data.uuid, url];
})
);

const reblogButtonSelector = `
${postSelector} footer a[href*="/reblog/"],
Expand Down Expand Up @@ -320,18 +330,6 @@ export const main = async function () {
alreadyRebloggedLimit
} = await getPreferences('quick_reblog'));

blogSelector.replaceChildren(
...userBlogs.map(({ name, uuid }) => dom('option', { value: uuid }, null, [name])),
...joinedCommunities.length ? [dom('hr')] : [],
...joinedCommunities.map(({ title, uuid, blog: { name } }) => dom('option', { value: uuid }, null, [`${title} (${name})`]))
);

[...userBlogs, ...joinedCommunities].forEach((data) => {
const avatar = data.avatarImage ?? data.avatar;
const { url } = avatar.at(-1);
avatarUrls.set(data.uuid, url);
});

if (rememberLastBlog) {
for (const { uuid } of [...userBlogs, ...joinedCommunities]) {
blogHashes.set(uuid, await sha256(uuid));
Expand Down

0 comments on commit 3b2e2e6

Please sign in to comment.