Skip to content

Open-source social media scheduler built for AI agents and the teams behind them. Create, schedule and publish posts to every network through MCP or the REST API, or write them yourself in a composer your team will love.

7.3 KB
Raw Blame
<script setup lang="ts">
import { computed } from 'vue';

import ComposerLiveDataPending from '@/components/posts/composer/ComposerLiveDataPending.vue';
import AiGeneratedRow from '@/components/posts/editor/AiGeneratedRow.vue';
import DiscordSettings from '@/components/posts/editor/DiscordSettings.vue';
import GoogleBusinessSettings from '@/components/posts/editor/GoogleBusinessSettings.vue';
import InstagramSettings from '@/components/posts/editor/InstagramSettings.vue';
import LinkedInSettings from '@/components/posts/editor/LinkedInSettings.vue';
import MastodonSettings from '@/components/posts/editor/MastodonSettings.vue';
import PinterestSettings from '@/components/posts/editor/PinterestSettings.vue';
import ThreadsSettings from '@/components/posts/editor/ThreadsSettings.vue';
import TikTokSettings from '@/components/posts/editor/TikTokSettings.vue';
import YouTubeSettings from '@/components/posts/editor/YouTubeSettings.vue';
import { useComposerLiveState } from '@/composables/useComposerData';
import type {
    ComposerAccount,
    DestinationDraft,
} from '@/composables/usePostComposition';
import { isVideo } from '@/lib/mediaType';
import type { PinterestBoardsPayload } from '@/types';
import type { ChannelTikTokCreatorInfo } from '@/types/channel';
import { ContentType } from '@/types/content-type';
import type { MediaItem } from '@/types/media';
import { Platform } from '@/types/platform';

const props = withDefaults(
    defineProps<{
        account: ComposerAccount;
        destination: DestinationDraft & { content: string; media: MediaItem[] };
        platformIndex: number;
        platformConfig?: Record<string, any> | null;
        pinterestBoards?: PinterestBoardsPayload | null;
        tiktokCreatorInfo?: ChannelTikTokCreatorInfo | null;
        disabled?: boolean;
    }>(),
    {
        platformConfig: null,
        pinterestBoards: null,
        tiktokCreatorInfo: null,
        disabled: false,
    },
);

const emit = defineEmits<{
    'update:meta': [value: Record<string, any>];
    'link-facebook': [];
}>();

const { accountLoaded } = useComposerLiveState();

const waitsForLiveData = computed(
    () =>
        (props.account.platform === Platform.TikTok ||
            props.account.platform === Platform.Pinterest) &&
        !accountLoaded(props.account.id),
);

const videoDurationSec = computed(
    () =>
        Math.ceil(
            props.destination.media.find((item) => isVideo(item))?.meta
                ?.duration ?? 0,
        ) || null,
);

const update = (meta: Record<string, any>): void => emit('update:meta', meta);
const linkFacebook = (): void => emit('link-facebook');

const AI_GENERATED_ROWS: Partial<
    Record<string, { metaKey: string; testId: string }>
> = {
    [ContentType.YouTubeShort]: {
        metaKey: 'is_ai_generated',
        testId: 'youtube-ai-generated',
    },
    [ContentType.InstagramFeed]: {
        metaKey: 'is_ai_generated',
        testId: 'instagram-ai-generated',
    },
    [ContentType.InstagramReel]: {
        metaKey: 'is_ai_generated',
        testId: 'instagram-ai-generated',
    },
    [ContentType.InstagramStory]: {
        metaKey: 'is_ai_generated',
        testId: 'instagram-ai-generated',
    },
    [ContentType.TikTokVideo]: { metaKey: 'is_aigc', testId: 'tiktok-ai-generated' },
    [ContentType.XPost]: { metaKey: 'is_ai_generated', testId: 'x-ai-generated' },
    [ContentType.XPoll]: { metaKey: 'is_ai_generated', testId: 'x-ai-generated' },
};

const aiRow = computed(
    () => AI_GENERATED_ROWS[props.destination.content_type] ?? null,
);
const aiGenerated = computed({
    get: (): boolean =>
        aiRow.value
            ? props.destination.meta?.[aiRow.value.metaKey] === true
            : false,
    set: (value: boolean) => {
        if (aiRow.value) {
            update({ ...props.destination.meta, [aiRow.value.metaKey]: value });
        }
    },
});
</script>

<template>
    <div class="contents" data-testid="composer-network-settings">
        <InstagramSettings
            v-if="
                account.platform === Platform.Instagram ||
                account.platform === Platform.InstagramFacebook
            "
            :account-id="account.id"
            :platform="account.platform"
            :platform-index="platformIndex"
            :content-type="destination.content_type"
            :meta="destination.meta"
            :disabled="disabled"
            @update:meta="update"
            @link-facebook="linkFacebook"
        />
        <ThreadsSettings
            v-else-if="
                account.platform === Platform.Threads &&
                destination.content_type !== ContentType.ThreadsGhostPost
            "
            :meta="destination.meta"
            :disabled="disabled"
            @update:meta="update"
        />
        <ComposerLiveDataPending v-else-if="waitsForLiveData" />
        <TikTokSettings
            v-else-if="account.platform === Platform.TikTok"
            :social-account="account"
            :publish-config="platformConfig?.publishConfig ?? null"
            :creator-info="tiktokCreatorInfo"
            :video-duration-sec="videoDurationSec"
            :content-type="destination.content_type"
            :meta="destination.meta"
            :platform-index="platformIndex"
            :disabled="disabled"
            @update:meta="update"
        />
        <YouTubeSettings
            v-else-if="account.platform === Platform.YouTube"
            :platform-index="platformIndex"
            :publish-config="platformConfig?.publishConfig ?? null"
            :content="destination.content"
            :meta="destination.meta"
            :disabled="disabled"
            @update:meta="update"
        />
        <PinterestSettings
            v-else-if="account.platform === Platform.Pinterest"
            :social-account="account"
            :boards="pinterestBoards?.boards ?? []"
            :boards-truncated="pinterestBoards?.truncated ?? false"
            :meta="destination.meta"
            :platform-index="platformIndex"
            :disabled="disabled"
            @update:meta="update"
        />
        <LinkedInSettings
            v-else-if="
                account.platform === Platform.LinkedIn ||
                account.platform === Platform.LinkedInPage
            "
            :account-id="account.id"
            :media="destination.media"
            :meta="destination.meta"
            :disabled="disabled"
            @update:meta="update"
        />
        <GoogleBusinessSettings
            v-else-if="account.platform === Platform.GoogleBusiness"
            :platform-index="platformIndex"
            :meta="destination.meta"
            :disabled="disabled"
            @update:meta="update"
        />
        <DiscordSettings
            v-else-if="account.platform === Platform.Discord"
            :social-account="account"
            :meta="destination.meta"
            :platform-index="platformIndex"
            :disabled="disabled"
            @update:meta="update"
        />
        <MastodonSettings
            v-else-if="account.platform === Platform.Mastodon"
            :meta="destination.meta"
            :disabled="disabled"
            @update:meta="update"
        />
        <AiGeneratedRow
            v-if="aiRow"
            v-model="aiGenerated"
            :test-id="aiRow.testId"
            :disabled="disabled"
        />
    </div>
</template>