From 433d8b3bcc15d58d9c78127c239fb98fefadab59 Mon Sep 17 00:00:00 2001 From: Lim Chee Aun Date: Sun, 10 Dec 2023 19:16:34 +0800 Subject: [PATCH] Adjustments to welcome and login pages --- src/index.css | 9 ++++ src/pages/login.css | 2 +- src/pages/login.jsx | 77 ++++++++++++++++++++++++---------- src/pages/welcome.css | 87 +++++++++++++++----------------------- src/pages/welcome.jsx | 98 ++++++++++++++++++++++--------------------- 5 files changed, 148 insertions(+), 125 deletions(-) diff --git a/src/index.css b/src/index.css index b6cdb5cd..8fcbe497 100644 --- a/src/index.css +++ b/src/index.css @@ -242,6 +242,15 @@ button, :is(button, .button).plain4:not(:disabled, .disabled):is(:hover, :focus) { color: var(--text-color); } +:is(button, .button).plain5 { + background-color: transparent; + color: var(--link-color); + text-decoration: underline; + text-decoration-color: var(--link-faded-color); +} +:is(button, .button).plain5:not(:disabled, .disabled):is(:hover, :focus) { + text-decoration: underline; +} :is(button, .button).light { background-color: var(--bg-faded-color); color: var(--text-color); diff --git a/src/pages/login.css b/src/pages/login.css index 16873c3b..d142f67a 100644 --- a/src/pages/login.css +++ b/src/pages/login.css @@ -30,7 +30,7 @@ #instances-suggestions { margin: 0.2em 0 0; - padding: 0; + padding: 0 0 0 1.2em; list-style: none; width: 90vw; max-width: 40em; diff --git a/src/pages/login.jsx b/src/pages/login.jsx index ce5ec8c0..307fb112 100644 --- a/src/pages/login.jsx +++ b/src/pages/login.jsx @@ -3,6 +3,8 @@ import './login.css'; import { useEffect, useRef, useState } from 'preact/hooks'; import { useSearchParams } from 'react-router-dom'; +import logo from '../assets/logo.svg'; + import Link from '../components/link'; import Loader from '../components/loader'; import instancesListURL from '../data/instances.json?url'; @@ -42,6 +44,7 @@ function Login() { // }, []); const submitInstance = (instanceURL) => { + if (!instanceURL) return; store.local.set('instanceURL', instanceURL); (async () => { @@ -72,23 +75,18 @@ function Login() { })(); }; - const onSubmit = (e) => { - e.preventDefault(); - const { elements } = e.target; - let instanceURL = elements.instanceURL.value.toLowerCase(); - // Remove protocol from instance URL - instanceURL = instanceURL.replace(/^https?:\/\//, '').replace(/\/+$/, ''); - // Remove @acct@ or acct@ from instance URL - instanceURL = instanceURL.replace(/^@?[^@]+@/, ''); - if (!/\./.test(instanceURL)) { - instanceURL = instancesList.find((instance) => - instance.includes(instanceURL), - ); - } - submitInstance(instanceURL); - }; + const cleanInstanceText = instanceText + ? instanceText + .replace(/^https?:\/\//, '') // Remove protocol from instance URL + .replace(/\/+$/, '') // Remove trailing slash + .replace(/^@?[^@]+@/, '') // Remove @?acct@ + .trim() + : null; + const instanceTextLooksLikeDomain = + /[^\s\r\n\t\/\\]+\.[^\s\r\n\t\/\\]+/.test(cleanInstanceText) && + !/[\s\/\\@]/.test(cleanInstanceText); - const instancesSuggestions = instanceText + const instancesSuggestions = cleanInstanceText ? instancesList .filter((instance) => instance.includes(instanceText)) .sort((a, b) => { @@ -106,10 +104,39 @@ function Login() { .slice(0, 10) : []; + const selectedInstanceText = instanceTextLooksLikeDomain + ? cleanInstanceText + : instancesSuggestions?.length + ? instancesSuggestions[0] + : instanceText + ? instancesList.find((instance) => instance.includes(instanceText)) + : null; + + const onSubmit = (e) => { + e.preventDefault(); + // const { elements } = e.target; + // let instanceURL = elements.instanceURL.value.toLowerCase(); + // // Remove protocol from instance URL + // instanceURL = instanceURL.replace(/^https?:\/\//, '').replace(/\/+$/, ''); + // // Remove @acct@ or acct@ from instance URL + // instanceURL = instanceURL.replace(/^@?[^@]+@/, ''); + // if (!/\./.test(instanceURL)) { + // instanceURL = instancesList.find((instance) => + // instance.includes(instanceURL), + // ); + // } + // submitInstance(instanceURL); + submitInstance(selectedInstanceText); + }; + return (
-

Log in

+

+ +
+ Log in +