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