Files
discord-decomp/modules/user_profile/hooks/useNote.tsx
T
2026-11-01 12:12:55 +02:00

80 lines
2.0 KiB
TypeScript

// Metro module 12045 (f12046).
import { useEffect } from "react";
import NoteStore from "../notes/NoteStore";
import { Endpoints } from "../../../Constants";
import { useStateFromStores } from "../../../_bundle/Module589";
import Dispatcher from "../../../Dispatcher";
import { HTTP } from "../../../_bundle/sendRequest";
let _fetchNote = function _fetchNote() {
const r8 = async (userId) => {
let c27224_4 = 0;
let c30481_0, c30481_1;
L12: {
try {
c30481_0 = userId;
c30481_1 = void 0;
Dispatcher.dispatch({
type: "USER_NOTE_LOAD_START",
userId
});
c27224_4 = 1;
c30481_1 = (await HTTP.get({
url: Endpoints.NOTE(userId),
oldFormErrors: true,
rejectWithError: true
})).body;
if (c30481_1.note_user_id !== c30481_0) {
throw new Error("Invalid response from server");
}
Dispatcher.dispatch({
type: "USER_NOTE_UPDATE",
id: c30481_0,
note: c30481_1.note
});
c27224_4 = 0;
} catch ($e) {
let r7 = $e;
if (c27224_4 !== 0) {
while (true) {
try {
c27224_4 = 0;
Dispatcher.dispatch({
type: "USER_NOTE_UPDATE",
id: c30481_0
});
break L12;
} catch ($e) {
r7 = $e;
if (c27224_4 === 0) {
break;
}
}
}
}
throw r7;
}
}
};
_fetchNote = r8;
return r8.apply(this, arguments);
};
export default function useNote(a0) {
let stateFromStores;
let r12 = useStateFromStores([NoteStore], () => NoteStore.getNote(a0));
stateFromStores = r12;
useEffect(() => {
if (stateFromStores == null) {
(function fetchNote() {
return _fetchNote.apply(this, arguments);
})(a0);
}
}, [stateFromStores, a0]);
if (stateFromStores == null) {
r12 = {
loading: true,
note: null
};
}
return r12;
};