8000 Feature/Page media relations dnd by ra3orblade · Pull Request #1356 · anyproto/anytype-ts · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Feature/Page media relations dnd #1356

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 19, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/scss/page/main/media.scss
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
> .side.right { padding-top: 0px; margin-top: 32px; border-top: 0px; }
}

.blocks.horizontal.withSidebar { width: 100%; padding: 16px 16px 80px 16px; }
.blocks.horizontal.withSidebar { max-width: 736px; width: 100%; padding: 16px 16px 80px 16px; }
.blocks.horizontal.withSidebar {
.inner { min-height: 0 !important; }
.block.blockMedia {
Expand Down
35 changes: 29 additions & 6 deletions src/ts/component/drag/provider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import raf from 'raf';
import { observer } from 'mobx-react';
import { throttle } from 'lodash';
import { DragLayer } from 'Component';
import { I, C, S, U, J, focus, keyboard, scrollOnMove, Action, Preview, analytics } from 'Lib';
import { I, C, S, U, J, focus, keyboard, scrollOnMove, Action, Preview, analytics, Relation } from 'Lib';

interface Props {
children?: React.ReactNode;
Expand Down Expand Up @@ -356,12 +356,35 @@ const DragProvider = observer(forwardRef<DragProviderRefProps, Props>((props, re
};

case I.DropType.Relation: {
ids.forEach((id: string) => {
const relation = S.Record.getRelationById(id);
if (relation) {
C.BlockCreate(targetContextId, targetId, position, { type: I.BlockType.Relation, content: { key: relation.relationKey } });
const object = S.Detail.get(targetContextId, targetContextId);

if (U.Object.isInFileLayouts(object.layout)) {
const type = S.Record.getTypeById(object.type);

if (!type) {
break;
};

const list = Relation.getArrayValue(type.recommendedFileRelations);
const idx = list.findIndex(id => id == targetId);
const dir = position == I.BlockPosition.Bottom ? 1 : -1;

if (idx < 0) {
break;
};
});

for (let i = 0; i < ids.length; i++) {
list.splice(Math.max(0, i + idx + dir), 0, ids[i]);
};

C.ObjectListSetDetails([ type.id ], [ { key: 'recommendedFileRelations', value: U.Common.arrayUnique(list) } ]);
} else {
const keys = ids.map(id => S.Record.getRelationById(id)?.relationKey).filter(it => it);

keys.forEach((key: string) => {
C.BlockCreate(targetContextId, targetId, position, { type: I.BlockType.Relation, content: { key } });
});
};
break;
};
};
Expand Down
4 changes: 1 addition & 3 deletions src/ts/component/page/main/media.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ const PageMainMedia = observer(class PageMainMedia extends React.Component<I.Pag
const allowedDetails = S.Block.checkFlags(rootId, rootId, [ I.RestrictionObject.Details ]);
const allowedRelation = false; //S.Block.checkFlags(rootId, rootId, [ I.RestrictionObject.Relation ]);
const type = S.Record.getTypeById(object.type);
const skipKeys = [ 'description' ];
const showSidebar = S.Common.getShowSidebarRight(isPopup);

if (isDeleted) {
Expand All @@ -59,9 +58,8 @@ const PageMainMedia = observer(class PageMainMedia extends React.Component<I.Pag
map(it => S.Record.getRelationById(it));

relations.unshift(S.Record.getRelationByKey('description'));
relations = relations.filter(it => it && !skipKeys.includes(it.relationKey));
relations = relations.filter(it => it);
relations = S.Record.checkHiddenObjects(relations);
relations.sort((c1, c2) => U.Data.sortByFormat(c1, c2));

const isVideo = file?.isFileVideo();
const isImage = file?.isFileImage();
Expand Down
0