main

mattermost/focalboard

Last updated at: 29/12/2023 09:50

attachmentBlock.tsx

TLDR

This file contains a TypeScript module that exports a type and a function. The type is called AttachmentBlock and it represents a specific type of block. The function is called createAttachmentBlock and it is used to create an instance of the AttachmentBlock type.

Methods

createAttachmentBlock

This method is used to create an instance of the AttachmentBlock type. It takes an optional parameter block of type Block and returns an instance of AttachmentBlock. If the block parameter is provided, the fileId field of the created AttachmentBlock will be set based on the attachmentId or fileId field of the block parameter. Otherwise, the fileId field will be an empty string. The isUploading field of the created AttachmentBlock will be set to false and the uploadingPercent field will be set to 0.

Classes

// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import {Block, createBlock} from './block'

type AttachmentBlockFields = {
    fileId: string
}

type AttachmentBlock = Block & {
    type: 'attachment'
    fields: AttachmentBlockFields
    isUploading: boolean
    uploadingPercent: number
}

function createAttachmentBlock(block?: Block): AttachmentBlock {
    return {
        ...createBlock(block),
        type: 'attachment',
        fields: {
            fileId: block?.fields.attachmentId || block?.fields.fileId || '',
        },
        isUploading: false,
        uploadingPercent: 0,
    }
}

export {AttachmentBlock, createAttachmentBlock}