Add loader and transition for details page tabs (#5935)
Closes https://github.com/twentyhq/twenty/issues/5656 https://github.com/twentyhq/twenty/assets/22936103/3e4beea2-9aa9-4015-bb99-ee22adb53b63
This commit is contained in:
@ -1,8 +1,8 @@
|
||||
import { ChangeEvent, useRef, useState } from 'react';
|
||||
import styled from '@emotion/styled';
|
||||
import { isNonEmptyArray } from '@sniptt/guards';
|
||||
import { IconPlus } from 'twenty-ui';
|
||||
|
||||
import { SkeletonLoader } from '@/activities/components/SkeletonLoader';
|
||||
import { AttachmentList } from '@/activities/files/components/AttachmentList';
|
||||
import { DropZone } from '@/activities/files/components/DropZone';
|
||||
import { useAttachments } from '@/activities/files/hooks/useAttachments';
|
||||
@ -15,6 +15,7 @@ import {
|
||||
AnimatedPlaceholderEmptySubTitle,
|
||||
AnimatedPlaceholderEmptyTextContainer,
|
||||
AnimatedPlaceholderEmptyTitle,
|
||||
EMPTY_PLACEHOLDER_TRANSITION_PROPS,
|
||||
} from '@/ui/layout/animated-placeholder/components/EmptyPlaceholderStyled';
|
||||
import { isDefined } from '~/utils/isDefined';
|
||||
|
||||
@ -41,7 +42,7 @@ export const Attachments = ({
|
||||
targetableObject: ActivityTargetableObject;
|
||||
}) => {
|
||||
const inputFileRef = useRef<HTMLInputElement>(null);
|
||||
const { attachments } = useAttachments(targetableObject);
|
||||
const { attachments, loading } = useAttachments(targetableObject);
|
||||
const { uploadAttachmentFile } = useUploadAttachmentFile();
|
||||
|
||||
const [isDraggingFile, setIsDraggingFile] = useState(false);
|
||||
@ -58,7 +59,13 @@ export const Attachments = ({
|
||||
await uploadAttachmentFile(file, targetableObject);
|
||||
};
|
||||
|
||||
if (!isNonEmptyArray(attachments)) {
|
||||
const isAttachmentsEmpty = !attachments || attachments.length === 0;
|
||||
|
||||
if (loading && isAttachmentsEmpty) {
|
||||
return <SkeletonLoader />;
|
||||
}
|
||||
|
||||
if (isAttachmentsEmpty) {
|
||||
return (
|
||||
<StyledDropZoneContainer onDragEnter={() => setIsDraggingFile(true)}>
|
||||
{isDraggingFile ? (
|
||||
@ -67,7 +74,10 @@ export const Attachments = ({
|
||||
onUploadFile={onUploadFile}
|
||||
/>
|
||||
) : (
|
||||
<AnimatedPlaceholderEmptyContainer>
|
||||
<AnimatedPlaceholderEmptyContainer
|
||||
// eslint-disable-next-line react/jsx-props-no-spreading
|
||||
{...EMPTY_PLACEHOLDER_TRANSITION_PROPS}
|
||||
>
|
||||
<AnimatedPlaceholder type="noFile" />
|
||||
<AnimatedPlaceholderEmptyTextContainer>
|
||||
<AnimatedPlaceholderEmptyTitle>
|
||||
|
||||
@ -4,13 +4,12 @@ import { getActivityTargetObjectFieldIdName } from '@/activities/utils/getActivi
|
||||
import { CoreObjectNameSingular } from '@/object-metadata/types/CoreObjectNameSingular';
|
||||
import { useFindManyRecords } from '@/object-record/hooks/useFindManyRecords';
|
||||
|
||||
// do we need to test this?
|
||||
export const useAttachments = (targetableObject: ActivityTargetableObject) => {
|
||||
const targetableObjectFieldIdName = getActivityTargetObjectFieldIdName({
|
||||
nameSingular: targetableObject.targetObjectNameSingular,
|
||||
});
|
||||
|
||||
const { records: attachments } = useFindManyRecords<Attachment>({
|
||||
const { records: attachments, loading } = useFindManyRecords<Attachment>({
|
||||
objectNameSingular: CoreObjectNameSingular.Attachment,
|
||||
filter: {
|
||||
[targetableObjectFieldIdName]: {
|
||||
@ -26,5 +25,6 @@ export const useAttachments = (targetableObject: ActivityTargetableObject) => {
|
||||
|
||||
return {
|
||||
attachments,
|
||||
loading,
|
||||
};
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user