Skip to content

Commit

Permalink
Merge pull request #59 from KevinBatdorf/change-starred-to-bookmarked
Browse files Browse the repository at this point in the history
Add bookmarked notes update
  • Loading branch information
KevinBatdorf authored Jun 10, 2023
2 parents ad38d6e + d761415 commit fd807ae
Show file tree
Hide file tree
Showing 17 changed files with 100 additions and 81 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Obsidian Changelog

## [Add Bookmark Support | Version 1.12.0] - 2023-06-012
- Update Starred notes to Bookmarks

## [Several Quality of Life Improvements | Version 1.11.0] - 2023-02-05

- Add `Silent Mode` preference for the `Append to Daily Note Command` which prevents the command from opening the daily note
Expand Down
18 changes: 9 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ This is a raycast extension with commands for the note taking and knowledge mana
- [Create Note](https://github.com/KevinBatdorf/obsidian-raycast#create-note)
- [Daily Note](https://github.com/KevinBatdorf/obsidian-raycast#daily-note)
- [Append to Daily Note](https://github.com/KevinBatdorf/obsidian-raycast#append-to-daily-note)
- [Starred Note](https://github.com/KevinBatdorf/obsidian-raycast#starred-notes)
- [Bookmarked Note](https://github.com/KevinBatdorf/obsidian-raycast#bookmarked-notes)
- [Obsidian Menu Bar Item](https://github.com/KevinBatdorf/obsidian-raycast#obsidian-menu-bar-item)

## Search Note
Expand Down Expand Up @@ -61,8 +61,8 @@ Depending on the primary action set in preferences, the keyboard shortcuts can b
- `opt + v` will paste the notes content to the app you used before raycast
- `opt + l` will copy a markdown link for the note to your clipboard
- `opt + u` will copy the obsidian URI for the note to your clipboard (see: [Obsidian URI](https://help.obsidian.md/Advanced+topics/Using+obsidian+URI))
- `opt + p` will star an unstarred note
- `opt + p` will unstar a starred note
- `opt + p` will bookmark a note
- `opt + p` will "unbookmark" a bookmarked note
- Reload Notes, will reload notes from the vault (useful if you have just created a new note)

The primary action (`enter`) can be changed in the extensions preferences.
Expand Down Expand Up @@ -133,20 +133,20 @@ This command will append text to the daily note from the selected vault. If a da

It requires the community plugin [Advanced Obsidian URI](https://obsidian.md/plugins?id=obsidian-advanced-uri) and the core plugin "Daily notes" to be installed and enabled.

## Starred Notes
## Bookmarked Notes

This command will open a list of your starred notes. All actions and preferences from the `Search Note` command are available. Starring or unstarring a note will reflect in Obsidians starred notes. Starring a note in Obsidian will also reflect in Raycast.
This command will open a list of your bookmarked notes. All actions and preferences from the `Search Note` command are available. Bookmarking or unbookmarking a note will reflect in Obsidians Bookmarked notes. Bookmarking a note in Obsidian will also reflect in Raycast.

Additional actions:

- `opt + r` will reset all starred notes for the selected vault
- `opt + r` will reset all bookmarked notes for the selected vault

<img width="1000" alt="Starred Notes Command" src="https://user-images.githubusercontent.com/67844154/178248422-2668fad8-8936-490b-8cf1-1dea0793712a.png">
<img width="1000" alt="Bookmarked Notes Command" src="https://user-images.githubusercontent.com/67844154/178248422-2668fad8-8936-490b-8cf1-1dea0793712a.png">

## Obsidian Menu Bar Item

Use this command to add a menu bar item to the top of the screen (Obsidian icon).
Clicking it will reveal a list of your vaults. You can view your starred notes, perform actions on them or open a daily note.
Clicking it will reveal a list of your vaults. You can view your bookmarked notes, perform actions on them or open a daily note.

<img width="635" alt="Obsidian Menu Bar Item" src="https://user-images.githubusercontent.com/67844154/180802502-3c6243ae-e3f9-4ddc-95ba-f205dab46721.png">

Expand Down Expand Up @@ -188,7 +188,7 @@ Clicking it will reveal a list of your vaults. You can view your starred notes,
- heading in which the appended text will be placed (if not set, the text will be appended to the end of the note)
- silent mode, if enabled, will not open the note if it is currently not opened in an Obsidian tab or pane (Obsidian has to be running)

### Starred Notes
### Bookmarked Notes

- templates for append actions
- show note content in detail view
Expand Down
3 changes: 3 additions & 0 deletions assets/bookmark.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -143,9 +143,9 @@
},
{
"name": "starredNotesCommand",
"title": "Starred Notes",
"title": "Bookmarked Notes",
"subtitle": "Obsidian",
"description": "Search, open, view, copy, paste and edit starred notes in Obsidian.",
"description": "Search, open, view, copy, paste and edit bookmarked notes in Obsidian.",
"mode": "view",
"arguments": [
{
Expand Down
10 changes: 9 additions & 1 deletion src/components/NoteList/NoteListItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,15 @@ export function NoteListItem(props: {
return !noteHasBeenMoved ? (
<List.Item
title={note.title}
accessories={[{ text: note.starred ? "⭐" : "" }]}
accessories={[
{
icon: note.bookmarked
? {
source: "bookmark.svg",
}
: null,
},
]}
detail={
<List.Item.Detail
markdown={filterContent(note.content)}
Expand Down
4 changes: 2 additions & 2 deletions src/components/NoteList/NoteListObsidian.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ import { renewCache } from "../../utils/data/cache";
export function NoteListObsidian(props: {
vault: Vault;
showTitle: boolean;
starred: boolean;
bookmarked: boolean;
searchArguments: SearchArguments;
}) {
const { showTitle, vault, searchArguments } = props;

const [allNotes] = useNotes(vault, props.starred);
const [allNotes] = useNotes(vault, props.bookmarked);
const [currentViewNoteList, dispatch] = useReducer(NoteReducer, allNotes);

return (
Expand Down
4 changes: 1 addition & 3 deletions src/components/NoteQuickLook.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,10 @@ import { filterContent } from "../utils/utils";
export function NoteQuickLook(props: { showTitle: boolean; note: Note }) {
const { note, showTitle } = props;

const title = note.starred ? `⭐️ ${note.title}` : note.title;

return (
<Detail
isLoading={note === undefined}
navigationTitle={showTitle ? title : ""}
navigationTitle={showTitle ? note.title : ""}
markdown={filterContent(note.content)}
/>
);
Expand Down
16 changes: 8 additions & 8 deletions src/obsidianMenuBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import { useNotes } from "./utils/hooks";
import { Vault } from "./utils/interfaces";
import { getObsidianTarget, ObsidianTargetType, useObsidianVaults, vaultPluginCheck } from "./utils/utils";

function StarredNotesList(props: { vault: Vault }) {
function BookmarkedNotesList(props: { vault: Vault }) {
const [notes] = useNotes(props.vault, true);
return (
<MenuBarExtra.Submenu title={props.vault.name} key={props.vault.path + "Starred Notes"}>
<MenuBarExtra.Submenu title={props.vault.name} key={props.vault.path + "Bookmarked Notes"}>
{notes.map((note) => (
<MenuBarExtra.Item
title={note.title}
Expand All @@ -21,11 +21,11 @@ function StarredNotesList(props: { vault: Vault }) {
);
}

function StarredNotesVaultSelection(props: { vaults: Vault[] }) {
function BookmarkedNotesVaultSelection(props: { vaults: Vault[] }) {
return (
<MenuBarExtra.Submenu title="Starred Notes" key={"Starred Notes"}>
<MenuBarExtra.Submenu title="Bookmarked Notes" key={"Bookmarked Notes"}>
{props.vaults.map((vault) => (
<StarredNotesList vault={vault} key={vault.path + "Starred Notes"} />
<BookmarkedNotesList vault={vault} key={vault.path + "Bookmarked Notes"} />
))}
</MenuBarExtra.Submenu>
);
Expand Down Expand Up @@ -65,9 +65,9 @@ function OpenVaultSelection(props: { vaults: Vault[] }) {
function ObsidianMenuBar(props: { vaults: Vault[] }) {
return (
<MenuBarExtra icon={ObsidianIconDynamicBold} tooltip="Obsidian">
<DailyNoteVaultSelection vaults={props.vaults}></DailyNoteVaultSelection>
<OpenVaultSelection vaults={props.vaults}></OpenVaultSelection>
<StarredNotesVaultSelection vaults={props.vaults}></StarredNotesVaultSelection>
<DailyNoteVaultSelection vaults={props.vaults} />
<OpenVaultSelection vaults={props.vaults} />
<BookmarkedNotesVaultSelection vaults={props.vaults} />
</MenuBarExtra>
);
}
Expand Down
6 changes: 4 additions & 2 deletions src/searchNoteCommand.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,14 @@ export default function Command(props: { arguments: SearchArguments }) {
<VaultSelection
vaults={vaults}
target={(vault: Vault) => (
<NoteListObsidian vault={vault} showTitle={true} starred={false} searchArguments={props.arguments} />
<NoteListObsidian vault={vault} showTitle={true} bookmarked={false} searchArguments={props.arguments} />
)}
/>
);
} else if (vaults.length == 1) {
return <NoteListObsidian vault={vaults[0]} showTitle={false} starred={false} searchArguments={props.arguments} />;
return (
<NoteListObsidian vault={vaults[0]} showTitle={false} bookmarked={false} searchArguments={props.arguments} />
);
} else {
noVaultPathsToast();
}
Expand Down
4 changes: 2 additions & 2 deletions src/starredNotesCommand.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ export default function Command(props: { arguments: SearchArguments }) {
<VaultSelection
vaults={vaults}
target={(vault: Vault) => (
<NoteListObsidian vault={vault} showTitle={true} starred={true} searchArguments={props.arguments} />
<NoteListObsidian vault={vault} showTitle={true} bookmarked={true} searchArguments={props.arguments} />
)}
/>
);
} else if (vaults.length == 1) {
return <NoteListObsidian vault={vaults[0]} showTitle={false} starred={true} searchArguments={props.arguments} />;
return <NoteListObsidian vault={vaults[0]} showTitle={false} bookmarked={true} searchArguments={props.arguments} />;
} else {
noVaultPathsToast();
}
Expand Down
22 changes: 13 additions & 9 deletions src/utils/actions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -147,32 +147,32 @@ export function QuickLookAction(props: { note: Note; notes: Note[]; vault: Vault
return <Action.Push title="Quick Look" target={<NoteQuickLook note={note} showTitle={true} />} icon={Icon.Eye} />;
}

export function StarNoteAction(props: { note: Note; vault: Vault }) {
export function BookmarkNoteAction(props: { note: Note; vault: Vault }) {
const { note, vault } = props;
const dispatch = useNotesDispatchContext();
return (
<Action
title="Star Note"
title="Bookmark Note"
shortcut={{ modifiers: ["opt"], key: "p" }}
onAction={() => {
dispatch({ type: NoteReducerActionType.Star, payload: { note: note, vault: vault } });
dispatch({ type: NoteReducerActionType.Bookmark, payload: { note: note, vault: vault } });
}}
icon={Icon.Star}
icon={Icon.Bookmark}
/>
);
}

export function UnstarNoteAction(props: { note: Note; vault: Vault }) {
export function UnbookmarkNoteAction(props: { note: Note; vault: Vault }) {
const { note, vault } = props;
const dispatch = useNotesDispatchContext();
return (
<Action
title="Unstar Note"
title="Unbookmark Note"
shortcut={{ modifiers: ["opt"], key: "p" }}
onAction={() => {
dispatch({ type: NoteReducerActionType.Unstar, payload: { note: note, vault: vault } });
dispatch({ type: NoteReducerActionType.Unbookmark, payload: { note: note, vault: vault } });
}}
icon={Icon.Star}
icon={Icon.Bookmark}
/>
);
}
Expand Down Expand Up @@ -282,7 +282,11 @@ export function NoteActions(props: { notes: Note[]; note: Note; vault: Vault })
<React.Fragment>
<ShowPathInFinderAction path={note.path} />
<ShowMentioningNotesAction vault={vault} str={note.title} notes={notes} />
{note.starred ? <UnstarNoteAction note={note} vault={vault} /> : <StarNoteAction note={note} vault={vault} />}
{note.bookmarked ? (
<UnbookmarkNoteAction note={note} vault={vault} />
) : (
<BookmarkNoteAction note={note} vault={vault} />
)}
<CopyCodeAction note={note} />
<EditNoteAction note={note} vault={vault} />
<AppendToNoteAction note={note} vault={vault} />
Expand Down
4 changes: 2 additions & 2 deletions src/utils/constants.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ export enum NoteAction {
Edit,
Delete,
Append,
Star,
Unstar,
Bookmark,
UnBookmark,
}

export enum PrimaryAction {
Expand Down
6 changes: 3 additions & 3 deletions src/utils/data/loader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { AUDIO_FILE_EXTENSIONS, VIDEO_FILE_EXTENSIONS } from "../constants";
import { Note, Vault, Media } from "../interfaces";
import {
getNoteFileContent,
getStarredNotePaths,
getBookmarkedNotePaths,
getUserIgnoreFilters,
prefExcludedFolders,
walkFilesHelper,
Expand All @@ -32,7 +32,7 @@ export class NoteLoader {
console.log("Loading Notes for vault: " + this.vault.path);
const notes: Note[] = [];
const files = this._getFiles();
const starred = getStarredNotePaths(this.vault);
const bookmarked = getBookmarkedNotePaths(this.vault);

for (const f of files) {
const comp = f.split("/");
Expand All @@ -48,7 +48,7 @@ export class NoteLoader {
path: f,
tags: tagsForString(noteContent),
content: noteContent,
starred: starred.includes(f.split(this.vault.path)[1].slice(1)),
bookmarked: bookmarked.includes(f.split(this.vault.path)[1].slice(1)),
};

notes.push(note);
Expand Down
26 changes: 13 additions & 13 deletions src/utils/data/reducers.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { deleteNoteFromCache, updateNoteInCache } from "./cache";
import { Note, Vault } from "../interfaces";
import { deleteNote, getNoteFileContent, starNote, unstarNote } from "../utils";
import { deleteNote, getNoteFileContent, bookmarkNote, unbookmarkNote } from "../utils";
import { tagsForNotes } from "../yaml";

export enum NoteReducerActionType {
Set,
Delete,
Star,
Unstar,
Bookmark,
Unbookmark,
Update,
Add,
}
Expand All @@ -25,14 +25,14 @@ export type NoteReducerAction =
};
}
| {
type: NoteReducerActionType.Star;
type: NoteReducerActionType.Bookmark;
payload: {
note: Note;
vault: Vault;
};
}
| {
type: NoteReducerActionType.Unstar;
type: NoteReducerActionType.Unbookmark;
payload: {
note: Note;
vault: Vault;
Expand Down Expand Up @@ -67,23 +67,23 @@ export function NoteReducer(notes: Note[], action: NoteReducerAction) {
return notes.filter((note) => note.path !== action.payload.note.path);
}

case NoteReducerActionType.Star: {
console.log("REDUCER STAR");
starNote(action.payload.vault, action.payload.note);
case NoteReducerActionType.Bookmark: {
console.log("REDUCER BOOKMARK");
bookmarkNote(action.payload.vault, action.payload.note);
return notes.map((note) => {
if (note.path === action.payload.note.path) {
note.starred = true;
note.bookmarked = true;
updateNoteInCache(action.payload.vault, note);
}
return note;
});
}
case NoteReducerActionType.Unstar: {
console.log("REDUCER UNSTAR");
unstarNote(action.payload.vault, action.payload.note);
case NoteReducerActionType.Unbookmark: {
console.log("REDUCER UNBOOKMARK");
unbookmarkNote(action.payload.vault, action.payload.note);
return notes.map((note) => {
if (note.path === action.payload.note.path) {
note.starred = false;
note.bookmarked = false;
updateNoteInCache(action.payload.vault, note);
}
return note;
Expand Down
6 changes: 3 additions & 3 deletions src/utils/hooks.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { getNotesFromCache } from "./data/cache";
import { Note, Vault } from "./interfaces";
import { NotesContext, NotesDispatchContext } from "./utils";

export function useNotes(vault: Vault, starred = false) {
export function useNotes(vault: Vault, bookmarked = false) {
/**
* The preferred way of loading notes inside the extension
*
Expand All @@ -15,8 +15,8 @@ export function useNotes(vault: Vault, starred = false) {

const [notes] = useState<Note[]>(notes_);
console.log("Using Notes");
if (starred) {
return [notes.filter((note: Note) => note.starred)] as const;
if (bookmarked) {
return [notes.filter((note: Note) => note.bookmarked)] as const;
} else {
return [notes] as const;
}
Expand Down
2 changes: 1 addition & 1 deletion src/utils/interfaces.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export interface Note {
path: string;
tags: string[];
content: string;
starred: boolean;
bookmarked: boolean;
}

export interface CodeBlock {
Expand Down
Loading

0 comments on commit fd807ae

Please sign in to comment.