Refactor: Make app version info editable
Make the app version and description fields in the AppVersionInfo component editable.
This commit is contained in:
@@ -2,11 +2,16 @@
|
||||
import React, { useCallback, useEffect, useState, useRef } from 'react';
|
||||
import { getAppVersionInfo, isAndroidPlatform } from '@/utils/platform';
|
||||
import { Label } from '@/components/ui/label';
|
||||
import { Input } from '@/components/ui/input';
|
||||
import { Textarea } from '@/components/ui/textarea';
|
||||
import { Button } from '@/components/ui/button';
|
||||
|
||||
interface AppVersionInfoProps {
|
||||
className?: string;
|
||||
showDevInfo?: boolean;
|
||||
editable?: boolean;
|
||||
}
|
||||
|
||||
const AppVersionInfo: React.FC<AppVersionInfoProps> = ({
|
||||
className,
|
||||
showDevInfo = true,
|
||||
@@ -27,6 +32,9 @@ const AppVersionInfo: React.FC<AppVersionInfoProps> = ({
|
||||
// 편집 가능한 필드를 위한 상태
|
||||
const [editableVersionName, setEditableVersionName] = useState('1.0.1');
|
||||
const [editableBuildNumber, setEditableBuildNumber] = useState('2');
|
||||
const [companyText, setCompanyText] = useState('ZELLYY CLOUD');
|
||||
const [detailText, setDetailText] = useState('The first build');
|
||||
const [isEditing, setIsEditing] = useState(false);
|
||||
|
||||
// 버전 정보 가져오기
|
||||
const fetchVersionInfo = useCallback(async () => {
|
||||
@@ -102,39 +110,109 @@ const AppVersionInfo: React.FC<AppVersionInfoProps> = ({
|
||||
}
|
||||
}
|
||||
}, [fetchVersionInfo, error, loading, editable]);
|
||||
|
||||
const handleSaveChanges = () => {
|
||||
setIsEditing(false);
|
||||
// 여기서 실제 저장 로직을 구현할 수 있습니다 (예: 로컬 스토리지 또는 API 호출)
|
||||
console.log('변경사항 저장:', {
|
||||
versionName: editableVersionName,
|
||||
buildNumber: editableBuildNumber,
|
||||
companyText,
|
||||
detailText
|
||||
});
|
||||
};
|
||||
|
||||
if (editable) {
|
||||
return <div className={className}>
|
||||
return (
|
||||
<div className={className}>
|
||||
<div className="space-y-3">
|
||||
<div>
|
||||
<Label htmlFor="versionName" className="text-gray-600 text-center block">앱 버전</Label>
|
||||
<div className="p-2 text-base mt-1 py-0 text-center">
|
||||
{editableVersionName} (build {editableBuildNumber})
|
||||
</div>
|
||||
{isEditing ? (
|
||||
<div className="flex gap-2 mt-1">
|
||||
<Input
|
||||
id="versionName"
|
||||
value={editableVersionName}
|
||||
onChange={(e) => setEditableVersionName(e.target.value)}
|
||||
className="text-center"
|
||||
/>
|
||||
<Input
|
||||
id="buildNumber"
|
||||
value={editableBuildNumber}
|
||||
onChange={(e) => setEditableBuildNumber(e.target.value)}
|
||||
className="text-center w-20"
|
||||
/>
|
||||
</div>
|
||||
) : (
|
||||
<div className="p-2 text-base mt-1 py-0 text-center">
|
||||
{editableVersionName} (build {editableBuildNumber})
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<Label htmlFor="notes" className="text-gray-600 text-center block">세부 설명</Label>
|
||||
<div className="p-2 text-base mt-1 py-0 text-center">The first build</div>
|
||||
{isEditing ? (
|
||||
<Textarea
|
||||
id="detailText"
|
||||
value={detailText}
|
||||
onChange={(e) => setDetailText(e.target.value)}
|
||||
className="text-center min-h-[80px] mt-1"
|
||||
/>
|
||||
) : (
|
||||
<div className="p-2 text-base mt-1 py-0 text-center">{detailText}</div>
|
||||
)}
|
||||
</div>
|
||||
|
||||
<div className="mt-[70px] text-center">
|
||||
<p className="text-gray-400 font-semibold text-lg my-[50px]">ZELLYY CLOUD</p>
|
||||
{isEditing ? (
|
||||
<Input
|
||||
id="companyText"
|
||||
value={companyText}
|
||||
onChange={(e) => setCompanyText(e.target.value)}
|
||||
className="text-center text-gray-400 font-semibold text-lg"
|
||||
/>
|
||||
) : (
|
||||
<p className="text-gray-400 font-semibold text-lg my-[50px]">{companyText}</p>
|
||||
)}
|
||||
</div>
|
||||
|
||||
<div className="flex justify-center mt-4">
|
||||
{isEditing ? (
|
||||
<div className="flex gap-2">
|
||||
<Button variant="outline" onClick={() => setIsEditing(false)}>취소</Button>
|
||||
<Button onClick={handleSaveChanges}>저장</Button>
|
||||
</div>
|
||||
) : (
|
||||
<Button onClick={() => setIsEditing(true)}>편집</Button>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</div>;
|
||||
</div>
|
||||
);
|
||||
}
|
||||
return <div className={className}>
|
||||
{loading ? <div className="py-1 text-center">
|
||||
|
||||
return (
|
||||
<div className={className}>
|
||||
{loading ? (
|
||||
<div className="py-1 text-center">
|
||||
<p className="text-sm text-gray-400 animate-pulse">버전 정보 로딩 중...</p>
|
||||
</div> : error ? <div className="py-1 text-center">
|
||||
</div>
|
||||
) : error ? (
|
||||
<div className="py-1 text-center">
|
||||
<p className="text-sm text-red-500">빌드 정보 로딩 오류</p>
|
||||
<button onClick={handleRetry} className="text-xs text-blue-500 underline mt-1 px-2 py-0.5 rounded hover:bg-blue-50">
|
||||
재시도
|
||||
</button>
|
||||
</div> : <div className="py-1 text-center">
|
||||
</div>
|
||||
) : (
|
||||
<div className="py-1 text-center">
|
||||
<p className="text-sm">{versionInfo.versionName} (build {versionInfo.buildNumber})</p>
|
||||
{showDevInfo && versionInfo.versionCode && <p className="text-xs text-gray-400 mt-1 font-mono">versionCode: {versionInfo.versionCode}</p>}
|
||||
</div>}
|
||||
</div>;
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default AppVersionInfo;
|
||||
|
||||
Reference in New Issue
Block a user