mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-14 13:25:12 +00:00
fix(core): migration favorite appear again (#7768)
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import { IconButton, useConfirmModal } from '@affine/component';
|
||||
import { track } from '@affine/core/mixpanel';
|
||||
import { ExplorerTreeRoot } from '@affine/core/modules/explorer/views/tree';
|
||||
import { FavoriteItemsAdapter } from '@affine/core/modules/properties';
|
||||
import { MigrationFavoriteItemsAdapter } from '@affine/core/modules/properties';
|
||||
import { Trans, useI18n } from '@affine/i18n';
|
||||
import { BroomIcon, HelpIcon } from '@blocksuite/icons/rc';
|
||||
import { DocsService, useLiveData, useServices } from '@toeverything/infra';
|
||||
@@ -15,17 +15,18 @@ import * as styles from './styles.css';
|
||||
export const ExplorerMigrationFavorites = () => {
|
||||
const t = useI18n();
|
||||
|
||||
const { favoriteItemsAdapter, docsService } = useServices({
|
||||
FavoriteItemsAdapter,
|
||||
const { migrationFavoriteItemsAdapter, docsService } = useServices({
|
||||
MigrationFavoriteItemsAdapter,
|
||||
DocsService,
|
||||
});
|
||||
|
||||
const docs = useLiveData(docsService.list.docs$);
|
||||
const trashDocs = useLiveData(docsService.list.trashDocs$);
|
||||
const migrated = useLiveData(migrationFavoriteItemsAdapter.migrated$);
|
||||
const { openConfirmModal } = useConfirmModal();
|
||||
|
||||
const favorites = useLiveData(
|
||||
favoriteItemsAdapter.favorites$.map(favs => {
|
||||
migrationFavoriteItemsAdapter.favorites$.map(favs => {
|
||||
return favs.filter(fav => {
|
||||
if (fav.type === 'doc') {
|
||||
return (
|
||||
@@ -57,10 +58,10 @@ export const ExplorerMigrationFavorites = () => {
|
||||
cancelText:
|
||||
t['com.affine.rootAppSidebar.migration-data.clean-all.cancel'](),
|
||||
onConfirm() {
|
||||
favoriteItemsAdapter.clearAll();
|
||||
migrationFavoriteItemsAdapter.markFavoritesMigrated();
|
||||
},
|
||||
});
|
||||
}, [favoriteItemsAdapter, openConfirmModal, t]);
|
||||
}, [migrationFavoriteItemsAdapter, openConfirmModal, t]);
|
||||
|
||||
const handleClickHelp = useCallback(() => {
|
||||
openConfirmModal({
|
||||
@@ -85,7 +86,7 @@ export const ExplorerMigrationFavorites = () => {
|
||||
track.$.navigationPanel.migrationData.openMigrationDataHelp();
|
||||
}, [handleClickClear, openConfirmModal, t]);
|
||||
|
||||
if (favorites.length === 0) {
|
||||
if (favorites.length === 0 || migrated) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
export {
|
||||
CompatibleFavoriteItemsAdapter,
|
||||
MigrationFavoriteItemsAdapter as FavoriteItemsAdapter,
|
||||
MigrationFavoriteItemsAdapter,
|
||||
WorkspacePropertiesAdapter,
|
||||
} from './services/adapter';
|
||||
export { WorkspaceLegacyProperties } from './services/legacy-properties';
|
||||
|
||||
@@ -159,8 +159,8 @@ export class WorkspacePropertiesAdapter extends Service {
|
||||
/**
|
||||
* After the user completes the migration, call this function to clear the favorite data
|
||||
*/
|
||||
cleanupFavorites() {
|
||||
this.proxy.favorites = {};
|
||||
markFavoritesMigrated() {
|
||||
this.proxy.favoritesMigrated = true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -173,14 +173,18 @@ export class MigrationFavoriteItemsAdapter extends Service {
|
||||
this.getItems().filter(i => i.value)
|
||||
);
|
||||
|
||||
migrated$ = this.adapter.properties$.map(
|
||||
props => props.favoritesMigrated ?? false
|
||||
);
|
||||
|
||||
getItems() {
|
||||
return Object.entries(this.adapter.favorites ?? {})
|
||||
.filter(([k]) => k.includes(':'))
|
||||
.map(([, v]) => v);
|
||||
}
|
||||
|
||||
clearAll() {
|
||||
this.adapter.cleanupFavorites();
|
||||
markFavoritesMigrated() {
|
||||
this.adapter.markFavoritesMigrated();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -104,6 +104,7 @@ export const WorkspaceAffinePropertiesSchema = z.object({
|
||||
schema: WorkspaceAffinePropertiesSchemaSchema.optional(),
|
||||
favorites: z.record(WorkspaceFavoriteItemSchema).optional(),
|
||||
pageProperties: z.record(WorkspacePagePropertiesSchema).optional(),
|
||||
favoritesMigrated: z.boolean().optional(),
|
||||
});
|
||||
|
||||
export type PageInfoCustomPropertyMeta = z.infer<
|
||||
|
||||
Reference in New Issue
Block a user