Skip to content

Commit

Permalink
fix: relation
Browse files Browse the repository at this point in the history
  • Loading branch information
qinluhe committed Jul 16, 2024
1 parent 568dcf3 commit b05c202
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,7 @@ export class AFClientService implements AFService {
this.publishViewLoaded.add(name);
}

if (!this.cacheDatabaseRowDocMap.has(name)) {
this.cacheDatabaseRowDocMap.set(name, rowMapDoc);
}
this.cacheDatabaseRowDocMap.set(name, rowMapDoc);

return doc;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ import {
import { RelationCell, RelationCellData } from '@/application/database-yjs/cell.type';
import { ViewMeta } from '@/application/db/tables/view_metas';
import { RelationPrimaryValue } from '@/components/database/components/cell/relation/RelationPrimaryValue';
import React, { useCallback, useContext, useEffect, useState } from 'react';
import { debounce } from 'lodash-es';
import React, { useCallback, useContext, useEffect, useMemo, useState } from 'react';

function RelationItems({ style, cell, fieldId }: { cell: RelationCell; fieldId: string; style?: React.CSSProperties }) {
const viewId = useContext(DatabaseContext)?.iidIndex;
Expand Down Expand Up @@ -59,12 +60,20 @@ function RelationItems({ style, cell, fieldId }: { cell: RelationCell; fieldId:
const { rows } = await getViewRowsMap(relatedViewId);

setRows(rows);
handleUpdateRowIds(rows);
} catch (e) {
console.error(e);
}
})();
}, [getViewRowsMap, relatedViewId, relatedFieldId, handleUpdateRowIds]);
});

const debounceUpdateRowIds = useMemo(() => {
return debounce(handleUpdateRowIds, 500);
}, [handleUpdateRowIds]);

useEffect(() => {
if (!rows) return;
debounceUpdateRowIds(rows);
}, [rows, debounceUpdateRowIds]);

useEffect(() => {
const observerHandler = () => (rows ? handleUpdateRowIds(rows) : setRowIds([]));
Expand All @@ -80,6 +89,8 @@ function RelationItems({ style, cell, fieldId }: { cell: RelationCell; fieldId:
try {
const viewDoc = await loadView?.(relatedViewId);

console.log('View not loaded, fetching view', relatedViewId);

if (!viewDoc) {
throw new Error('No access');
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ export function RelationPrimaryValue({ rowDoc, fieldId }: { rowDoc: YDoc; fieldI
};

onRowChange();
data?.observe(onRowChange);
data?.observeDeep(onRowChange);
return () => {
data?.unobserve(onRowChange);
data?.unobserveDeep(onRowChange);
};
}, [rowDoc]);

Expand Down

0 comments on commit b05c202

Please sign in to comment.