1
0
Fork 0
mirror of https://github.com/anyproto/anytype-ts.git synced 2025-06-07 21:47:02 +09:00

JS-6448: Bookmark templateId integration

This commit is contained in:
Andrew Simachev 2025-02-18 17:26:38 +01:00
parent 5a86e9c96a
commit e5b7522bb1
No known key found for this signature in database
GPG key ID: 1DFE44B21443F0EF
8 changed files with 23 additions and 12 deletions

View file

@ -413,11 +413,11 @@ const Create = observer(class Create extends React.Component<I.PageComponent, St
this.setState({ isLoading: true, error: '' });
const details = Object.assign({ name: this.refName?.getValue(), origin: I.ObjectOrigin.Webclipper }, this.details);
const type = details.type;
const type = S.Record.getTypeByKey(details.type);
delete(details.type);
C.ObjectCreateFromUrl(details, S.Common.space, type, this.url, withContent, (message: any) => {
C.ObjectCreateFromUrl(details, S.Common.space, type?.uniqueKey, this.url, withContent, type?.defaultTemplateId, (message: any) => {
this.setState({ isLoading: false });
if (message.error.code) {

View file

@ -27,7 +27,7 @@ html.anytypeWebclipper-popup { width: 268px; }
.input, .select { height: 32px; padding: 0px 10px; }
.select { display: flex; align-items: center; padding-right: 20px; }
.textarea { padding: 10px; resize: none; height: 68px; display: block; }
.buttonsWrapper { display: flex; flex-direction: column; justify-content: center; gap: 8px 0px; margin: 16px 0px 0px 0px; }
.buttonsWrapper { display: flex; flex-direction: column; justify-content: center; gap: 8px 0px; margin: 16px 0px 0px 0px; align-items: center; }
.loaderWrapper { position: fixed; left: 0px; top: 0px; width: 100%; height: 100%; background: var(--color-bg-loader); z-index: 10; }
.error { @include text-small; margin: 1em 0px 0px 0px; }

View file

@ -254,8 +254,9 @@ const BlockBookmark = observer(class BlockBookmark extends React.Component<I.Blo
onChangeUrl (e: any, url: string) {
const { rootId, block } = this.props;
const bookmark = S.Record.getBookmarkType();
C.BlockBookmarkFetch(rootId, block.id, url);
C.BlockBookmarkFetch(rootId, block.id, url, bookmark?.defaultTemplateId);
};
resize () {

View file

@ -630,6 +630,7 @@ const ChatForm = observer(class ChatForm extends React.Component<Props, State> {
const bookmarks = list.filter(it => it.isTmp && U.Object.isBookmarkLayout(it.layout));
const fl = files.length;
const bl = bookmarks.length;
const bookmark = S.Record.getBookmarkType();
const attachments = (this.state.attachments || []).filter(it => !it.isTmp).map(it => ({ target: it.id, type: I.AttachmentType.Link }));
loader.addClass('active');
@ -710,7 +711,7 @@ const ChatForm = observer(class ChatForm extends React.Component<Props, State> {
let n = 0;
for (const item of bookmarks) {
C.ObjectCreateFromUrl({ source: item.source }, S.Common.space, J.Constant.typeKey.bookmark, item.source, true, (message: any) => {
C.ObjectCreateFromUrl({ source: item.source }, S.Common.space, J.Constant.typeKey.bookmark, item.source, true, bookmark.defaultTemplateId, (message: any) => {
n++;
if (message.objectId) {

View file

@ -2006,7 +2006,9 @@ const EditorPage = observer(class EditorPage extends React.Component<Props, Stat
};
case 'block': {
C.BlockBookmarkCreateAndFetch(rootId, focused, position, url, (message: any) => {
const bookmark = S.Record.getBookmarkType();
C.BlockBookmarkCreateAndFetch(rootId, focused, position, url, bookmark?.defaultTemplateId, (message: any) => {
if (!message.error.code) {
analytics.event('CreateBlock', { middleTime: message.middleTime, type: I.BlockType.Bookmark });
};

View file

@ -57,6 +57,7 @@ class MenuDataviewCreateBookmark extends React.Component<I.Menu, State> {
const { onSubmit, route } = data;
const value = this.ref.getValue();
const details = data.details || {};
const bookmark = S.Record.getBookmarkType();
if (!value) {
return;
@ -64,7 +65,7 @@ class MenuDataviewCreateBookmark extends React.Component<I.Menu, State> {
this.setState({ loading: true });
C.ObjectCreateBookmark({ ...details, source: value }, S.Common.space, (message: any) => {
C.ObjectCreateBookmark({ ...details, source: value }, S.Common.space, bookmark?.defaultTemplateId, (message: any) => {
this.setState({ loading: false });
if (message.error.code) {

View file

@ -482,23 +482,25 @@ export const BlockSplit = (contextId: string, blockId: string, range: I.TextRang
dispatcher.request(BlockSplit.name, request, callBack);
};
export const BlockBookmarkFetch = (contextId: string, blockId: string, url: string, callBack?: (message: any) => void) => {
export const BlockBookmarkFetch = (contextId: string, blockId: string, url: string, templateId: string, callBack?: (message: any) => void) => {
const request = new Rpc.BlockBookmark.Fetch.Request();
request.setContextid(contextId);
request.setBlockid(blockId);
request.setUrl(url);
request.setTemplateid(templateId);
dispatcher.request(BlockBookmarkFetch.name, request, callBack);
};
export const BlockBookmarkCreateAndFetch = (contextId: string, targetId: string, position: I.BlockPosition, url: string, callBack?: (message: any) => void) => {
export const BlockBookmarkCreateAndFetch = (contextId: string, targetId: string, position: I.BlockPosition, url: string, templateId: string, callBack?: (message: any) => void) => {
const request = new Rpc.BlockBookmark.CreateAndFetch.Request();
request.setContextid(contextId);
request.setTargetid(targetId);
request.setPosition(position as number);
request.setUrl(url);
request.setTemplateid(templateId);
dispatcher.request(BlockBookmarkCreateAndFetch.name, request, callBack);
};
@ -1271,16 +1273,17 @@ export const ObjectCreateSet = (sources: string[], details: any, templateId: str
dispatcher.request(ObjectCreateSet.name, request, callBack);
};
export const ObjectCreateBookmark = (details: any, spaceId: string, callBack?: (message: any) => void) => {
export const ObjectCreateBookmark = (details: any, spaceId: string, templateId: string, callBack?: (message: any) => void) => {
const request = new Rpc.Object.CreateBookmark.Request();
request.setDetails(Encode.struct(details));
request.setSpaceid(spaceId);
request.setTemplateid(templateId);
dispatcher.request(ObjectCreateBookmark.name, request, callBack);
};
export const ObjectCreateFromUrl = (details: any, spaceId: string, typeKey: string, url: string, withContent: boolean, callBack?: (message: any) => void) => {
export const ObjectCreateFromUrl = (details: any, spaceId: string, typeKey: string, url: string, withContent: boolean, templateId: string, callBack?: (message: any) => void) => {
const request = new Rpc.Object.CreateFromUrl.Request();
request.setDetails(Encode.struct(details));
@ -1288,6 +1291,7 @@ export const ObjectCreateFromUrl = (details: any, spaceId: string, typeKey: stri
request.setObjecttypeuniquekey(typeKey);
request.setUrl(url);
request.setAddpagecontent(withContent);
request.setTemplateid(templateId);
dispatcher.request(ObjectCreateFromUrl.name, request, callBack);
};

View file

@ -1155,7 +1155,9 @@ class UtilMenu {
};
if (url) {
C.ObjectCreateBookmark({ ...details, source: url }, S.Common.space, (message: any) => {
const bookmark = S.Record.getBookmarkType();
C.ObjectCreateBookmark({ ...details, source: url }, S.Common.space, bookmark?.defaultTemplateId, (message: any) => {
cb(message.details, message.middleTime);
});
} else {