aboutsummaryrefslogtreecommitdiffstats
path: root/helpers
diff options
context:
space:
mode:
Diffstat (limited to 'helpers')
-rw-r--r--helpers/email.js4
-rw-r--r--helpers/submitForm.js26
-rw-r--r--helpers/windowActions.js49
3 files changed, 79 insertions, 0 deletions
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 => `<p>Thank you for creating an account in Notes App.<br/>We are sending you the verification code:</p><p style="font-size: 150%;padding: 1em;border: 1px solid black">${key}</p><p>To finish verification log in and paste this code.</p></br>`
+
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
+}
+