Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/add settings layout #33

Merged
merged 25 commits into from
Dec 29, 2023
Merged
Show file tree
Hide file tree
Changes from 24 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
941a7f6
Merge branch 'feature/add-layout-resize' of https://github.com/Quiddl…
Tedzury Dec 23, 2023
fa5b7f9
feat: add layout and functionality for settigns page. Add headers, th…
Tedzury Dec 25, 2023
dc18e99
feat: add logic and layout for showing and closing confirm modal window
Tedzury Dec 26, 2023
5a4dab6
feat: add localization for setting page
Tedzury Dec 26, 2023
9089262
feat: add logic for switching the app color theme
Tedzury Dec 26, 2023
e57fc84
feat: add logic and UI for undo data clearance
Tedzury Dec 26, 2023
f4d2b67
feat: add tests for settings page
Tedzury Dec 26, 2023
6914f50
test: attempt to fix tests #1
Tedzury Dec 26, 2023
75f2760
test: attempt to fix tests #2
Tedzury Dec 26, 2023
d866f53
docs: attepmt to fix tests
Quiddlee Dec 26, 2023
228e7e8
Merge branch 'develop' into feat/add_settings_layout
Quiddlee Dec 26, 2023
798e3ac
Update main.yml
Quiddlee Dec 26, 2023
632406d
test: attempt to fix test #3
Tedzury Dec 27, 2023
3f84893
Merge branch 'feat/add_settings_layout' of https://github.com/Quiddle…
Tedzury Dec 27, 2023
ea1380f
test: attempts to fix tests #4
Tedzury Dec 27, 2023
79bd1ff
test: attempts to fix tests #5
Tedzury Dec 27, 2023
ccda1d0
test: attempts to fix tests #6
Tedzury Dec 27, 2023
7401b31
test: attempts to fix tests #7
Tedzury Dec 27, 2023
6c56b2a
test: attempts to fix tests #8
Tedzury Dec 27, 2023
d404f79
test: attempts to fix tests #9
Tedzury Dec 27, 2023
b198e12
test: attempts to fix tests #10
Tedzury Dec 27, 2023
a8a4935
feat: pull develop branch, resolve merge conflicts
Tedzury Dec 27, 2023
f8eb6f5
fix: fix small layout issues
Tedzury Dec 27, 2023
01b623d
fix: remove nanoid from deps. Changed keys in Li to names
Tedzury Dec 27, 2023
753ee7a
fix: fix small issues which were requested during code review
Tedzury Dec 28, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ module.exports = {
'import/no-extraneous-dependencies': 0,
'react/function-component-definition': 0,
'no-underscore-dangle': 0,
'jsx-a11y/no-static-element-interactions': 0,
'react-refresh/only-export-components': ['warn', { allowConstantExport: true }],
'sort-imports': ['error', {ignoreCase: true, ignoreDeclarationSort: true}],
'import/order': [
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ on:
types: [opened, synchronize]

env:
NODE_VERSION: 18.16.0
NODE_VERSION: 21.5.0

jobs:
linting:
Expand Down
58 changes: 39 additions & 19 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"react-dom": "^18.2.0",
"react-hook-form": "^7.48.2",
"react-router-dom": "^6.20.1",
"react-toastify": "^9.1.3",
"toastify-js": "^1.12.0",
"yup": "^1.3.2"
},
Expand All @@ -37,8 +38,8 @@
"@types/node": "^20.10.3",
"@types/react": "^18.2.37",
"@types/react-dom": "^18.2.15",
"@types/toastify-js": "^1.12.3",
"@types/react-test-renderer": "^18.0.7",
"@types/toastify-js": "^1.12.3",
"@typescript-eslint/eslint-plugin": "^6.13.2",
"@typescript-eslint/parser": "^6.13.2",
"@vitejs/plugin-react": "^4.2.0",
Expand Down
9 changes: 9 additions & 0 deletions src/app/App.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,19 @@
import { useEffect } from 'react';

import { RouterProvider } from 'react-router-dom';

import router from '@/router/router';
import colorThemeSwitcher from '@/shared/helpers/colorThemeSwitcher';
import AuthProvider from '@shared/Context/AuthContext';
import LanguageProvider from '@shared/Context/LanguageContext';

const App = () => {
useEffect(() => {
const isLightTheme = localStorage.getItem('graphiQlColorTheme');
if (isLightTheme) {
colorThemeSwitcher.setLight();
}
}, []);
Tedzury marked this conversation as resolved.
Show resolved Hide resolved
return (
<AuthProvider>
<LanguageProvider>
Expand Down
8 changes: 4 additions & 4 deletions src/components/DocsComp/ui/DocsOverlay.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ type PropsType = {
};

const DocsOverlay = ({ isShown, setIsDocsShown, explorer, children }: PropsType) => {
function closeHandler(e: React.MouseEvent<HTMLButtonElement, MouseEvent>) {
function closeHandler(e: React.MouseEvent<HTMLDivElement, MouseEvent> | React.KeyboardEvent<HTMLDivElement>) {
if ((e.target as HTMLButtonElement).hasAttribute('data-overlay')) {
setIsDocsShown((prev) => !prev);
explorer.setInitState();
Expand All @@ -23,15 +23,15 @@ const DocsOverlay = ({ isShown, setIsDocsShown, explorer, children }: PropsType)
return null;
}
return (
<button
<div
data-testid="overlay"
data-overlay
type="button"
onClick={(e) => closeHandler(e)}
onKeyDown={(e) => closeHandler(e)}
className="overlay absolute left-0 top-0 z-10 flex h-full w-full justify-start bg-black/60 "
>
{children}
</button>
</div>
);
};

Expand Down
2 changes: 1 addition & 1 deletion src/components/DocsComp/ui/DocsRootComp.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const DocsRootComp = ({ types, explorer }: { types: SchemaTypeObj[]; explorer: D
<div ref={rootRef} className="h-full">
<div className="rounded-[24px] bg-surface-container px-10 py-[56px] text-left text-on-surface sm:px-[56px]">
<h3 className="text-[57px] font-[500]">Docs</h3>
<p className="text-md text-left">A GraphQL schema provides a root type for each kind of operation.</p>
<p className="text-md mt-10 text-left">A GraphQL schema provides a root type for each kind of operation.</p>
</div>
<div className="mt-[56px] p-10 text-left font-[500] sm:px-[56px]">
<h4 className="text-[28px]">Root types:</h4>
Expand Down
8 changes: 4 additions & 4 deletions src/components/DocsComp/ui/DocsTypeComp.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ const DocsTypeComp = ({ explorer, currType }: { explorer: DocsExplorerType; curr
const beforeSeparator = <br />;
const afterSeparator = i >= field.args.length - 1 ? <br /> : null;
return (
<>
<p key={argTypeName.concat(i.toString())} className="inline">
{separation && beforeSeparator}
<span className={separation ? 'pl-3' : ''} key={argTypeName}>
<span className={separation ? 'pl-3' : ''}>
<span className="text-tertiary">{arg.name}</span>:&nbsp;
{before}
<a className="text-docs-link-text-color hover:underline" href={link} onClick={(e) => clinkHandler(e, link)}>
Expand All @@ -30,7 +30,7 @@ const DocsTypeComp = ({ explorer, currType }: { explorer: DocsExplorerType; curr
{after}
</span>
{separation && afterSeparator}
</>
</p>
);
});
const returnType = getTypeName(field.type);
Expand All @@ -56,7 +56,7 @@ const DocsTypeComp = ({ explorer, currType }: { explorer: DocsExplorerType; curr
});
const inputFields = currType?.inputFields?.map((field) => {
return (
<li key={field.name}>
<li key={field?.type?.name}>
{field.name}:&nbsp;
<a
className="text-docs-link-text-color hover:underline"
Expand Down
34 changes: 34 additions & 0 deletions src/components/SettingsPageComp/ClearStorageComp.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { useState } from 'react';

import useLanguage from '@/shared/Context/hooks';
import FilledTonalButton from '@/shared/ui/FilledTonalButton';

import ConfirmModal from './ConfirmModal';
import ConfirmOverlay from './ConfirmOverlay';

const ClearStorageComp = () => {
const [isModalShown, setIsModalShown] = useState(false);
const { translation } = useLanguage();

return (
<>
<div className="mt-6 flex items-center justify-between pb-6">
<div className="flex flex-col justify-between">
<h4 className="text-[22px]">{translation.settingsPage.clear.title}</h4>
<p className="mt-4">{translation.settingsPage.clear.subtitle}</p>
</div>
<FilledTonalButton data-clear-btn className="text-primary" onClick={() => setIsModalShown((prev) => !prev)}>
{translation.settingsPage.clear.btn}
</FilledTonalButton>
</div>
<ConfirmOverlay isShown={isModalShown} setIsShown={setIsModalShown}>
<ConfirmModal
setIsShown={setIsModalShown}
locales={{ ...translation.settingsPage.clear.modal, ...translation.settingsPage.clear.undo }}
/>
</ConfirmOverlay>
</>
);
};

export default ClearStorageComp;
44 changes: 44 additions & 0 deletions src/components/SettingsPageComp/ClearUndo.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import { useEffect, useState } from 'react';

type UndoPropsType = {
closeToast: () => void;
title: string;
btn: string;
};

const ClearUndo = (props: UndoPropsType) => {
const { closeToast, title, btn } = props;
const [deleteDataTimeout, setDeleteDataTimeout] = useState(null as unknown as NodeJS.Timeout);

const dataClearance = () => {
localStorage.clear();
};

useEffect(() => {
const timeoutId = setTimeout(() => {
dataClearance();
}, 2000);

setDeleteDataTimeout(timeoutId);

return () => {
clearTimeout(timeoutId);
};
}, []);

const handleClick = () => {
clearTimeout(deleteDataTimeout);
closeToast();
};

return (
<div className="flex items-center justify-around text-sm">
<p className="font-[400] text-inverse-on-surface">{title}</p>
<button className="font-[500] text-inverse-primary" type="button" onClick={handleClick}>
{btn}
</button>
</div>
);
};

export default ClearUndo;
47 changes: 47 additions & 0 deletions src/components/SettingsPageComp/ConfirmModal.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import { Dispatch, FC, SetStateAction } from 'react';

import { toast } from 'react-toastify';
import 'react-toastify/dist/ReactToastify.css';

import FilledTonalButton from '@/shared/ui/FilledTonalButton';
import Icon from '@/shared/ui/Icon';
import TextButton from '@/shared/ui/TextButton';

import 'toastify-js/src/toastify.css';
import ClearUndo from './ClearUndo';
Tedzury marked this conversation as resolved.
Show resolved Hide resolved

type PropsType = {
setIsShown: Dispatch<SetStateAction<boolean>>;
locales: {
title: string;
subtitle: string;
cancel: string;
confirm: string;
undoTitle: string;
cancelBtn: string;
};
};

const ConfirmModal: FC<PropsType> = ({ setIsShown, locales }) => {
const { title, subtitle, cancel, confirm, undoTitle, cancelBtn } = locales;
return (
<div className="w-[312px] rounded-4xl bg-surface-container-high p-6 text-center font-[500] text-on-surface">
<Icon>delete</Icon>
<h3 className="mt-4 text-2xl">{title}</h3>
<p className="mt-4 text-start text-sm text-on-surface-variant">{subtitle}</p>
<div className="mt-6 flex justify-end gap-2">
<TextButton onClick={() => setIsShown((prev) => !prev)}>{cancel}</TextButton>
<FilledTonalButton
onClick={() => {
toast(<ClearUndo closeToast={() => {}} title={undoTitle} btn={cancelBtn} />);
setIsShown((prev) => !prev);
}}
>
{confirm}
</FilledTonalButton>
</div>
</div>
);
};

export default ConfirmModal;
29 changes: 29 additions & 0 deletions src/components/SettingsPageComp/ConfirmOverlay.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
type PropsType = {
setIsShown: React.Dispatch<React.SetStateAction<boolean>>;
isShown: boolean;
children: JSX.Element;
};

const ConfirmOverlay = ({ isShown, setIsShown, children }: PropsType) => {
function closeHandler(e: React.MouseEvent<HTMLDivElement, MouseEvent> | React.KeyboardEvent<HTMLDivElement>) {
if ((e.target as HTMLButtonElement).hasAttribute('data-overlay')) {
setIsShown((prev) => !prev);
}
}
if (!isShown) {
return null;
}
return (
<div
data-testid="overlay"
data-overlay
onClick={(e) => closeHandler(e)}
onKeyDown={(e) => closeHandler(e)}
className="overlay absolute left-0 top-0 z-10 flex h-full w-full items-center justify-center bg-black/60"
>
{children}
</div>
);
};

export default ConfirmOverlay;
Loading