-
-
Notifications
You must be signed in to change notification settings - Fork 111
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
[sync] Add syncing with link to relation #633
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ pkgs ? import <nixpkgs> {} }: | ||
|
||
pkgs.mkShell { | ||
|
||
buildInputs = [ | ||
pkgs.nodejs | ||
pkgs.pnpm | ||
]; | ||
|
||
} |
Original file line number | Diff line number | Diff line change | ||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,72 @@ | ||||||||||||||||
import { isFullPage } from '@notionhq/client'; | ||||||||||||||||
|
||||||||||||||||
import { getGlobalNotero, getXULElementById } from '../utils'; | ||||||||||||||||
import { setMenuItems } from '../utils/elements'; | ||||||||||||||||
|
||||||||||||||||
import { getNoteroPref, NoteroPref } from './notero-pref'; | ||||||||||||||||
|
||||||||||||||||
type DialogArguments = { | ||||||||||||||||
accepted: boolean; | ||||||||||||||||
associatedLink: string; | ||||||||||||||||
syncEnabled: boolean; | ||||||||||||||||
}; | ||||||||||||||||
|
||||||||||||||||
class Dialog { | ||||||||||||||||
private collectionDialogContainer!: XUL.XULElement; | ||||||||||||||||
private associatedLinkElement!: XUL.MenuListElement; | ||||||||||||||||
private syncEnabledElement!: XUL.CheckboxElement; | ||||||||||||||||
private params!: DialogArguments; | ||||||||||||||||
|
||||||||||||||||
public async init(): Promise<void> { | ||||||||||||||||
await Zotero.uiReadyPromise; | ||||||||||||||||
|
||||||||||||||||
/* eslint-disable @typescript-eslint/no-non-null-assertion */ | ||||||||||||||||
this.params = window.arguments![0]! as DialogArguments; | ||||||||||||||||
Comment on lines
+23
to
+24
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Consider safer type assertions. The non-null assertion on - this.params = window.arguments![0]! as DialogArguments;
+ if (!window.arguments?.[0]) {
+ throw new Error('Dialog initialized without arguments');
+ }
+ this.params = window.arguments[0] as DialogArguments; 📝 Committable suggestion
Suggested change
|
||||||||||||||||
|
||||||||||||||||
/* eslint-disable @typescript-eslint/no-non-null-assertion */ | ||||||||||||||||
this.collectionDialogContainer = getXULElementById( | ||||||||||||||||
'notero-collection-dialog', | ||||||||||||||||
)!; | ||||||||||||||||
this.associatedLinkElement = getXULElementById('notero-associatedLink')!; | ||||||||||||||||
|
||||||||||||||||
const notero = getGlobalNotero(); | ||||||||||||||||
const pref = getNoteroPref(NoteroPref.linkedCollectionID); | ||||||||||||||||
if (pref) { | ||||||||||||||||
const client = await notero.getNotionClient(); | ||||||||||||||||
const res = await client.databases.query({ database_id: pref }); | ||||||||||||||||
const results = res.results | ||||||||||||||||
.map((result: (typeof res.results)[0]) => { | ||||||||||||||||
if (isFullPage(result)) { | ||||||||||||||||
return { | ||||||||||||||||
value: result.id, | ||||||||||||||||
label: Object.values(result.properties).find( | ||||||||||||||||
(prop) => prop.type === 'title', | ||||||||||||||||
)?.title[0]!.plain_text, | ||||||||||||||||
}; | ||||||||||||||||
} | ||||||||||||||||
}) | ||||||||||||||||
.filter((item) => item != undefined); | ||||||||||||||||
setMenuItems(this.associatedLinkElement, results); | ||||||||||||||||
} | ||||||||||||||||
auscyber marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||
|
||||||||||||||||
this.associatedLinkElement.value = this.params.associatedLink; | ||||||||||||||||
this.syncEnabledElement = getXULElementById('notero-syncEnabled')!; | ||||||||||||||||
this.syncEnabledElement.checked = this.params.syncEnabled; | ||||||||||||||||
document.addEventListener('dialogaccept', () => { | ||||||||||||||||
return this.accept(); | ||||||||||||||||
}); | ||||||||||||||||
} | ||||||||||||||||
accept(): boolean { | ||||||||||||||||
// @ts-expect-error dataOut is not defined in the type | ||||||||||||||||
window.arguments![0]!.dataOut = { | ||||||||||||||||
associatedLink: this.associatedLinkElement.value, | ||||||||||||||||
syncEnabled: this.syncEnabledElement.checked, | ||||||||||||||||
accepted: true, | ||||||||||||||||
}; | ||||||||||||||||
return true; | ||||||||||||||||
} | ||||||||||||||||
Comment on lines
+59
to
+67
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Improve type safety in the accept method. The current implementation uses @ts-expect-error and unsafe type assertions. Consider extending the window type or using a safer approach. +interface DialogWindow extends Window {
+ arguments: [{
+ dataOut?: DialogArguments;
+ } & DialogArguments];
+}
+
accept(): boolean {
- // @ts-expect-error dataOut is not defined in the type
- window.arguments![0]!.dataOut = {
+ (window as DialogWindow).arguments[0].dataOut = {
associatedLink: this.associatedLinkElement.value,
syncEnabled: this.syncEnabledElement.checked,
accepted: true,
};
return true;
}
|
||||||||||||||||
} | ||||||||||||||||
|
||||||||||||||||
module.exports = { | ||||||||||||||||
dialog: new Dialog(), | ||||||||||||||||
}; |
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,48 @@ | ||||||||||
<?xml version="1.0"?> | ||||||||||
<?xml-stylesheet href="chrome://global/skin/" type="text/css"?> <?xml-stylesheet | ||||||||||
href="chrome://zotero/skin/zotero.css" type="text/css"?> <?xml-stylesheet | ||||||||||
href="chrome://zotero-platform/content/zotero.css" type="text/css"?> | ||||||||||
|
||||||||||
<window | ||||||||||
type="child" | ||||||||||
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" | ||||||||||
xmlns:html="http://www.w3.org/1999/xhtml" | ||||||||||
style="width: 100px; height: 100px" | ||||||||||
buttons="cancel,accept" | ||||||||||
Comment on lines
+10
to
+11
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Adjust window dimensions The hardcoded window dimensions (100x100) seem too small for the content. Consider:
- style="width: 100px; height: 100px"
+ style="min-width: 400px; min-height: 200px" 📝 Committable suggestion
Suggested change
|
||||||||||
onload="notero.dialog.init();" | ||||||||||
> | ||||||||||
Comment on lines
+12
to
+13
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Remove duplicate initialization The buttons="cancel,accept"
- onload="notero.dialog.init();"
>
<script>
Services.scriptloader.loadSubScript( Also applies to: 28-29 |
||||||||||
<script> | ||||||||||
Services.scriptloader.loadSubScript( | ||||||||||
'chrome://zotero/content/customElements.js', | ||||||||||
this, | ||||||||||
); | ||||||||||
|
||||||||||
Services.scriptloader.loadSubScript( | ||||||||||
'chrome://notero/content/prefs/dialog.js', | ||||||||||
this, | ||||||||||
); | ||||||||||
</script> | ||||||||||
<dialog | ||||||||||
id="notero-collection-dialog" | ||||||||||
title="Collection Properties" | ||||||||||
onload="notero.dialog.init();" | ||||||||||
> | ||||||||||
<div> | ||||||||||
<label>Collection Settings</label> | ||||||||||
<grid> | ||||||||||
<rows> | ||||||||||
<row> | ||||||||||
<label value="Associated Link:" /> | ||||||||||
<menulist id="notero-associatedLink"> | ||||||||||
<menupopup /> | ||||||||||
</menulist> | ||||||||||
</row> | ||||||||||
<row> | ||||||||||
<label value="Sync Enabled:" /> | ||||||||||
<checkbox id="notero-syncEnabled" /> | ||||||||||
</row> | ||||||||||
</rows> | ||||||||||
</grid> | ||||||||||
</div> | ||||||||||
</dialog> | ||||||||||
</window> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Add error handling for chrome registration.
The chrome registration process should include error handling to ensure proper initialization.