forked from raycast/extensions
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update repository-manager extension (raycast#14372)
* update repository-manager extension add customizable primary action fix list items indexes by ensuring they are unique * add release changelog * Add the possibility to mark a project as favorite to show it at the top of the list * Update CHANGELOG.md --------- Co-authored-by: Per Nielsen Tikær <per@raycast.com>
- Loading branch information
1 parent
ebb40d3
commit a43ecfc
Showing
14 changed files
with
282 additions
and
48 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -1,3 +1,10 @@ | ||
# Repository Manager Changelog | ||
|
||
## [Initial Version] - 2023-10-06 | ||
## [Add Customizable Primary Action] - 2024-09-07 | ||
- Fix issue with duplicated repositories not showing up because of not unique indexes | ||
- Add customizable primary action in settings | ||
|
||
## [Add Favorites] - 2024-09-07 | ||
- Add the possibility to mark a project as favorite to show it at the top of the list | ||
|
||
## [Initial Version] - 2023-10-06 |
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
57 changes: 57 additions & 0 deletions
57
extensions/repository-manager/src/components/AddToFavorites.tsx
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,57 @@ | ||
import { Action, Icon, LocalStorage } from '@raycast/api' | ||
import { withToast } from '../ui/toast' | ||
import { getFavoriteProjects } from '../helpers' | ||
import { Project } from '../project' | ||
|
||
type AddToFavoritesProps = { | ||
project: Project | ||
onFavoriteChange: (project: Project) => void | ||
} | ||
|
||
export default function AddToFavorites({ project, onFavoriteChange }: AddToFavoritesProps) { | ||
async function addProjectToFavorites() { | ||
const favorites = await getFavoriteProjects() | ||
|
||
if (favorites) { | ||
const newFavorites = [...favorites, project.name].filter((value, index, self) => self.indexOf(value) === index) | ||
await LocalStorage.setItem('favorites', JSON.stringify(newFavorites)) | ||
} else { | ||
await LocalStorage.setItem('favorites', JSON.stringify([project.name])) | ||
} | ||
|
||
onFavoriteChange(project) | ||
} | ||
|
||
async function removeProjectFromFavorites() { | ||
const favorites = await getFavoriteProjects() | ||
|
||
if (favorites) { | ||
const newFavorites = favorites.filter((value) => value !== project.name) | ||
await LocalStorage.setItem('favorites', JSON.stringify(newFavorites)) | ||
} | ||
|
||
onFavoriteChange(project) | ||
} | ||
|
||
async function toggleFavorite() { | ||
if (project.isFavorite) { | ||
await removeProjectFromFavorites() | ||
} else { | ||
await addProjectToFavorites() | ||
} | ||
} | ||
|
||
return ( | ||
<Action | ||
title={project.isFavorite ? 'Remove From Favorites' : 'Add to Favorites'} | ||
key="add-to-favorites" | ||
icon={project.isFavorite ? Icon.StarDisabled : Icon.Star} | ||
shortcut={{ modifiers: ['cmd', 'shift'], key: 'f' }} | ||
onAction={withToast({ | ||
action: toggleFavorite, | ||
onSuccess: () => (project.isFavorite ? 'Removed from favorites' : 'Added to favorites'), | ||
onFailure: () => (project.isFavorite ? 'Failed to remove from favorites' : 'Failed to add to favorites'), | ||
})} | ||
/> | ||
) | ||
} |
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
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
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
Oops, something went wrong.