This commit is contained in:
2023-06-08 22:22:29 +02:00
parent 3e6fb75575
commit cf287f31ab
10 changed files with 41 additions and 49 deletions

View File

@@ -16,7 +16,7 @@ const config: CapacitorConfig = {
}, },
FirebaseAuthentication: { FirebaseAuthentication: {
skipNativeAuth: false, skipNativeAuth: false,
providers: ['google.com'] providers: ['google.com', 'microsoft.com', 'github.com']
} }
} }
} }

View File

@@ -60,37 +60,33 @@ const providers: Provider[] = [
const credential = GoogleAuthProvider.credential(result.credential?.idToken) const credential = GoogleAuthProvider.credential(result.credential?.idToken)
await signInWithCredential(auth, credential) await signInWithCredential(auth, credential)
} }
},
{
name: 'microsoft',
icon: 'fa-brands fa-microsoft',
signin: async () => {
const result = await FirebaseAuthentication.signInWithMicrosoft({
mode: 'redirect'
})
const provider = new OAuthProvider('microsoft.com')
const credential = provider.credential({
idToken: result.credential?.idToken,
rawNonce: result.credential?.nonce
})
await signInWithCredential(auth, credential)
}
},
{
name: 'github',
icon: 'fa-brands fa-github',
signin: async () => {
const result = await FirebaseAuthentication.signInWithGithub({
mode: 'redirect'
})
const provider = new OAuthProvider('github.com')
const credential = provider.credential({
idToken: result.credential?.idToken,
rawNonce: result.credential?.nonce
})
await signInWithCredential(auth, credential)
}
} }
// {
// name: 'microsoft',
// icon: 'fa-brands fa-microsoft',
// signin: async () => {
// const result = await FirebaseAuthentication.signInWithMicrosoft({
// mode: 'redirect'
// })
// const provider = new OAuthProvider('microsoft.com')
// // const credential = provider.credential({
// // idToken: result.credential?.idToken,
// // rawNonce: result.credential?.nonce
// // })
// if (result.credential) {
// const credential = provider.credential(result.credential)
// console.log(credential)
// try {
// const user = await signInWithCredential(auth, credential)
// console.log('user', user)
// } catch (error: any) {
// console.log(error)
// console.log('message', error.message)
// }
// }
// }
// }
// Microsoft users can't be signed in manually so this does not work on native
] ]
// type Provider = (typeof providers)[number] // type Provider = (typeof providers)[number]
const signInWithProvider = async (provider: Provider) => { const signInWithProvider = async (provider: Provider) => {

View File

@@ -15,8 +15,7 @@ import ContextedPlugin from '@/ckeditor/ContextedPlugin'
import { mdToHtml, htmlToMd } from '@/utils/markdown' import { mdToHtml, htmlToMd } from '@/utils/markdown'
import { getNoteByTitle, setActiveNote, addNote } from '@/composables/useNotes' import { getNoteByTitle, setActiveNote, addNote } from '@/composables/useNotes'
import Autocomplete from '@/components/Note/Autocomplete.vue' import Autocomplete from '@/components/Note/Autocomplete.vue'
import { Haptics, ImpactStyle } from '@capacitor/haptics' import { vibrate } from '@/composables/useHaptics'
const props = defineProps<{ note: Note }>() const props = defineProps<{ note: Note }>()
const emit = defineEmits<{ const emit = defineEmits<{
@@ -68,7 +67,7 @@ const handleClick = async ({ data }: { data: any }) => {
let note: BaseNote | Note | undefined = getNoteByTitle(noteTitle) let note: BaseNote | Note | undefined = getNoteByTitle(noteTitle)
if (!note) note = addNote(noteTitle, '') if (!note) note = addNote(noteTitle, '')
setActiveNote(note.id) setActiveNote(note.id)
await Haptics.impact({ style: ImpactStyle.Light }) await vibrate()
} }
const autocompleteRef = ref<InstanceType<typeof Autocomplete> | null>(null) const autocompleteRef = ref<InstanceType<typeof Autocomplete> | null>(null)

View File

@@ -2,6 +2,7 @@
import { Capacitor } from '@capacitor/core' import { Capacitor } from '@capacitor/core'
import { Dialog } from '@capacitor/dialog' import { Dialog } from '@capacitor/dialog'
import type { ConfirmOptions } from '@capacitor/dialog' import type { ConfirmOptions } from '@capacitor/dialog'
import { vibrate } from '@/composables/useHaptics'
const props = defineProps<{ const props = defineProps<{
note: Note note: Note
@@ -57,7 +58,7 @@ const openModal = async (open: () => void, modal: ModalOptions) => {
<UIButtonGroup class="flex items-center" v-if="!props.note.isRoot"> <UIButtonGroup class="flex items-center" v-if="!props.note.isRoot">
<UIModal v-for="confirmModal in confirmModals" :key="confirmModal.key"> <UIModal v-for="confirmModal in confirmModals" :key="confirmModal.key">
<template #activator="{ open }"> <template #activator="{ open }">
<UIButton size="sm" @click="openModal(open, confirmModal)" :join="true"> <UIButton size="sm" @click="openModal(open, confirmModal)" :join="true" @mousedown="vibrate">
<i :class="confirmModal.icon" /> <i :class="confirmModal.icon" />
</UIButton> </UIButton>
</template> </template>

View File

@@ -1,12 +1,6 @@
<script setup lang="ts"> <script setup lang="ts">
import { OnClickOutside } from '@vueuse/components' import { OnClickOutside } from '@vueuse/components'
import { Haptics, ImpactStyle } from '@capacitor/haptics' import { vibrate } from '@/composables/useHaptics'
const vibrate = (event: PointerEvent) => {
if (event.target !== document.activeElement) {
Haptics.impact({ style: ImpactStyle.Light })
}
}
</script> </script>
<template> <template>
<OnClickOutside> <OnClickOutside>

View File

@@ -32,7 +32,6 @@ const updateNoteContent = (content: string) => {
const references = computed<Note[]>(() => getNoteReferences(props.note)) const references = computed<Note[]>(() => getNoteReferences(props.note))
const handleAction = async (action: string, closeModal: () => Promise<Boolean>) => { const handleAction = async (action: string, closeModal: () => Promise<Boolean>) => {
Haptics.impact({ style: ImpactStyle.Light })
switch (action) { switch (action) {
case 'delete': case 'delete':
if (closeModal) await closeModal() if (closeModal) await closeModal()

View File

@@ -1,6 +1,6 @@
<script setup lang="ts"> <script setup lang="ts">
import { onClickOutside } from '@vueuse/core' import { onClickOutside } from '@vueuse/core'
import { Haptics, ImpactStyle } from '@capacitor/haptics' import { vibrate } from '@/composables/useHaptics'
const props = withDefaults( const props = withDefaults(
defineProps<{ defineProps<{
@@ -20,9 +20,8 @@ const show = ref<boolean>(false)
watch( watch(
() => props.open, () => props.open,
() => { () => {
if (show.value) { if (show.value) vibrate()
Haptics.impact({ style: ImpactStyle.Light })
}
show.value = props.open show.value = props.open
}, },
{ immediate: true } { immediate: true }

View File

@@ -60,6 +60,7 @@ export const initializeFirebase = async () => {
const app = initializeApp(firebaseConfig) const app = initializeApp(firebaseConfig)
const auth = await getFirebaseAuth(app) const auth = await getFirebaseAuth(app)
onAuthStateChanged(auth, (firebaseUser) => { onAuthStateChanged(auth, (firebaseUser) => {
console.log('auth state changed', firebaseUser)
user.value = firebaseUser user.value = firebaseUser
}) })
db.value = markRaw( db.value = markRaw(

View File

@@ -0,0 +1,3 @@
import { Haptics, ImpactStyle } from '@capacitor/haptics'
export const vibrate = () => Haptics.impact({ style: ImpactStyle.Light })

View File

@@ -8,7 +8,7 @@ import { defaultNotes } from '@/utils/defaultNotes'
import { mdToHtml } from '@/utils/markdown' import { mdToHtml } from '@/utils/markdown'
import { getAllMatches } from '@/utils/helpers' import { getAllMatches } from '@/utils/helpers'
import { preferredNotesSource } from '@/composables/useSettings' import { preferredNotesSource } from '@/composables/useSettings'
import { Haptics, ImpactStyle } from '@capacitor/haptics' import { vibrate } from '@/composables/useHaptics'
export const notesSources = computed(() => ({ export const notesSources = computed(() => ({
local: true, local: true,
@@ -104,7 +104,7 @@ export const setActiveNote = (noteId: string | undefined, haptic: boolean = true
if (noteId) { if (noteId) {
activeNoteId.value = noteId activeNoteId.value = noteId
activeViewMode.value = viewModes.find((mode) => mode.name === 'Note') || viewModes[0] activeViewMode.value = viewModes.find((mode) => mode.name === 'Note') || viewModes[0]
if (haptic) Haptics.impact({ style: ImpactStyle.Light }) if (haptic) vibrate()
} }
} }