-
Notifications
You must be signed in to change notification settings - Fork 103
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
port js to ts #1270
Merged
Merged
port js to ts #1270
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
import FlexContainer from "./containers/flex_container.js"; | ||
import OpenNoteButtonWidget from "./buttons/open_note_button_widget.js"; | ||
import BookmarkFolderWidget from "./buttons/bookmark_folder.js"; | ||
import froca from "../services/froca.js"; | ||
import utils from "../services/utils.js"; | ||
import type { EventData } from "../components/app_context.js"; | ||
import type Component from "../components/component.js"; | ||
|
||
interface BookmarkButtonsSettings { | ||
titlePlacement?: string; | ||
} | ||
|
||
export default class BookmarkButtons extends FlexContainer<Component> { | ||
private settings: BookmarkButtonsSettings; | ||
private noteIds: string[]; | ||
|
||
constructor(isHorizontalLayout: boolean) { | ||
super(isHorizontalLayout ? "row" : "column"); | ||
|
||
this.contentSized(); | ||
this.settings = {}; | ||
this.noteIds = []; | ||
} | ||
|
||
async refresh(): Promise<void> { | ||
this.$widget.empty(); | ||
this.children = []; | ||
this.noteIds = []; | ||
|
||
const bookmarkParentNote = await froca.getNote("_lbBookmarks"); | ||
|
||
if (!bookmarkParentNote) { | ||
return; | ||
} | ||
|
||
for (const note of await bookmarkParentNote.getChildNotes()) { | ||
this.noteIds.push(note.noteId); | ||
|
||
let buttonWidget: OpenNoteButtonWidget | BookmarkFolderWidget = note.isLabelTruthy("bookmarkFolder") | ||
? new BookmarkFolderWidget(note) | ||
: new OpenNoteButtonWidget(note).class("launcher-button"); | ||
|
||
if (this.settings.titlePlacement) { | ||
if (!('settings' in buttonWidget)) { | ||
(buttonWidget as any).settings = {}; | ||
} | ||
|
||
(buttonWidget as any).settings.titlePlacement = this.settings.titlePlacement; | ||
} | ||
|
||
this.child(buttonWidget); | ||
|
||
this.$widget.append(buttonWidget.render()); | ||
|
||
buttonWidget.refreshIcon(); | ||
} | ||
|
||
utils.reloadTray(); | ||
} | ||
|
||
initialRenderCompleteEvent(): void { | ||
this.refresh(); | ||
} | ||
|
||
entitiesReloadedEvent({ loadResults }: EventData<"entitiesReloaded">): void { | ||
if (loadResults.getBranchRows().find((branch) => branch.parentNoteId === "_lbBookmarks")) { | ||
this.refresh(); | ||
} | ||
|
||
if (loadResults.getAttributeRows().find((attr) => | ||
attr.type === "label" && | ||
attr.name && ["iconClass", "workspaceIconClass", "bookmarkFolder"].includes(attr.name) && | ||
attr.noteId && this.noteIds.includes(attr.noteId) | ||
)) { | ||
this.refresh(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 0 additions & 49 deletions
49
src/public/app/widgets/buttons/show_highlights_list_widget_button.js
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
I don't think there's a need to explicitly declare the return type of functions here.
I personally don't mind it, but I haven't seen that being done across the TriliumNext codebase, but I'll leave it to @eliandoran to decide :-)
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.
@pano9000 , indeed generally it's not needed.
The only case when we should add is when the return type is non-obvious (i.e. there are multiple return points, each forming the data in a different way).