Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(account): add loading state for avatar upload #556

Merged
merged 3 commits into from
Mar 5, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,10 @@ export const NodeHeader = memo(

return (
<>
<div className={`flex-shrink-0 ${source === 'skillResponsePreview' ? 'mb-0' : 'mb-3'}`}>
<div
data-cy="skill-response-node-header"
className={`flex-shrink-0 ${source === 'skillResponsePreview' ? 'mb-0' : 'mb-3'}`}
>
<div className="flex items-center gap-2">
{showIcon && (
<div className="w-6 h-6 rounded bg-[#F79009] shadow-lg flex items-center justify-center flex-shrink-0">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,14 @@ import { useTranslation } from 'react-i18next';
import { useDebouncedCallback } from 'use-debounce';
import ImgCrop from 'antd-img-crop';
import { useSiderStoreShallow } from '@refly-packages/ai-workspace-common/stores/sider';
import { AiOutlineLoading3Quarters } from 'react-icons/ai';
import { BiSolidEdit } from 'react-icons/bi';

export const AccountSetting = () => {
const [form] = Form.useForm();
const userStore = useUserStore();
const { t } = useTranslation();
const [loadingAvatar, setLoadingAvatar] = useState(false);

const { showSettingModal } = useSiderStoreShallow((state) => ({
showSettingModal: state.showSettingModal,
Expand All @@ -37,9 +40,12 @@ export const AccountSetting = () => {
};

const uploadAvatar = async (file: File) => {
if (loadingAvatar) return;
setLoadingAvatar(true);
const { data } = await getClient().upload({
body: { file, visibility: 'public' },
});
setLoadingAvatar(false);
if (data?.data.url) {
setAvatarError(false);
setAvatarUrl(data.data.url);
Expand Down Expand Up @@ -153,7 +159,18 @@ export const AccountSetting = () => {
showUploadList={false}
beforeUpload={beforeUpload}
>
<div className="w-full h-full bg-gray-200 rounded-full flex items-center justify-center overflow-hidden">
<div className="w-full h-full group relative bg-gray-200 rounded-full flex items-center justify-center overflow-hidden">
{loadingAvatar && (
<div className="absolute inset-0 bg-black/20 flex items-center justify-center">
<AiOutlineLoading3Quarters size={22} className="animate-spin text-white" />
</div>
)}
{!loadingAvatar && (
<div className="absolute invisible group-hover:visible inset-0 bg-black/20 flex items-center justify-center">
<BiSolidEdit size={22} className="text-white" />
</div>
)}

{avatarUrl && !avatarError ? (
<img
src={avatarUrl}
Expand Down