Files
AFFiNE/packages/frontend/core/src/utils/user-setting.ts
EYHN 13d882d6d8 refactor(core): refactor collection to use new filter system (#12228)
<!-- This is an auto-generated comment: release notes by coderabbit.ai -->
## Summary by CodeRabbit

- **New Features**
  - Introduced a new Collection entity and store with reactive management and real-time updates.
  - Added reactive favorite and shared filters with expanded filtering options.
- **Refactor**
  - Overhauled collection and filtering logic for better performance and maintainability.
  - Replaced legacy filtering UI and logic with a streamlined, service-driven rules system.
  - Updated collection components to use reactive data streams and simplified props.
  - Simplified collection creation by delegating ID generation and instantiation to the service layer.
  - Removed deprecated hooks and replaced state-based filtering with observable-driven filtering.
- **Bug Fixes**
  - Improved accuracy and consistency of tag and favorite filtering in collections.
- **Chores**
  - Removed deprecated and unused filter-related files, types, components, and styles to reduce complexity.
  - Cleaned up imports and removed unused code across multiple components.
- **Documentation**
  - Corrected inline documentation for improved clarity.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
2025-05-13 08:28:02 +00:00

36 lines
912 B
TypeScript

import type { Workspace } from '@blocksuite/affine/store';
import { nanoid } from 'nanoid';
import type { Map as YMap } from 'yjs';
import { Doc as YDoc } from 'yjs';
export class UserSetting {
constructor(
private readonly docCollection: Workspace,
private readonly userId: string
) {}
get setting(): YDoc {
const rootDoc = this.docCollection.doc;
const settingMap = rootDoc.getMap('settings') as YMap<YDoc>;
if (!settingMap.has(this.userId)) {
settingMap.set(
this.userId,
new YDoc({
guid: nanoid(),
})
);
}
return settingMap.get(this.userId) as YDoc;
}
get loaded(): Promise<void> {
if (!this.setting.isLoaded) {
this.setting.load();
}
return this.setting.whenLoaded;
}
}
export const getUserSetting = (docCollection: Workspace, userId: string) => {
return new UserSetting(docCollection, userId);
};