Skip to content

Commit

Permalink
chore(): clean up repeat useEffect
Browse files Browse the repository at this point in the history
  • Loading branch information
didd committed Sep 20, 2024
1 parent ada15ff commit 23dbde5
Showing 1 changed file with 2 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -85,45 +85,6 @@ export const useBlocksPublishing = (props: UseBlocksPublishingProps) => {
};
}, []);

React.useEffect(() => {
if (!blocksInUse.length) return;
if (blocksInUse.every(bl => bl.status === 'success') && appInfo) {
const tagLabelType = sdk.current.services.gql.labelTypes.TAG;
const tags = editorTags.map(tagName => {
return {
labelType: tagLabelType,
value: tagName,
};
});
const beamContent: AkashaBeamInput = {
active: true,
nsfw: isNsfw,
tags: tags,
content: blocksInUse.map(blockData => ({
blockID: blockData.response?.blockID,
order: blockData.order,
})),
createdAt: new Date().toISOString(),
appID: appInfo.appID,
appVersionID: appInfo.appVersionID,
};

if (createBeamQuery.loading || createBeamQuery.error) return;
if (createBeamQuery.called) return;

createBeam({
variables: {
i: {
content: beamContent,
},
},
}).then(resp => {
setBlocksInUse([]);
setIsPublishing(false);
});
}
}, [blocksInUse, appInfo, editorTags, isNsfw, createBeam, createBeamQuery]);

// always add the default block
React.useEffect(() => {
if (blocksInUse.length === 0) {
Expand All @@ -141,7 +102,7 @@ export const useBlocksPublishing = (props: UseBlocksPublishingProps) => {

React.useEffect(() => {
if (!blocksInUse.length) return;
if (blocksInUse.every(bl => bl.status === 'success')) {
if (blocksInUse.every(bl => bl.status === 'success') && appInfo) {
const tagLabelType = sdk.current.services.gql.labelTypes.TAG;
const tags = editorTags.map(tagName => {
return {
Expand Down Expand Up @@ -181,7 +142,7 @@ export const useBlocksPublishing = (props: UseBlocksPublishingProps) => {
setErrors(prev => [...prev, new Error(`failed to create beam: ${err.message}`)]);
});
}
}, [blocksInUse, createBeam, createBeamQuery, isNsfw, editorTags]);
}, [blocksInUse, createBeam, createBeamQuery, isNsfw, editorTags, onComplete, appInfo]);

const createContentBlocks = React.useCallback(
async (nsfw: boolean, editorTags: string[], blocksWithActiveNsfw: Map<number, boolean>) => {
Expand Down

0 comments on commit 23dbde5

Please sign in to comment.