mirror of
https://github.com/bitsocialnet/5chan.git
synced 2026-08-03 07:41:04 +02:00
fix(upload): animate uploading ellipsis
This commit is contained in:
@@ -25,6 +25,7 @@ const testState = vi.hoisted(() => ({
|
|||||||
handleUploadMock: vi.fn(),
|
handleUploadMock: vi.fn(),
|
||||||
isOffline: false,
|
isOffline: false,
|
||||||
isOnlineStatusLoading: false,
|
isOnlineStatusLoading: false,
|
||||||
|
isUploading: false,
|
||||||
isResolvingExternalQuotes: false,
|
isResolvingExternalQuotes: false,
|
||||||
navigateMock: vi.fn(),
|
navigateMock: vi.fn(),
|
||||||
offlineTitle: 'offline board',
|
offlineTitle: 'offline board',
|
||||||
@@ -172,12 +173,16 @@ vi.mock('../../../hooks/use-file-upload', () => ({
|
|||||||
testState.uploadComplete = onUploadComplete;
|
testState.uploadComplete = onUploadComplete;
|
||||||
return {
|
return {
|
||||||
handleUpload: testState.handleUploadMock,
|
handleUpload: testState.handleUploadMock,
|
||||||
isUploading: false,
|
isUploading: testState.isUploading,
|
||||||
uploadedFileName: testState.uploadedFileName,
|
uploadedFileName: testState.uploadedFileName,
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
vi.mock('../../loading-ellipsis', () => ({
|
||||||
|
default: ({ string }: { string: string }) => createElement('span', { 'data-testid': 'loading-ellipsis' }, string),
|
||||||
|
}));
|
||||||
|
|
||||||
vi.mock('../../../lib/utils/media-utils', () => ({
|
vi.mock('../../../lib/utils/media-utils', () => ({
|
||||||
getDisplayMediaInfoType: (type: string, t: (key: string) => string) => t(type),
|
getDisplayMediaInfoType: (type: string, t: (key: string) => string) => t(type),
|
||||||
getLinkMediaInfo: (link: string) => {
|
getLinkMediaInfo: (link: string) => {
|
||||||
@@ -293,6 +298,7 @@ describe('PostForm', () => {
|
|||||||
testState.gifFrameStatus = 'idle';
|
testState.gifFrameStatus = 'idle';
|
||||||
testState.isOffline = false;
|
testState.isOffline = false;
|
||||||
testState.isOnlineStatusLoading = false;
|
testState.isOnlineStatusLoading = false;
|
||||||
|
testState.isUploading = false;
|
||||||
testState.isResolvingExternalQuotes = false;
|
testState.isResolvingExternalQuotes = false;
|
||||||
testState.offlineTitle = 'offline board';
|
testState.offlineTitle = 'offline board';
|
||||||
testState.postIndex = undefined;
|
testState.postIndex = undefined;
|
||||||
@@ -433,6 +439,15 @@ describe('PostForm', () => {
|
|||||||
expect(table?.textContent).toContain('file name.jpg');
|
expect(table?.textContent).toContain('file name.jpg');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('uses the shared loading ellipsis while a post form upload is running', async () => {
|
||||||
|
testState.isUploading = true;
|
||||||
|
|
||||||
|
await renderPostForm('/all');
|
||||||
|
await clickByText(container, 'start_new_thread');
|
||||||
|
|
||||||
|
expect(container.querySelector('[data-testid="loading-ellipsis"]')?.textContent).toBe('uploading');
|
||||||
|
});
|
||||||
|
|
||||||
it('redirects to the pending route when a post publish index is already available on mount', async () => {
|
it('redirects to the pending route when a post publish index is already available on mount', async () => {
|
||||||
testState.postIndex = 7;
|
testState.postIndex = 7;
|
||||||
testState.resolvedCommunityAddress = 'music-posting.eth';
|
testState.resolvedCommunityAddress = 'music-posting.eth';
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ import { getShowUploadControls, isWebRuntime } from '../../lib/media-hosting/sho
|
|||||||
import { isCommentArchived } from '../../lib/utils/comment-moderation-utils';
|
import { isCommentArchived } from '../../lib/utils/comment-moderation-utils';
|
||||||
import useMediaHostingStore from '../../stores/use-media-hosting-store';
|
import useMediaHostingStore from '../../stores/use-media-hosting-store';
|
||||||
import BoardOfflineAlert from '../board-offline-alert/board-offline-alert';
|
import BoardOfflineAlert from '../board-offline-alert/board-offline-alert';
|
||||||
|
import LoadingEllipsis from '../loading-ellipsis';
|
||||||
import styles from './post-form.module.css';
|
import styles from './post-form.module.css';
|
||||||
import capitalize from 'lodash/capitalize';
|
import capitalize from 'lodash/capitalize';
|
||||||
import debounce from 'lodash/debounce';
|
import debounce from 'lodash/debounce';
|
||||||
@@ -258,7 +259,7 @@ const PostFormFields = ({
|
|||||||
isUploading={isUploading}
|
isUploading={isUploading}
|
||||||
showUploadControls={showUploadControls}
|
showUploadControls={showUploadControls}
|
||||||
/>
|
/>
|
||||||
<span>{isUploading ? t('uploading') : getPublishURLFilename(url) || uploadedFileName || t('no_file_chosen')}</span>
|
<span>{isUploading ? <LoadingEllipsis string={t('uploading')} /> : getPublishURLFilename(url) || uploadedFileName || t('no_file_chosen')}</span>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
)}
|
)}
|
||||||
|
|||||||
@@ -165,6 +165,10 @@ vi.mock('../../../hooks/use-file-upload', () => ({
|
|||||||
},
|
},
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
vi.mock('../../loading-ellipsis', () => ({
|
||||||
|
default: ({ string }: { string: string }) => createElement('span', { 'data-testid': 'loading-ellipsis' }, string),
|
||||||
|
}));
|
||||||
|
|
||||||
vi.mock('lodash/debounce', () => ({
|
vi.mock('lodash/debounce', () => ({
|
||||||
default: <T extends (...args: any[]) => void>(fn: T) => {
|
default: <T extends (...args: any[]) => void>(fn: T) => {
|
||||||
const wrapped = ((...args: Parameters<T>) => fn(...args)) as T & { cancel: () => void };
|
const wrapped = ((...args: Parameters<T>) => fn(...args)) as T & { cancel: () => void };
|
||||||
@@ -344,6 +348,14 @@ describe('ReplyModal', () => {
|
|||||||
expect(testState.setPublishReplyOptionsMock).toHaveBeenCalledWith({ displayName: 'Alice' });
|
expect(testState.setPublishReplyOptionsMock).toHaveBeenCalledWith({ displayName: 'Alice' });
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('uses the shared loading ellipsis while a reply upload is running', async () => {
|
||||||
|
testState.isUploading = true;
|
||||||
|
|
||||||
|
await renderReplyModal('/mu/thread/post-1');
|
||||||
|
|
||||||
|
expect(container.querySelector('[data-testid="loading-ellipsis"]')?.textContent).toBe('uploading');
|
||||||
|
});
|
||||||
|
|
||||||
it('does not render an offline warning when the shared offline hook reports the board as online', async () => {
|
it('does not render an offline warning when the shared offline hook reports the board as online', async () => {
|
||||||
await renderReplyModal('/mu/thread/post-1');
|
await renderReplyModal('/mu/thread/post-1');
|
||||||
|
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ import usePublishReply from '../../hooks/use-publish-reply';
|
|||||||
import useIsMobile from '../../hooks/use-is-mobile';
|
import useIsMobile from '../../hooks/use-is-mobile';
|
||||||
import { useFileUpload } from '../../hooks/use-file-upload';
|
import { useFileUpload } from '../../hooks/use-file-upload';
|
||||||
import BoardOfflineAlert from '../board-offline-alert/board-offline-alert';
|
import BoardOfflineAlert from '../board-offline-alert/board-offline-alert';
|
||||||
|
import LoadingEllipsis from '../loading-ellipsis';
|
||||||
import styles from './reply-modal.module.css';
|
import styles from './reply-modal.module.css';
|
||||||
import capitalize from 'lodash/capitalize';
|
import capitalize from 'lodash/capitalize';
|
||||||
import debounce from 'lodash/debounce';
|
import debounce from 'lodash/debounce';
|
||||||
@@ -374,7 +375,7 @@ const ReplyModal = ({ closeModal, showReplyModal, parentCid, parentNumber, threa
|
|||||||
</button>
|
</button>
|
||||||
</span>
|
</span>
|
||||||
<span className={styles.uploadFileName} title={displayedFileName || t('no_file_chosen')}>
|
<span className={styles.uploadFileName} title={displayedFileName || t('no_file_chosen')}>
|
||||||
{isUploading ? t('uploading') : displayedFileName || t('no_file_chosen')}
|
{isUploading ? <LoadingEllipsis string={t('uploading')} /> : displayedFileName || t('no_file_chosen')}
|
||||||
</span>
|
</span>
|
||||||
</span>
|
</span>
|
||||||
)}
|
)}
|
||||||
|
|||||||
Reference in New Issue
Block a user