Pass UID across composer popups

This commit is contained in:
Lim Chee Aun 2023-01-11 17:07:47 +08:00
parent adcea89a25
commit 162fc7ad07
2 changed files with 9 additions and 3 deletions

View file

@ -81,8 +81,8 @@ function Compose({
}) { }) {
console.warn('RENDER COMPOSER'); console.warn('RENDER COMPOSER');
const [uiState, setUIState] = useState('default'); const [uiState, setUIState] = useState('default');
const UID = useMemo(() => uid(), []); const UID = useRef(uid());
console.log('Compose UID', UID); console.log('Compose UID', UID.current);
const currentAccount = getCurrentAccount(); const currentAccount = getCurrentAccount();
const currentAccountInfo = currentAccount.info; const currentAccountInfo = currentAccount.info;
@ -178,6 +178,7 @@ function Compose({
} }
if (draftStatus) { if (draftStatus) {
const { const {
uid,
status, status,
spoilerText, spoilerText,
visibility, visibility,
@ -186,6 +187,7 @@ function Compose({
poll, poll,
mediaAttachments, mediaAttachments,
} = draftStatus; } = draftStatus;
UID.current = uid;
const composablePoll = !!poll?.options && { const composablePoll = !!poll?.options && {
...poll, ...poll,
options: poll.options.map((o) => o?.title || o), options: poll.options.map((o) => o?.title || o),
@ -384,6 +386,7 @@ function Compose({
editStatus, editStatus,
replyToStatus, replyToStatus,
draftStatus: { draftStatus: {
uid: UID.current,
status: textareaRef.current.value, status: textareaRef.current.value,
spoilerText: spoilerTextRef.current.value, spoilerText: spoilerTextRef.current.value,
visibility, visibility,
@ -459,6 +462,7 @@ function Compose({
editStatus, editStatus,
replyToStatus, replyToStatus,
draftStatus: { draftStatus: {
uid: UID.current,
status: textareaRef.current.value, status: textareaRef.current.value,
spoilerText: spoilerTextRef.current.value, spoilerText: spoilerTextRef.current.value,
visibility, visibility,
@ -630,7 +634,7 @@ function Compose({
); );
} else { } else {
newStatus = await masto.v1.statuses.create(params, { newStatus = await masto.v1.statuses.create(params, {
idempotencyKey: UID, idempotencyKey: UID.current,
}); });
} }
setUIState('default'); setUIState('default');

View file

@ -74,6 +74,8 @@ function App() {
); );
} }
console.debug('OPEN COMPOSE');
return ( return (
<Compose <Compose
editStatus={editStatus} editStatus={editStatus}