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:
@@ -134,6 +134,7 @@ function App() {
|
|||||||
const newProvider: Provider = {
|
const newProvider: Provider = {
|
||||||
...provider,
|
...provider,
|
||||||
id: generateId(),
|
id: generateId(),
|
||||||
|
createdAt: Date.now(), // 添加创建时间戳
|
||||||
};
|
};
|
||||||
await window.api.addProvider(newProvider, activeApp);
|
await window.api.addProvider(newProvider, activeApp);
|
||||||
await loadProviders();
|
await loadProviders();
|
||||||
|
|||||||
@@ -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 (
|
return (
|
||||||
<div className="space-y-4">
|
<div className="space-y-4">
|
||||||
{Object.values(providers).length === 0 ? (
|
{sortedProviders.length === 0 ? (
|
||||||
<div className="text-center py-12">
|
<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">
|
<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)]" />
|
<Users size={24} className="text-[var(--color-text-tertiary)]" />
|
||||||
@@ -60,7 +81,7 @@ const ProviderList: React.FC<ProviderListProps> = ({
|
|||||||
</div>
|
</div>
|
||||||
) : (
|
) : (
|
||||||
<div className="space-y-3">
|
<div className="space-y-3">
|
||||||
{Object.values(providers).map((provider) => {
|
{sortedProviders.map((provider) => {
|
||||||
const isCurrent = provider.id === currentProviderId;
|
const isCurrent = provider.id === currentProviderId;
|
||||||
const apiUrl = getApiUrl(provider);
|
const apiUrl = getApiUrl(provider);
|
||||||
|
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ export interface Provider {
|
|||||||
name: string;
|
name: string;
|
||||||
settingsConfig: Record<string, any>; // 应用配置对象:Claude 为 settings.json;Codex 为 { auth, config }
|
settingsConfig: Record<string, any>; // 应用配置对象:Claude 为 settings.json;Codex 为 { auth, config }
|
||||||
websiteUrl?: string;
|
websiteUrl?: string;
|
||||||
|
createdAt?: number; // 添加时间戳(毫秒)
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface AppConfig {
|
export interface AppConfig {
|
||||||
|
|||||||
Reference in New Issue
Block a user