-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: typings & add IndexDb instead of ls ✨
Signed-off-by: Vinayak Kulkarni <19776877+vinayakkulkarni@users.noreply.github.com>
- Loading branch information
1 parent
a3a3ccf
commit 9499b46
Showing
10 changed files
with
371 additions
and
178 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 |
---|---|---|
@@ -1,20 +1,80 @@ | ||
import { defineStore } from 'pinia'; | ||
import { v4 as uuid } from 'uuid'; | ||
import type { PopupOptions } from 'maplibre-gl'; | ||
import type { ExpenseForm, ExpenseFeatureCollection } from '~/types/expense'; | ||
|
||
/** | ||
* Expense Store | ||
*/ | ||
export const useExpense = defineStore({ | ||
id: 'expense', | ||
state: () => { | ||
return { | ||
state: () => ({ | ||
map: { | ||
ui: { | ||
loaded: false as boolean, | ||
isMarker: true, | ||
isCluster: false, | ||
isHeatmap: false, | ||
}, | ||
}; | ||
}, | ||
actions: { | ||
setLoaded(loaded: boolean) { | ||
this.ui.loaded = loaded; | ||
center: [73.8567, 18.5204], | ||
zoom: 11, | ||
marker: { | ||
options: { draggable: true }, | ||
popup: { | ||
options: { | ||
closeButton: false, | ||
closeOnClick: false, | ||
offset: { | ||
top: [0, 10], | ||
bottom: [0, -10], | ||
}, | ||
} as PopupOptions, | ||
}, | ||
coordinates: [73.8567, 18.5204] as [number, number], | ||
}, | ||
}, | ||
form: { | ||
amount: undefined as number | undefined, | ||
description: '' as string, | ||
type: 'debit' as 'credit' | 'debit', | ||
} as ExpenseForm, | ||
geojson: { | ||
id: uuid().split('-').join(''), | ||
type: 'FeatureCollection', | ||
features: [], | ||
} as ExpenseFeatureCollection, | ||
popup: { | ||
shown: false, | ||
options: { | ||
closeButton: false, | ||
closeOnClick: false, | ||
offset: { | ||
top: [0, 10], | ||
bottom: [0, -10], | ||
}, | ||
} as PopupOptions, | ||
}, | ||
}), | ||
getters: { | ||
isMarker: (state): boolean => { | ||
return ( | ||
!state.map.ui.isCluster && | ||
state.map.ui.isMarker && | ||
!state.map.ui.isHeatmap | ||
); | ||
}, | ||
isCluster: (state): boolean => { | ||
return ( | ||
state.map.ui.isCluster && | ||
!state.map.ui.isMarker && | ||
!state.map.ui.isHeatmap | ||
); | ||
}, | ||
isHeatmap: (state): boolean => { | ||
return ( | ||
!state.map.ui.isCluster && | ||
!state.map.ui.isMarker && | ||
state.map.ui.isHeatmap | ||
); | ||
}, | ||
}, | ||
}); |
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,23 @@ | ||
import { openDB } from 'idb'; | ||
import type { IDBPDatabase } from 'idb'; | ||
import type { MyDB } from '~/types/expense'; | ||
|
||
/** | ||
* Composable for using idb | ||
* | ||
* @returns {Promise<IDBPDatabase<MyDB>>} - The IndexDB database | ||
*/ | ||
async function useIdb(): Promise<IDBPDatabase<MyDB>> { | ||
const db = await openDB<MyDB>('db', 1, { | ||
upgrade(db) { | ||
// Create Language Store | ||
const expenseStore = db.createObjectStore('expenses', { | ||
keyPath: 'id', | ||
}); | ||
expenseStore.createIndex('by-id', 'id'); | ||
}, | ||
}); | ||
return db; | ||
} | ||
|
||
export { useIdb }; |
Oops, something went wrong.