Fix darkMode

This commit is contained in:
Julien Nahum 2024-01-16 15:00:22 +01:00
parent dfb84dc88e
commit 359e993374
9 changed files with 51 additions and 30 deletions

View File

@ -182,12 +182,12 @@ export default {
return this.config.public.paidPlansEnabled return this.config.public.paidPlansEnabled
}, },
showAuth() { showAuth() {
return this.$route.name && !this.$route.name.startsWith('forms-slug') return this.$route.name && this.$route.name !== 'forms-slug'
}, },
hasNavbar() { hasNavbar() {
if (this.isIframe) return false if (this.isIframe) return false
if (this.$route.name && this.$route.name.startsWith('forms-slug')) { if (this.$route.name && this.$route.name === 'forms-slug') {
if (this.form) { if (this.form) {
// If there is a cover, or if branding is hidden remove nav // If there is a cover, or if branding is hidden remove nav
if (this.form.cover_picture || this.form.no_branding) { if (this.form.cover_picture || this.form.no_branding) {

View File

@ -23,7 +23,7 @@
class="border shadow-sm p-2 my-4 flex items-center rounded-md bg-yellow-100 border-yellow-500" class="border shadow-sm p-2 my-4 flex items-center rounded-md bg-yellow-100 border-yellow-500"
> >
<div class="flex flex-grow"> <div class="flex flex-grow">
<p class="mb-0 py-2 px-4 text-yellow-600"> <p class="mb-0 py-2 px-4 text-yellow-600 dark:text-yellow-600">
We disabled the password protection for this form because you are an owner of it. We disabled the password protection for this form because you are an owner of it.
</p> </p>
<v-button color="yellow" @click="hidePasswordDisabledMsg=true"> <v-button color="yellow" @click="hidePasswordDisabledMsg=true">

View File

@ -65,8 +65,9 @@ import draggable from 'vuedraggable'
import OpenFormButton from './OpenFormButton.vue' import OpenFormButton from './OpenFormButton.vue'
import VueHcaptcha from "@hcaptcha/vue3-hcaptcha" import VueHcaptcha from "@hcaptcha/vue3-hcaptcha"
import OpenFormField from './OpenFormField.vue' import OpenFormField from './OpenFormField.vue'
import {pendingSubmission} from "~/composables/forms/pendingSubmission.js"; import {pendingSubmission} from "~/composables/forms/pendingSubmission.js"
import FormLogicPropertyResolver from "~/lib/forms/FormLogicPropertyResolver.js"; import FormLogicPropertyResolver from "~/lib/forms/FormLogicPropertyResolver.js"
import {darkModeEnabled} from "~/lib/forms/public-page.js"
export default { export default {
name: 'OpenForm', name: 'OpenForm',
@ -104,7 +105,7 @@ export default {
dataForm, dataForm,
recordsStore, recordsStore,
workingFormStore, workingFormStore,
darkModeEnabled: useDark(), darkModeEnabled: darkModeEnabled(),
pendingSubmission: pendingSubmission(props.form) pendingSubmission: pendingSubmission(props.form)
} }
}, },

View File

@ -35,6 +35,7 @@ export default {
setup () { setup () {
const workingFormStore = useWorkingFormStore() const workingFormStore = useWorkingFormStore()
return { return {
workspacesStore: useWorkspacesStore(),
workingFormStore workingFormStore
} }
}, },
@ -53,7 +54,7 @@ export default {
} }
}, },
workspace () { workspace () {
return this.$store.getters['open/workspaces/getCurrent']() return this.workspacesStore.getCurrent
}, },
customDomainOptions () { customDomainOptions () {
return this.workspace.custom_domains.map((domain) => { return this.workspace.custom_domains.map((domain) => {

View File

@ -23,6 +23,16 @@
</small> </small>
</div> </div>
<select-input name="dark_mode" class="mt-4"
help="To see changes, save your form and open it"
:options="[
{name:'Auto - use Device System Preferences',value:'auto'},
{name:'Light Mode',value:'light'},
{name:'Dark Mode',value:'dark'}
]"
:form="form" label="Dark Mode"
/>
<select-input name="width" class="mt-4" <select-input name="width" class="mt-4"
:options="[ :options="[
{name:'Centered',value:'centered'}, {name:'Centered',value:'centered'},
@ -41,15 +51,6 @@
:required="false" :required="false"
/> />
<select-input name="dark_mode" class="mt-4"
help="To see changes, save your form and open it"
:options="[
{name:'Auto - use Device System Preferences',value:'auto'},
{name:'Light Mode',value:'light'},
{name:'Dark Mode',value:'dark'}
]"
:form="form" label="Dark Mode"
/>
<color-input name="color" class="mt-4" <color-input name="color" class="mt-4"
:form="form" :form="form"
label="Color (for buttons & inputs border)" label="Color (for buttons & inputs border)"

View File

@ -1,6 +1,6 @@
<template> <template>
<!-- Form Preview (desktop only) --> <!-- Form Preview (desktop only) -->
<div <div ref="parent"
class="bg-gray-50 dark:bg-notion-dark-light hidden md:flex flex-grow p-5 flex-col items-center overflow-y-scroll" class="bg-gray-50 dark:bg-notion-dark-light hidden md:flex flex-grow p-5 flex-col items-center overflow-y-scroll"
> >
<div class="border rounded-lg bg-white dark:bg-notion-dark w-full block transition-all max-w-5xl"> <div class="border rounded-lg bg-white dark:bg-notion-dark w-full block transition-all max-w-5xl">
@ -59,9 +59,9 @@
</template> </template>
<script> <script>
import { useWorkingFormStore } from '../../../../../stores/working_form'
import VSwitch from '../../../../forms/components/VSwitch.vue' import VSwitch from '../../../../forms/components/VSwitch.vue'
import OpenCompleteForm from '../../OpenCompleteForm.vue' import OpenCompleteForm from '../../OpenCompleteForm.vue'
import {handleDarkMode} from "~/lib/forms/public-page.js"
export default { export default {
components: { OpenCompleteForm, VSwitch }, components: { OpenCompleteForm, VSwitch },
@ -93,9 +93,16 @@ export default {
} }
}, },
watch: {}, watch: {
'form.dark_mode': {
handler () {
this.handleDarkMode()
}
}
},
mounted () { mounted () {
this.handleDarkMode()
}, },
methods: { methods: {
@ -108,7 +115,10 @@ export default {
return URL.createObjectURL(val) return URL.createObjectURL(val)
} }
return val return val
},
handleDarkMode () {
handleDarkMode(this.form.dark_mode, this.$refs.parent)
} }
} },
} }
</script> </script>

View File

@ -8,7 +8,7 @@
</template> </template>
<script> <script>
import {useDark} from "@vueuse/core"; import {darkModeEnabled} from "~/lib/forms/public-page.js"
export default { export default {
@ -21,7 +21,7 @@ export default {
data: () => ({}), data: () => ({}),
setup () { setup () {
const isDark = useDark() const isDark = darkModeEnabled()
return { return {
isDark isDark
} }

View File

@ -1,9 +1,13 @@
let darkModeNodeParent = process.client ? document.body : null
/** /**
* Handle form public pages dark mode and transparent mode * Handle form public pages dark mode and transparent mode
*/ */
export function handleDarkMode (darkMode, elem = null) { export function handleDarkMode (darkMode, elem = null) {
if (process.server) return if (process.server) return
const darkModeNodeParent = elem ?? document.body
darkModeNodeParent = elem ?? document.body
// Dark mode // Dark mode
if (['dark', 'light'].includes(darkMode)) { if (['dark', 'light'].includes(darkMode)) {
@ -11,14 +15,19 @@ export function handleDarkMode (darkMode, elem = null) {
} }
// Case auto // Case auto
handleDarkModeToggle(window.matchMedia('(prefers-color-scheme: dark)').matches, darkModeNodeParent) handleDarkModeToggle(window.matchMedia('(prefers-color-scheme: dark)').matches)
// Create listener // Create listener
window.matchMedia('(prefers-color-scheme: dark)') window.matchMedia('(prefers-color-scheme: dark)')
.addEventListener('change', handleDarkModeToggle) .addEventListener('change', handleDarkModeToggle)
} }
function handleDarkModeToggle (enabled, darkModeNodeParent) { export function darkModeEnabled() {
if (process.server) return false
return computed(() => document.body.classList.contains('dark'))
}
function handleDarkModeToggle (enabled) {
if (enabled !== false && enabled !== true) { if (enabled !== false && enabled !== true) {
// if we received an event // if we received an event
enabled = enabled.matches enabled = enabled.matches

View File

@ -75,7 +75,6 @@ onBeforeRouteLeave((to, from) => {
}) })
const passwordEntered = function (password) { const passwordEntered = function (password) {
console.log('passwordEntered', password, sha256(password))
useCookie('password-' + slug, { useCookie('password-' + slug, {
maxAge: 60 * 60 * 7, maxAge: 60 * 60 * 7,
sameSite: false, sameSite: false,
@ -83,14 +82,12 @@ const passwordEntered = function (password) {
}).value = sha256(password) }).value = sha256(password)
loadForm().then(() => { loadForm().then(() => {
if (form.value?.is_password_protected) { if (form.value?.is_password_protected) {
console.log(openCompleteForm.value)
openCompleteForm.value.addPasswordError('Invalid password.') openCompleteForm.value.addPasswordError('Invalid password.')
} }
}) })
} }
const loadForm = async (setup=false) => { const loadForm = async (setup=false) => {
console.log('loadForm',setup)
if (formsStore.loading || (form.value && !form.value.is_password_protected)) return Promise.resolve() if (formsStore.loading || (form.value && !form.value.is_password_protected)) return Promise.resolve()
if (setup) { if (setup) {
@ -107,8 +104,8 @@ const loadForm = async (setup=false) => {
formsStore.stopLoading() formsStore.stopLoading()
// Adapt page to form: colors, custom code etc // Adapt page to form: colors, custom code etc
handleDarkMode(form.value) handleDarkMode(form.value.dark_mode)
handleTransparentMode(form.value) handleTransparentMode(form.value.transparent_background)
if (process.server) return if (process.server) return
if (form.value.custom_code) { if (form.value.custom_code) {
@ -120,6 +117,8 @@ const loadForm = async (setup=false) => {
onMounted(() => { onMounted(() => {
loadForm() loadForm()
handleDarkMode(form.value.dark_mode)
handleTransparentMode(form.value.transparent_background)
}) })
await loadForm(true) await loadForm(true)