feat(providers): add timestamp-based sorting for provider list

- Add createdAt timestamp field to Provider interface
- Implement sorting logic: old providers without timestamp first, then by creation time
- Providers without timestamps are sorted alphabetically by name
- New providers are automatically timestamped on creation
This commit is contained in:
Jason
2025-09-07 22:29:08 +08:00
parent fa2b11fcc2
commit 1482dc9e66
3 changed files with 25 additions and 2 deletions

View File

@@ -134,6 +134,7 @@ function App() {
const newProvider: Provider = {
...provider,
id: generateId(),
createdAt: Date.now(), // 添加创建时间戳
};
await window.api.addProvider(newProvider, activeApp);
await loadProviders();

View File

@@ -44,9 +44,30 @@ const ProviderList: React.FC<ProviderListProps> = ({
}
};
// 对供应商列表进行排序
const sortedProviders = Object.values(providers).sort((a, b) => {
// 按添加时间排序
// 没有时间戳的视为最早添加的(排在最前面)
// 有时间戳的按时间升序排列
const timeA = a.createdAt || 0;
const timeB = b.createdAt || 0;
// 如果都没有时间戳,按名称排序
if (timeA === 0 && timeB === 0) {
return a.name.localeCompare(b.name, 'zh-CN');
}
// 如果只有一个没有时间戳,没有时间戳的排在前面
if (timeA === 0) return -1;
if (timeB === 0) return 1;
// 都有时间戳,按时间升序
return timeA - timeB;
});
return (
<div className="space-y-4">
{Object.values(providers).length === 0 ? (
{sortedProviders.length === 0 ? (
<div className="text-center py-12">
<div className="w-16 h-16 mx-auto mb-4 bg-[var(--color-bg-tertiary)] rounded-full flex items-center justify-center">
<Users size={24} className="text-[var(--color-text-tertiary)]" />
@@ -60,7 +81,7 @@ const ProviderList: React.FC<ProviderListProps> = ({
</div>
) : (
<div className="space-y-3">
{Object.values(providers).map((provider) => {
{sortedProviders.map((provider) => {
const isCurrent = provider.id === currentProviderId;
const apiUrl = getApiUrl(provider);

View File

@@ -3,6 +3,7 @@ export interface Provider {
name: string;
settingsConfig: Record<string, any>; // 应用配置对象Claude 为 settings.jsonCodex 为 { auth, config }
websiteUrl?: string;
createdAt?: number; // 添加时间戳(毫秒)
}
export interface AppConfig {