Skip to content

Commit

Permalink
✨ Star roles
Browse files Browse the repository at this point in the history
Was going to call these 'roles' but that would
clash with Dexie cloud's built-in roles table.
  • Loading branch information
homostellaris committed Jul 27, 2024
1 parent fa39a39 commit ab5d157
Show file tree
Hide file tree
Showing 17 changed files with 901 additions and 372 deletions.
25 changes: 12 additions & 13 deletions components/db.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,22 @@
import Dexie, { Table } from 'dexie'

import dexieCloud from 'dexie-cloud-addon'
import dexieCloud, { DexieCloudTable } from 'dexie-cloud-addon'

export interface Todo {
completedAt?: Date
id: string
note?: Note
role?: Role
starRole?: StarRole['id']
starPoints?: string
title: string
}

export interface CreatedTodo extends Todo {
createdAt: Date
completedAt?: Date
id?: string
}

export interface Note {
uri: string
}

export interface Role {
export interface StarRole {
id: string
title: string
}

Expand All @@ -40,17 +37,19 @@ export interface Setting {

export class DexieStarfocus extends Dexie {
lists!: Table<List>
settings!: Table<Setting>
todos!: Table<CreatedTodo>
settings!: DexieCloudTable<Setting, 'key'>
starRoles: DexieCloudTable<StarRole, 'id'>
todos!: DexieCloudTable<Todo, 'id'>

constructor() {
super('starfocus', {
addons: [dexieCloud],
})
this.version(2).stores({
todos: '@id, createdAt, completedAt, title',
this.version(3).stores({
todos: '@id, createdAt, completedAt, starRole, title',
lists: 'type',
settings: '&key',
starRoles: '@id, title',
})
this.cloud.configure({
databaseUrl: 'https://zy0myinc2.dexie.cloud',
Expand Down
89 changes: 87 additions & 2 deletions components/pages/Constellation.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,94 @@
import { IonPage } from '@ionic/react'
import {
IonContent,
IonFab,
IonFabButton,
IonHeader,
IonIcon,
IonItem,
IonLabel,
IonList,
IonPage,
IonReorder,
IonReorderGroup,
IonSpinner,
IonTitle,
IonToolbar,
} from '@ionic/react'
import { useLiveQuery } from 'dexie-react-hooks'
import { add, starOutline } from 'ionicons/icons'
import { useCallback, useRef } from 'react'
import { db } from '../db'
import { useCreateStarRoleModal } from '../starRoles/create/useCreateStarRoleModal'

export default function Constellation() {
const starRoles = useLiveQuery(() => db.starRoles.toArray())
const isLoading = starRoles === undefined

const fab = useRef<HTMLIonFabElement>(null)
const [presentCreateStarRoleModal, dismiss] = useCreateStarRoleModal()
const openCreateStarRoleModal = useCallback(() => {
presentCreateStarRoleModal({
onWillDismiss: () => {
if (fab.current) fab.current.activated = false
},
})
}, [fab, presentCreateStarRoleModal])

return (
<IonPage>
<h1>Constellation</h1>
<IonHeader>
<IonToolbar>
<IonTitle>Constellation</IonTitle>
</IonToolbar>
</IonHeader>
<IonContent fullscreen>
{isLoading ? (
<div className="flex items-center justify-center h-full">
<IonSpinner
className="w-20 h-20"
name="dots"
/>
</div>
) : starRoles.length === 0 ? (
<div className="flex flex-col items-center justify-center h-full gap-5">
<IonIcon
icon={starOutline}
size="large"
/>
<p>
Create some roles to focus on what matters in different areas of
your life
</p>
</div>
) : (
<IonList inset>
<IonReorderGroup
disabled={false}
// onIonItemReorder={handleReorder}
>
{starRoles.map(role => (
<IonItem
button
key={role.id}
>
<IonLabel>{role?.title}</IonLabel>
<IonReorder slot="end"></IonReorder>
</IonItem>
))}
</IonReorderGroup>
</IonList>
)}
<IonFab
ref={fab}
slot="fixed"
vertical="bottom"
horizontal="end"
>
<IonFabButton onClick={openCreateStarRoleModal}>
<IonIcon icon={add}></IonIcon>
</IonFabButton>
</IonFab>
</IonContent>
</IonPage>
)
}
Loading

0 comments on commit ab5d157

Please sign in to comment.