MCPcopy Create free account
hub / github.com/Forward-Future/loopy / loadVotes

Function loadVotes

loop-library/site/script.js:805–860  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

803 account.append(label, logout);
804
805 const anchor = document.querySelector(".results-line") ||
806 document.querySelector(".detail-actions");
807 anchor?.insertAdjacentElement("afterend", account);
808}
809
810async function loadVotes() {
811 if (voteControls.length === 0) return;
812
813 try {
814 const response = await fetch(VOTE_API_URL, {
815 credentials: "same-origin",
816 headers: { Accept: "application/json" },
817 });
818 if (!response.ok) throw new Error("Voting unavailable");
819 const body = await response.json();
820 voteViewer = null;
821 viewerVotes = {};
822 const sessionToken = readVoteSessionToken();
823 if (sessionToken) {
824 try {
825 const sessionResponse = await fetch(`${LOOP_LIBRARY_PATH}/auth/session`, {
826 method: "POST",
827 credentials: "same-origin",
828 headers: {
829 Accept: "application/json",
830 "Content-Type": "application/json",
831 },
832 body: JSON.stringify({ sessionToken }),
833 });
834 if (!sessionResponse.ok) {
835 if (sessionResponse.status < 500) clearVoteSessionToken();
836 } else {
837 const sessionBody = await sessionResponse.json();
838 if (sessionBody.viewer) {
839 voteViewer = sessionBody.viewer;
840 viewerVotes = sessionBody.viewerVotes || {};
841 } else {
842 clearVoteSessionToken();
843 }
844 }
845 } catch {
846 // Public totals and the launch gate remain usable when restoring an
847 // existing session is temporarily unavailable.
848 }
849 }
850 voteControls.forEach((control) => {
851 const slug = control.dataset.loopSlug;
852 updateVoteControls(
853 control,
854 body.votes?.[slug],
855 viewerVotes[slug] || 0,
856 );
857 });
858 setVotingUiVisible(body.uiEnabled === true);
859 applySort(activeSort);
860 updateLibrary();
861 if (body.uiEnabled === true) renderVoteAccount();
862 } catch {

Callers 1

script.jsFile · 0.85

Calls 8

readVoteSessionTokenFunction · 0.85
clearVoteSessionTokenFunction · 0.85
updateVoteControlsFunction · 0.85
setVotingUiVisibleFunction · 0.85
applySortFunction · 0.85
updateLibraryFunction · 0.85
renderVoteAccountFunction · 0.85
fetchFunction · 0.50

Tested by

no test coverage detected