diff --git a/.babelrc b/.babelrc deleted file mode 100644 index ebdb6f7..0000000 --- a/.babelrc +++ /dev/null @@ -1,3 +0,0 @@ -{ - "plugins": ["@emotion"] -} diff --git a/app/controllers/admin_controller.ts b/app/controllers/admin_controller.ts index 0c4e3af..4d1b3b0 100644 --- a/app/controllers/admin_controller.ts +++ b/app/controllers/admin_controller.ts @@ -31,16 +31,22 @@ export default class AdminController { protected collectionsController: CollectionsController ) {} - async index({ inertia }: HttpContext) { + async index({ response }: HttpContext) { const users = await this.usersController.getAllUsersWithTotalRelations(); const linksCount = await this.linksController.getTotalLinksCount(); const collectionsCount = await this.collectionsController.getTotalCollectionsCount(); - return inertia.render('admin/dashboard', { + // TODO: return view + return response.json({ users: users.map((user) => new UserWithRelationCountDto(user).toJson()), totalLinks: linksCount, totalCollections: collectionsCount, }); + // return inertia.render('admin/dashboard', { + // users: users.map((user) => new UserWithRelationCountDto(user).toJson()), + // totalLinks: linksCount, + // totalCollections: collectionsCount, + // }); } } diff --git a/app/controllers/collections_controller.ts b/app/controllers/collections_controller.ts index ff38fad..39ccc18 100644 --- a/app/controllers/collections_controller.ts +++ b/app/controllers/collections_controller.ts @@ -26,7 +26,7 @@ export default class CollectionsController { } // TODO: Create DTOs - return inertia.render('mantine_dashboard', { + return inertia.render('dashboard', { collections: collections.map((collection) => collection.serialize()), activeCollection: activeCollection?.serialize() || collections[0].serialize(), @@ -36,7 +36,7 @@ export default class CollectionsController { // Create collection form async showCreatePage({ inertia, auth }: HttpContext) { const collections = await this.getCollectionsByAuthorId(auth.user!.id); - return inertia.render('mantine/collections/create', { + return inertia.render('collections/create', { disableHomeLink: collections.length === 0, }); } @@ -61,7 +61,7 @@ export default class CollectionsController { collectionId, auth.user!.id ); - return inertia.render('mantine/collections/edit', { + return inertia.render('collections/edit', { collection, }); } @@ -96,7 +96,7 @@ export default class CollectionsController { collectionId, auth.user!.id ); - return inertia.render('mantine/collections/delete', { + return inertia.render('collections/delete', { collection, }); } diff --git a/app/controllers/links_controller.ts b/app/controllers/links_controller.ts index 29f636f..ce36361 100644 --- a/app/controllers/links_controller.ts +++ b/app/controllers/links_controller.ts @@ -17,7 +17,7 @@ export default class LinksController { async showCreatePage({ auth, inertia }: HttpContext) { const collections = await this.collectionsController.getCollectionsByAuthorId(auth.user!.id); - return inertia.render('mantine/links/create', { collections }); + return inertia.render('links/create', { collections }); } async store({ auth, request, response }: HttpContext) { @@ -50,7 +50,7 @@ export default class LinksController { await this.collectionsController.getCollectionsByAuthorId(userId); const link = await this.getLinkById(linkId, userId); - return inertia.render('mantine/links/edit', { collections, link }); + return inertia.render('links/edit', { collections, link }); } async update({ request, auth, response }: HttpContext) { @@ -98,7 +98,7 @@ export default class LinksController { const link = await this.getLinkById(linkId, auth.user!.id); await link.load('collection'); - return inertia.render('mantine/links/delete', { link }); + return inertia.render('links/delete', { link }); } async delete({ request, auth, response }: HttpContext) { diff --git a/app/controllers/shared_collections_controller.ts b/app/controllers/shared_collections_controller.ts index 6354f96..fd2d971 100644 --- a/app/controllers/shared_collections_controller.ts +++ b/app/controllers/shared_collections_controller.ts @@ -4,13 +4,16 @@ import { getSharedCollectionValidator } from '#validators/shared_collection'; import type { HttpContext } from '@adonisjs/core/http'; export default class SharedCollectionsController { - async index({ request, inertia }: HttpContext) { + async index({ request, response }: HttpContext) { const { params } = await request.validateUsing( getSharedCollectionValidator ); const collection = await this.getSharedCollectionById(params.id); - return inertia.render('shared', { collection }); + console.log('shared page', collection); + // TODO: return view + return response.json(collection); + // return inertia.render('shared', { collection }); } private async getSharedCollectionById(id: Collection['id']) { diff --git a/inertia/app/app.tsx b/inertia/app/app.tsx index 67913ee..60c0d73 100644 --- a/inertia/app/app.tsx +++ b/inertia/app/app.tsx @@ -3,14 +3,12 @@ import { createInertiaApp } from '@inertiajs/react'; import 'dayjs/locale/en'; import 'dayjs/locale/fr'; import { hydrateRoot } from 'react-dom/client'; -import 'react-toggle/style.css'; -import { primaryColor } from '~/styles/common_colors'; import '../i18n/index'; const appName = import.meta.env.VITE_APP_NAME || 'MyLinks'; createInertiaApp({ - progress: { color: primaryColor }, + progress: { color: '#5474B4' }, title: (title) => `${appName}${title && ` - ${title}`}`, diff --git a/inertia/components/common/dropdown/dropdown.tsx b/inertia/components/common/dropdown/dropdown.tsx deleted file mode 100644 index fe8d28f..0000000 --- a/inertia/components/common/dropdown/dropdown.tsx +++ /dev/null @@ -1,64 +0,0 @@ -import styled from '@emotion/styled'; -import { HtmlHTMLAttributes, ReactNode, useRef } from 'react'; -import DropdownContainer from '~/components/common/dropdown/dropdown_container'; -import DropdownLabel from '~/components/common/dropdown/dropdown_label'; -import useClickOutside from '~/hooks/use_click_outside'; -import useToggle from '~/hooks/use_modal'; -import useShortcut from '~/hooks/use_shortcut'; - -const DropdownStyle = styled.div<{ opened: boolean; svgSize?: number }>( - ({ opened, theme, svgSize = 24 }) => ({ - cursor: 'pointer', - userSelect: 'none', - position: 'relative', - minWidth: 'fit-content', - width: 'fit-content', - maxWidth: '250px', - backgroundColor: opened ? theme.colors.secondary : theme.colors.background, - padding: '4px', - borderRadius: theme.border.radius, - - '&:hover': { - backgroundColor: theme.colors.secondary, - }, - - '& svg': { - height: `${svgSize}px`, - width: `${svgSize}px`, - }, - }) -); - -export default function Dropdown({ - children, - label, - className, - svgSize, - onClick, -}: HtmlHTMLAttributes & { - label: ReactNode | string; - className?: string; - svgSize?: number; -}) { - const dropdownRef = useRef(null); - const { isShowing, toggle, close } = useToggle(); - - useClickOutside(dropdownRef, close); - useShortcut('ESCAPE_KEY', close, { disableGlobalCheck: true }); - - return ( - { - onClick?.(event); - toggle(); - }} - ref={dropdownRef} - className={className} - svgSize={svgSize} - > - {label} - {children} - - ); -} diff --git a/inertia/components/common/dropdown/dropdown_container.tsx b/inertia/components/common/dropdown/dropdown_container.tsx deleted file mode 100644 index 82c87e3..0000000 --- a/inertia/components/common/dropdown/dropdown_container.tsx +++ /dev/null @@ -1,21 +0,0 @@ -import styled from '@emotion/styled'; -import TransitionLayout from '~/components/layouts/_transition_layout'; - -const DropdownContainer = styled(TransitionLayout)<{ show: boolean }>( - ({ show, theme }) => ({ - zIndex: 99, - position: 'absolute', - top: 'calc(100% + 0.5em)', - right: 0, - minWidth: '175px', - backgroundColor: show ? theme.colors.secondary : theme.colors.background, - border: `2px solid ${theme.colors.secondary}`, - borderRadius: theme.border.radius, - boxShadow: theme.colors.boxShadow, - display: show ? 'flex' : 'none', - flexDirection: 'column', - overflow: 'hidden', - }) -); - -export default DropdownContainer; diff --git a/inertia/components/common/dropdown/dropdown_item.tsx b/inertia/components/common/dropdown/dropdown_item.tsx deleted file mode 100644 index ed9e46b..0000000 --- a/inertia/components/common/dropdown/dropdown_item.tsx +++ /dev/null @@ -1,31 +0,0 @@ -import styled from '@emotion/styled'; -import { Link } from '@inertiajs/react'; - -const DropdownItemBase = styled('div', { - shouldForwardProp: (propName) => propName !== 'danger', -})<{ danger?: boolean }>(({ theme, danger }) => ({ - fontSize: '14px', - whiteSpace: 'nowrap', - color: danger ? theme.colors.lightRed : theme.colors.primary, - padding: '8px 12px', - borderRadius: theme.border.radius, - - '&:hover': { - backgroundColor: theme.colors.background, - }, -})); - -const DropdownItemButton = styled(DropdownItemBase)({ - display: 'flex', - gap: '0.75em', - alignItems: 'center', -}); - -const DropdownItemLink = styled(DropdownItemBase.withComponent(Link))({ - width: '100%', - display: 'flex', - gap: '0.75em', - alignItems: 'center', -}); - -export { DropdownItemButton, DropdownItemLink }; diff --git a/inertia/components/common/dropdown/dropdown_label.tsx b/inertia/components/common/dropdown/dropdown_label.tsx deleted file mode 100644 index e1339d1..0000000 --- a/inertia/components/common/dropdown/dropdown_label.tsx +++ /dev/null @@ -1,11 +0,0 @@ -import styled from '@emotion/styled'; - -const DropdownLabel = styled.div(({ theme }) => ({ - height: 'auto', - width: 'auto', - color: theme.colors.font, - display: 'flex', - gap: '0.35em', -})); - -export default DropdownLabel; diff --git a/inertia/components/common/form/_button.tsx b/inertia/components/common/form/_button.tsx deleted file mode 100644 index b41efeb..0000000 --- a/inertia/components/common/form/_button.tsx +++ /dev/null @@ -1,31 +0,0 @@ -import styled from '@emotion/styled'; - -const Button = styled.button<{ danger?: boolean }>(({ theme, danger }) => { - const btnColor = !danger ? theme.colors.primary : theme.colors.lightRed; - const btnDarkColor = !danger ? theme.colors.darkBlue : theme.colors.lightRed; - return { - cursor: 'pointer', - width: '100%', - textTransform: 'uppercase', - fontSize: '14px', - color: theme.colors.white, - background: btnColor, - padding: '0.75em', - border: `1px solid ${btnColor}`, - borderRadius: theme.border.radius, - transition: theme.transition.delay, - - '&:disabled': { - cursor: 'not-allowed', - opacity: '0.5', - }, - - '&:not(:disabled):hover': { - boxShadow: `${btnDarkColor} 0 0 3px 1px`, - background: btnDarkColor, - color: theme.colors.white, - }, - }; -}); - -export default Button; diff --git a/inertia/components/common/form/_form.tsx b/inertia/components/common/form/_form.tsx deleted file mode 100644 index 4a88224..0000000 --- a/inertia/components/common/form/_form.tsx +++ /dev/null @@ -1,10 +0,0 @@ -import styled from '@emotion/styled'; - -const Form = styled.form({ - width: '100%', - display: 'flex', - gap: '1em', - flexDirection: 'column', -}); - -export default Form; diff --git a/inertia/components/common/form/_form_field.tsx b/inertia/components/common/form/_form_field.tsx deleted file mode 100644 index d709557..0000000 --- a/inertia/components/common/form/_form_field.tsx +++ /dev/null @@ -1,25 +0,0 @@ -import styled from '@emotion/styled'; - -const FormField = styled('div', { - shouldForwardProp: (propName) => propName !== 'required', -})<{ required?: boolean }>(({ required, theme }) => ({ - display: 'flex', - gap: '0.25em', - flexDirection: 'column', - - '& label': { - position: 'relative', - userSelect: 'none', - width: 'fit-content', - }, - - '& label::after': { - position: 'absolute', - top: 0, - right: '-0.75em', - color: theme.colors.lightRed, - content: (required ? '"*"' : '""') as any, - }, -})); - -export default FormField; diff --git a/inertia/components/common/form/_form_field_error.tsx b/inertia/components/common/form/_form_field_error.tsx deleted file mode 100644 index de3fb4d..0000000 --- a/inertia/components/common/form/_form_field_error.tsx +++ /dev/null @@ -1,9 +0,0 @@ -import styled from '@emotion/styled'; - -// TODO: create a global style variable (fontSize) -const FormFieldError = styled.p(({ theme }) => ({ - fontSize: '12px', - color: theme.colors.lightRed, -})); - -export default FormFieldError; diff --git a/inertia/components/common/form/_input.tsx b/inertia/components/common/form/_input.tsx deleted file mode 100644 index cb0a1e0..0000000 --- a/inertia/components/common/form/_input.tsx +++ /dev/null @@ -1,27 +0,0 @@ -import styled from '@emotion/styled'; - -const Input = styled.input(({ theme }) => ({ - width: '100%', - color: theme.colors.font, - backgroundColor: theme.colors.secondary, - padding: '0.75em', - border: `1px solid ${theme.colors.lightGrey}`, - borderBottom: `2px solid ${theme.colors.lightGrey}`, - borderRadius: theme.border.radius, - transition: theme.transition.delay, - - '&:focus': { - borderBottom: `2px solid ${theme.colors.primary}`, - }, - - '&:disabled': { - opacity: 0.85, - }, - - '&::placeholder': { - fontStyle: 'italic', - color: theme.colors.grey, - }, -})); - -export default Input; diff --git a/inertia/components/common/form/checkbox.tsx b/inertia/components/common/form/checkbox.tsx deleted file mode 100644 index 22f7038..0000000 --- a/inertia/components/common/form/checkbox.tsx +++ /dev/null @@ -1,55 +0,0 @@ -import { ChangeEvent, Fragment, InputHTMLAttributes, useState } from 'react'; -import Toggle from 'react-toggle'; -import FormField from '~/components/common/form/_form_field'; -import FormFieldError from '~/components/common/form/_form_field_error'; - -interface InputProps - extends Omit, 'onChange'> { - label: string; - name: string; - checked: boolean; - errors?: string[]; - onChange?: (name: string, checked: boolean) => void; -} - -export default function Checkbox({ - name, - label, - checked = false, - errors = [], - onChange, - required = false, - ...props -}: InputProps): JSX.Element { - const [checkboxChecked, setCheckboxChecked] = useState(checked); - - if (typeof window === 'undefined') return ; - - function _onChange({ target }: ChangeEvent) { - setCheckboxChecked(target.checked); - if (onChange) { - onChange(target.name, target.checked); - } - } - - return ( - - - - {errors.length > 0 && - errors.map((error) => {error})} - - ); -} diff --git a/inertia/components/common/form/selector.tsx b/inertia/components/common/form/selector.tsx deleted file mode 100644 index af49212..0000000 --- a/inertia/components/common/form/selector.tsx +++ /dev/null @@ -1,79 +0,0 @@ -import { useTheme } from '@emotion/react'; -import { InputHTMLAttributes, ReactNode, useEffect, useState } from 'react'; -import Select, { - FormatOptionLabelMeta, - GroupBase, - OptionsOrGroups, -} from 'react-select'; -import FormField from '~/components/common/form/_form_field'; - -type Option = { label: string | number; value: string | number }; - -interface SelectorProps - extends Omit, 'onChange'> { - label: string; - name: string; - errors?: string[]; - options: OptionsOrGroups>; - value: number | string; - onChangeCallback?: (value: number | string) => void; - formatOptionLabel?: ( - data: Option, - formatOptionLabelMeta: FormatOptionLabelMeta