Skip to content

Commit

Permalink
Try watcher
Browse files Browse the repository at this point in the history
  • Loading branch information
Sébastien LeBlanc committed Oct 6, 2023
1 parent 1775499 commit cb96e06
Showing 1 changed file with 30 additions and 1 deletion.
31 changes: 30 additions & 1 deletion src/stores/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export const useIndexStore = defineStore('store', () => {
const menuOpened = ref(false);
const selectedDay = ref(new Date().toLocaleDateString('en-CA'));
const filter = ref('daily');
const selectedTabIndex = ref(0);
const selectedTabIndex = ref(1);
const sort = ref('entries');
const weekObjective = ref('40:00');
const projects = useCollection<Project>(query(collection(db, 'projects'), where('user', '==', user.value?.uid)), {
Expand All @@ -51,6 +51,35 @@ export const useIndexStore = defineStore('store', () => {
ssrKey: 'entries',
},
);
watch(
() => selectedDay.value,
() => {
entries.value = useCollection<Entry>(
query(
collection(db, 'entries').withConverter(dateConverter),
where('user', '==', user.value?.uid),
where('date', '>', $moment(selectedDay.value).startOf('week').toDate()),
where('date', '<', $moment(selectedDay.value).endOf('week').toDate()),
),
{
ssrKey: 'entries',
},
).value;
},
);
// const entries = computed(() => {
// return useCollection<Entry>(
// query(
// collection(db, 'entries').withConverter(dateConverter),
// where('user', '==', user.value?.uid),
// where('date', '>', $moment(selectedDay.value).startOf('week').toDate()),
// where('date', '<', $moment(selectedDay.value).endOf('week').toDate()),
// ),
// {
// ssrKey: 'entries',
// },
// ).value;
// });

const todaysEntries = computed((): Entry[] => {
return [...entries.value]
Expand Down

0 comments on commit cb96e06

Please sign in to comment.