Skip to content

Commit

Permalink
Corrections
Browse files Browse the repository at this point in the history
  • Loading branch information
Sébastien LeBlanc committed Oct 11, 2023
1 parent aa7a2c3 commit 7b2876f
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 31 deletions.
2 changes: 0 additions & 2 deletions src/components/WeekSummary.vue
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,6 @@ import { storeToRefs } from 'pinia';
import { useAuthStore } from '@/stores/auth';
const auth = useAuthStore();
const { logout } = auth;
const user = useCurrentUser();
const store = useIndexStore();
const route = useRoute();
Expand Down
18 changes: 18 additions & 0 deletions src/pages/logout.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
</template>

<script lang="ts" setup>
import { signOut } from 'firebase/auth';
import { useIndexStore } from '@/stores/index';
definePageMeta({
layout: 'login',
});
Expand All @@ -15,4 +18,19 @@ defineI18nRoute({
en: '/logout',
},
});
const auth = useFirebaseAuth()!;
const store = useIndexStore();
const localePath = useLocalePath();
onMounted(async () => {
await nextTick();
await signOut(auth);
store.$reset();
navigateTo(
localePath({
name: 'login',
}),
);
});
</script>
19 changes: 5 additions & 14 deletions src/stores/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,30 +8,21 @@ import { useIndexStore } from '@/stores/index';
export const useAuthStore = defineStore('auth', () => {
async function login() {
const auth = useFirebaseAuth()!;
const localeRoute = useLocaleRoute();
const localePath = useLocalePath();

await signInWithPopup(auth, googleAuthProvider);
return navigateTo(
localeRoute({
localePath({
name: 'index',
}),
);
}
async function logout() {
const auth = useFirebaseAuth()!;
const localeRoute = useLocaleRoute();
const store = useIndexStore();
const localePath = useLocalePath();

await navigateTo(
localeRoute({
name: 'logout',
}),
);
store.$reset();
await signOut(auth);
return navigateTo(
localeRoute({
name: 'login',
localePath({
name: 'logout',
}),
);
}
Expand Down
34 changes: 19 additions & 15 deletions src/stores/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export const useIndexStore = defineStore('store', () => {
},
};

const selectedDay = useLocalStorage('selectedDay', ref(new Date().toLocaleDateString('en-CA')));
const selectedDay = ref(new Date().toLocaleDateString('en-CA'));
const filter = useLocalStorage('filter', ref('daily'));
const selectedTabIndex = useLocalStorage('selectedTabIndex', ref(0));
const sort = useLocalStorage('sort', ref('name'));
Expand All @@ -38,23 +38,28 @@ export const useIndexStore = defineStore('store', () => {
const weekEnd = computed(() => {
return $moment(selectedDay.value).endOf('week').toDate();
});
const projects = useCollection<Project>(query(collection(db, 'projects'), where('user', '==', user.value?.uid)), {
ssrKey: 'projects',
});
const projects = useCollection<Project>(
user.value ? query(collection(db, 'projects'), where('user', '==', user.value?.uid)) : null,
{
ssrKey: 'projects',
},
);
const priorities = useCollection<Priority>(
query(collection(db, 'priorities'), where('user', '==', user.value?.uid)),
user.value ? query(collection(db, 'priorities'), where('user', '==', user.value?.uid)) : null,
{
ssrKey: 'priorities',
},
);
const entries = useCollection<Entry>(
computed(() =>
query(
collection(db, 'entries').withConverter(dateConverter),
where('user', '==', user.value?.uid),
where('date', '>=', weekStart.value),
where('date', '<=', weekEnd.value),
),
user.value
? query(
collection(db, 'entries').withConverter(dateConverter),
where('user', '==', user.value?.uid),
where('date', '>=', weekStart.value),
where('date', '<=', weekEnd.value),
)
: null,
),
{
ssrKey: 'entries',
Expand Down Expand Up @@ -87,7 +92,6 @@ export const useIndexStore = defineStore('store', () => {
const weekSummary = computed((): Summary => {
return entries.value
.filter((e) => !e.is_creating)
.filter((e) => $moment(e.date).isBetween(weekStart.value, weekEnd.value, 'day', '[]'))
.reduce(
(acc: Summary, e: Entry) => {
const day = $moment(e.date).locale('en').format('dddd').toLowerCase() as keyof Summary;
Expand All @@ -111,7 +115,6 @@ export const useIndexStore = defineStore('store', () => {
const weeklySummaryByProjects = computed((): [string, string][] => {
const projects = [...entries.value]
.filter((e) => !e.is_creating)
// .filter((e) => $moment(e.date).isBetween(weekStart, weekEnd, 'day', '[]'))
.reduce((acc: { [key: string]: string }, e: Entry) => {
const project = e.project;

Expand Down Expand Up @@ -193,13 +196,13 @@ export const useIndexStore = defineStore('store', () => {
await addDoc(collection(db, 'entries').withConverter(dateConverter), {
...entry,
user: user.value?.uid,
project: doc(db, 'projects', entry.project.id),
project: entry.project?.id ? doc(db, 'projects', entry.project.id) : null,
});
}
async function updateEntry(entry: Entry) {
await updateDoc(doc(db, 'entries', entry.id), {
...entry,
project: doc(db, 'projects', entry.project.id),
project: entry.project?.id ? doc(db, 'projects', entry.project.id) : null,
date: $moment(entry.date).startOf('day').toDate(),
});
}
Expand Down Expand Up @@ -284,6 +287,7 @@ export const useIndexStore = defineStore('store', () => {

return {
// state
user,
menuOpened,
selectedDay,
filter,
Expand Down

0 comments on commit 7b2876f

Please sign in to comment.