-
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.
- Loading branch information
1 parent
87eca0a
commit 20e5b83
Showing
9 changed files
with
224 additions
and
28 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import { ActionSheetOptions, useIonActionSheet } from '@ionic/react' | ||
import { HookOverlayOptions } from '@ionic/react/dist/types/hooks/HookOverlayOptions' | ||
import { StarRole, db } from '../db' | ||
import { useEditStarRoleModal } from './edit/useEditStarRoleModal' | ||
|
||
// TODO: Make this so that todo is never null, action sheet doesn't make sense to be open if its null | ||
export function useStarRoleActionSheet() { | ||
// Using controller action sheet rather than inline because I was re-inventing what it was doing allowing dynamic options to be passed easily | ||
const [presentActionSheet, dismissActionSheet] = useIonActionSheet() | ||
// Using controller modal than inline because the trigger prop doesn't work with an ID on a controller-based action sheet button | ||
const [presentEditStarRoleModal] = useEditStarRoleModal() | ||
|
||
return [ | ||
(starRole: StarRole, options?: ActionSheetOptions & HookOverlayOptions) => { | ||
presentActionSheet({ | ||
buttons: [ | ||
...(options?.buttons || []), | ||
{ | ||
text: 'Edit', | ||
data: { | ||
action: 'edit', | ||
}, | ||
handler: () => { | ||
presentEditStarRoleModal(starRole) | ||
}, | ||
}, | ||
{ | ||
text: 'Delete', | ||
role: 'destructive', | ||
data: { | ||
action: 'delete', | ||
}, | ||
handler: async () => { | ||
db.transaction('rw', db.lists, db.starRoles, async () => { | ||
await db.starRoles.delete(starRole.id) | ||
const starRoles = await db.lists.get('#starRoles') | ||
if (starRoles!.order.includes(starRole.id)) { | ||
await db.lists.update('#starRoles', list => { | ||
list.order = list.order.filter(id => id !== starRole.id) | ||
}) | ||
} | ||
}) | ||
}, | ||
}, | ||
], | ||
header: starRole.title, | ||
}) | ||
}, | ||
dismissActionSheet, | ||
] | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import { IonCol, IonGrid, IonIcon, IonRow } from '@ionic/react' | ||
import * as icons from 'ionicons/icons' | ||
import { useMemo } from 'react' | ||
|
||
export default function Icons({ | ||
query, | ||
onClick, | ||
}: { | ||
query: string | ||
onClick: (icon: { name: string; value: string }) => void | ||
}) { | ||
const matchingIcons = useMemo(() => { | ||
return Object.entries(icons).filter(([name]) => | ||
!query ? true : name.includes('Sharp') && name.includes(query), | ||
) | ||
}, [query]) | ||
|
||
return ( | ||
<IonGrid className="relative p-2 border rounded"> | ||
<IonRow> | ||
<a | ||
className="absolute p-1 space-x-1 text-xs bg-white right-2 -top-3" | ||
href="https://ionic.io/ionicons" | ||
target="_blank" | ||
> | ||
<span>View all icons</span> | ||
<IonIcon icon={icons.openSharp} /> | ||
</a> | ||
{matchingIcons.length ? ( | ||
matchingIcons.map(([name, value]) => ( | ||
<IonCol | ||
key={name} | ||
size="1" | ||
> | ||
<IonIcon | ||
className="cursor-pointer" | ||
onClick={() => onClick({ name, value })} | ||
icon={value} | ||
></IonIcon> | ||
</IonCol> | ||
)) | ||
) : ( | ||
<p className="w-full m-2 text-center text-gray-300"> | ||
No matching icons | ||
</p> | ||
)} | ||
</IonRow> | ||
</IonGrid> | ||
) | ||
} | ||
|
||
export function getIonIcon(name) { | ||
return icons[name] | ||
} |
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