From 464e470441287572cfda8d95484f781236b9db35 Mon Sep 17 00:00:00 2001 From: piotrruss Date: Mon, 9 Aug 2021 21:36:03 +0200 Subject: init commit --- helpers/email.js | 4 ++++ helpers/submitForm.js | 26 +++++++++++++++++++++++++ helpers/windowActions.js | 49 ++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 79 insertions(+) create mode 100644 helpers/email.js create mode 100644 helpers/submitForm.js create mode 100644 helpers/windowActions.js (limited to 'helpers') diff --git a/helpers/email.js b/helpers/email.js new file mode 100644 index 0000000..d79426c --- /dev/null +++ b/helpers/email.js @@ -0,0 +1,4 @@ +export const subject = 'Verification of your new Notes App account' +export const text = key => `Thank you for creating an account in Notes App.\nWe are sending you the verification code:\n\n${key}\n\nTo finish verification log in and paste this code.` +export const html = key => `

Thank you for creating an account in Notes App.
We are sending you the verification code:

${key}

To finish verification log in and paste this code.


` + diff --git a/helpers/submitForm.js b/helpers/submitForm.js new file mode 100644 index 0000000..77b283d --- /dev/null +++ b/helpers/submitForm.js @@ -0,0 +1,26 @@ +import fetchJson from 'lib/fetchJson' + +const submitForm = async (e, url, mutateUser, setErrorMsg) => { + e.preventDefault() + + const body = { + email: e.currentTarget.email.value, + password: e.currentTarget.password.value, + } + + try { + mutateUser( + await fetchJson(url, { + method: 'POST', + headers: { 'Content-Type': 'application/json' }, + body: JSON.stringify(body), + }) + ) + } catch (err) { + url.includes('login') + ? setErrorMsg('Could not log in') + : setErrorMsg('Could not register user') + } +} + +export default submitForm diff --git a/helpers/windowActions.js b/helpers/windowActions.js new file mode 100644 index 0000000..fda0f73 --- /dev/null +++ b/helpers/windowActions.js @@ -0,0 +1,49 @@ +export const toggleMin = (appName, apps, setApps) => setApps([ + ...apps.map(a => a.name === appName ? {...a, min: !a.min} : a ) +]) + +export const toggleMax = (appName, apps, setApps) => setApps([ + ...apps.map(a => a.name === appName ? {...a, max: !a.max} : a ) +]) + +export const close = (appName, apps, setApps) => { setApps(apps.filter(a => a.name !== appName)) } + +export const open = (appName, apps, setApps) => { + apps.some(app => app.name === appName) + ? toggleMin(appName, apps, setApps) + : setApps([...apps, {name: appName, min: false, max: false, pos: []}]) +} + +export const move = (appName, winRef, apps, setApps) => { + winRef.current.onmousedown = (event) => { + if (event.target.classList && event.target.classList.contains('window__title')) { + const shiftX = event.clientX - winRef.current.getBoundingClientRect().left + const shiftY = event.clientY - winRef.current.getBoundingClientRect().top + winRef.current.classList.add('moving') + + function moveAt(pageX, pageY, clientY) { + const x = pageX - shiftX + const y = pageY - shiftY - 32 + setApps([...apps.map(a => a.name === appName + ? {...a, pos: [x + 'px', y < 0 ? 0 : y + 'px']} + : a + )]) + } + + const onMouseMove = (event) => { + moveAt(event.pageX, event.pageY, event.clientY) + } + + document.addEventListener('mousemove', onMouseMove) + + document.onmouseup = () => { + document.removeEventListener('mousemove', onMouseMove) + winRef.current.classList.remove('moving') + document.onmouseup = null + } + } + } + + winRef.current.ondragstart = () => null +} + -- cgit v1.2.3