// Dependencies import { useState, useEffect, useContext } from 'react' import { useTranslation } from 'next-i18next' import { DateTime } from 'luxon' import { CopyToClipboard } from 'react-copy-to-clipboard' import orderBy from 'lodash.orderby' // Hooks import { useAccount } from 'shared/hooks/use-account.mjs' import { useBackend } from 'shared/hooks/use-backend.mjs' import { useToast } from 'shared/hooks/use-toast.mjs' import { useRouter } from 'next/router' // Context import { LoadingContext } from 'shared/context/loading-context.mjs' import { ModalContext } from 'shared/context/modal-context.mjs' // Components import { BackToAccountButton, Choice } from './shared.mjs' import { Popout } from 'shared/components/popout.mjs' import { WebLink } from 'shared/components/web-link.mjs' import { CopyIcon } from 'shared/components/icons.mjs' import { Collapse } from 'shared/components/collapse.mjs' import { TrashIcon } from 'shared/components/icons.mjs' import { LeftIcon } from 'shared/components/icons.mjs' import { ModalWrapper } from 'shared/components/wrappers/modal.mjs' import Markdown from 'react-markdown' import { Tab } from './bio.mjs' export const ns = ['account', 'toast'] const NewSet = ({ t, account, setGenerate, oneAdded, backend, toast, standAlone = false }) => { // Context const { loading, startLoading, stopLoading } = useContext(LoadingContext) // Hooks const router = useRouter() // State const [name, setName] = useState('') const [mset, setMset] = useState(false) // Helper method to create a new set const createSet = async () => { startLoading() const result = await backend.createSet({ name, }) if (result.success) { toast.success({t('nailedIt')}) setMset(result.data.set) oneAdded() } else toast.for.backendError() stopLoading() } // Helper method to clear inputs const clear = () => { setMset(false) setGenerate(false) } // Shared props for tabs const tabProps = { activeTab, setActiveTab, t } return (

{t('newSet')}

{t('name')}

{t('setNameDesc')}

setName(evt.target.value)} className="input w-full input-bordered flex flex-row" type="text" placeholder={'Georg Cantor'} />
) } const Row = ({ title, children }) => (
{title}
{children}
) const MeasurementsSet = ({ apikey, t, account, backend, oneAdded }) => { // Context const { loading, startLoading, stopLoading } = useContext(LoadingContext) const { setModal } = useContext(ModalContext) // Hooks const toast = useToast() const fields = { id: 'ID', name: t('name'), level: t('keyLevel'), createdAt: t('created'), } const remove = async () => { startLoading() const result = await backend.removeSet(mset.id) if (result) toast.success(t('gone')) else toast.for.backendError() // This just forces a refresh of the list from the server // We obviously did not add a key here, but rather removed one oneAdded() stopLoading() } const removeModal = () => { setModal(

{t('areYouCertain')}

{t('deleteSetWarning')}

) } const title = (
{mset.name}
) //return
{JSON.stringify(mset, null ,2)}
return ( 4 ? remove : removeModal} > , ]} >
{JSON.stringify(mset, null, 2)}
{Object.entries(fields).map(([key, title]) => ( {mset[key]} ))}
) } // Component for the 'new/apikey' page //export const NewApikey = ({ app, standAlone = false }) => { // const { account, token } = useAccount() // const backend = useBackend(token) // const { t } = useTranslation(ns) // const toast = useToast() // // const [keys, setKeys] = useState([]) // const [generate, setGenerate] = useState(false) // const [added, setAdded] = useState(0) // // const oneAdded = () => setAdded(added + 1) // // return ( //
// //
// ) //} // Component for the account/sets page export const Sets = () => { // Context const { loading, startLoading, stopLoading } = useContext(LoadingContext) // Hooks const { account, token } = useAccount() const backend = useBackend(token) const { t } = useTranslation(ns) const toast = useToast() // State const [sets, setSets] = useState([]) const [generate, setGenerate] = useState(false) const [added, setAdded] = useState(0) // Effects useEffect(() => { const getSets = async () => { const result = await backend.getSets() if (result.success) setSets(result.data.sets) } getSets() }, [added]) // Helper method to force a refresh const oneAdded = () => setAdded(added + 1) return (
{generate ? ( ) : ( <>

{t('sets')}

{orderBy(sets, ['name'], ['asc']).map((mset) => ( ))} )}
) }