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

frontend case #15

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
18 changes: 18 additions & 0 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
module.exports = {
root: true,
env: { browser: true, es2020: true },
extends: [
'eslint:recommended',
'plugin:@typescript-eslint/recommended',
'plugin:react-hooks/recommended',
],
ignorePatterns: ['dist', '.eslintrc.cjs'],
parser: '@typescript-eslint/parser',
plugins: ['react-refresh'],
rules: {
'react-refresh/only-export-components': [
'warn',
{ allowConstantExport: true },
],
},
}
24 changes: 24 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*
lerna-debug.log*

node_modules
dist
dist-ssr
*.local

# Editor directories and files
.vscode/*
!.vscode/extensions.json
.idea
.DS_Store
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw?
13 changes: 13 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Vite + React + TS</title>
</head>
<body>
<div id="root"></div>
<script type="module" src="/src/main.tsx"></script>
</body>
</html>
30 changes: 30 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"name": "frontend-case",
"private": true,
"version": "0.0.0",
"type": "module",
"scripts": {
"dev": "vite",
"build": "tsc && vite build",
"lint": "eslint . --ext ts,tsx --report-unused-disable-directives --max-warnings 0",
"preview": "vite preview"
},
"dependencies": {
"@reduxjs/toolkit": "^1.9.7",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-redux": "^8.1.3"
},
"devDependencies": {
"@types/react": "^18.2.15",
"@types/react-dom": "^18.2.7",
"@typescript-eslint/eslint-plugin": "^6.0.0",
"@typescript-eslint/parser": "^6.0.0",
"@vitejs/plugin-react": "^4.0.3",
"eslint": "^8.45.0",
"eslint-plugin-react-hooks": "^4.6.0",
"eslint-plugin-react-refresh": "^0.4.3",
"typescript": "^5.0.2",
"vite": "^4.4.5"
}
}
19 changes: 19 additions & 0 deletions prettier.config.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
module.exports = {
arrowParens: 'avoid',
bracketSameLine: false,
bracketSpacing: true,
embeddedLanguageFormatting: 'auto',
htmlWhitespaceSensitivity: 'css',
insertPragma: false,
jsxSingleQuote: true,
proseWrap: 'preserve',
quoteProps: 'preserve',
requirePragma: false,
semi: false,
singleQuote: true,
printWidth: 130,
tabWidth: 2,
trailingComma: 'es5',
useTabs: false,
vueIndentScriptAndStyle: false,
}
File renamed without changes.
1 change: 1 addition & 0 deletions public/vite.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
123 changes: 123 additions & 0 deletions src/App.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
:root {
--borderColor: #d5d4d0;
--border: 2px solid var(--borderColor);
--borderThin: 1px solid var(--borderColor);
--borderRadius: 6px;
--bgColor: #f8f8f8;
--textColor: #3064d0;
--boxSize: 16px;
}

#root {
max-width: 1280px;
margin: 0 auto;
padding: 2rem;
text-align: center;
}

.multiplesearch__wrapper {
display: flex;
justify-content: center;
flex-direction: column;
padding: 2rem;
text-align: left;
border: var(--border);
border-radius: var(--borderRadius);
background-color: var(--bgColor);
}

.input__wrapper {
display: flex;
align-items: center;
justify-content: center;
position: relative;
}

.list__container {
overflow-y: auto;
max-height: calc(100vh / 2);
margin: 20px 0;
}

.list__container::-webkit-scrollbar {
width: 6px;
}

/* Track */
.list__container::-webkit-scrollbar-track {
background: rgba(128, 128, 128, 0.24);
border-radius: var(--borderRadius);
}

/* Handle */
.list__container::-webkit-scrollbar-thumb {
background: grey;
border-radius: var(--borderRadius);
}

/* Handle on hover */
.list__container::-webkit-scrollbar-thumb:hover {
background: grey;
}

.searchInput {
width: 100%;
padding: 8px;
border: var(--border);
border-radius: var(--borderRadius);
}

.searchIcon {
position: absolute;
right: 10px;
}

.checked__wrapper {
text-align: left;
}

.checkbox__wrapper {
display: flex;
align-items: center;
justify-content: flex-start;
cursor: pointer;
gap: 12px;
margin: 12px 0;
}

.check {
display: flex;
align-items: center;
justify-content: center;
width: var(--boxSize);
height: var(--boxSize);
background-color: var(--bgColor);
border: var(--border);
}

.checked {
--bgColor: var(--textColor);
width: calc(var(--boxSize) - 4px);
height: calc(var(--boxSize) - 4px);
background-color: var(--bgColor);
}

.list {
padding-right: 0;
border-bottom: 2px solid #8080803b;
margin-right: 20px;
}

.list:first-child:has(.checked) {
color: var(--textColor);
}

.button {
--border: 2px solid black;
text-align: center;
color: var(--bgColor);
background-color: var(--textColor);
padding: 20px;
border-bottom: var(--border);
border-radius: var(--borderRadius);
}
43 changes: 43 additions & 0 deletions src/App.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import { useEffect } from 'react'
import MultipleSearch from './components/MultipleSearch'
import { actions, useAppSelector, AppDispatch } from './redux/store'
import { useDispatch } from 'react-redux'
import { ISearchData } from './redux/category/category.entity'
import { clearSearchCategory, searchCategory, toggleCategory } from './redux/category/category.action'
import './App.css'

function App() {
const dispatch = useDispatch<AppDispatch>()

const searchData = useAppSelector(state => state.category.categories.filter(item => item.checked === false))
const searchDataChecked = useAppSelector(state => state.category.categories.filter(item => item.checked))
const searchedCategory = useAppSelector(state => state.category.search.filter(item => item.checked === false))

const handleToggle = (props: ISearchData) => {
dispatch(toggleCategory(props.id))
dispatch(clearSearchCategory(props.id))
}

const handleSearch = (value: string) => {
if (value.length > 2) {
dispatch(searchCategory(value))
} else {
dispatch(clearSearchCategory())
}
}
useEffect(() => {
dispatch(actions.category.getCategories())
}, [])

return (
<MultipleSearch
onClickItem={handleToggle}
onSearch={handleSearch}
searchData={searchData}
searchDataChecked={searchDataChecked}
searchedCategory={searchedCategory}
/>
)
}

export default App
File renamed without changes
1 change: 1 addition & 0 deletions src/assets/react.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
File renamed without changes
3 changes: 3 additions & 0 deletions src/components/Button.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export default function Button() {
return <div className='button'>Ara</div>
}
22 changes: 22 additions & 0 deletions src/components/CheckBox.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { ISearchData } from '../redux/category/category.entity'

interface ICheckBox {
id: string
label: string
checked: boolean
onClickItem: (arg: ISearchData) => void
type: 'search' | 'list' | 'checked'
}

export default function CheckBox({ id, checked, label, onClickItem, type }: ICheckBox) {
const handleClick = () => {
onClickItem({ checked, id, label })
}

return (
<div key={`${type}__${id}`} className='checkbox__wrapper' onClick={handleClick}>
<div className='check'>{checked ? <div className='checked'></div> : <div className='default'></div>}</div>
<div className='label'>{label}</div>
</div>
)
}
54 changes: 54 additions & 0 deletions src/components/MultipleSearch.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import { ISearchData } from '../redux/category/category.entity'
import Button from './Button'
import CheckBox from './CheckBox'
import SearchInput from './SearchInput'

interface IMultipeSearch {
searchData: ISearchData[]
searchDataChecked: ISearchData[]
searchedCategory: ISearchData[]
onSearch: (arg: string) => void
onClickItem: (arg: ISearchData) => void
}

export default function MultipleSearch({
searchData,
searchDataChecked,
searchedCategory,
onClickItem,
onSearch,
}: IMultipeSearch) {
return (
<div className='multiplesearch__wrapper'>
<h3>Kategoriler</h3>
<SearchInput onChange={onSearch} />

<div className='list__container'>
{searchDataChecked.length > 0 ? (
<div className='list'>
{searchDataChecked.map(item => {
return <CheckBox onClickItem={onClickItem} type='checked' {...item} />
})}
</div>
) : null}

{searchedCategory.length > 0 ? (
<div className='list'>
{searchedCategory.map(item => {
return <CheckBox onClickItem={onClickItem} type='search' {...item} />
})}
</div>
) : null}

{searchedCategory.length === 0 && searchData.length > 0 ? (
<div className='list'>
{searchData.map(item => {
return <CheckBox onClickItem={onClickItem} type='list' {...item} />
})}
</div>
) : null}
</div>
<Button />
</div>
)
}
15 changes: 15 additions & 0 deletions src/components/SearchInput.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import searchSvg from '../assets/search.svg'
interface ISearchInput {
onChange: (arg0: string) => void
}

export default function SearchInput({ onChange }: ISearchInput) {
return (
<div className='input__wrapper'>
<input className='searchInput' type='text' onChange={e => onChange(e.target?.value || '')} placeholder='kategori ara...' />
<div className='searchIcon'>
<img src={searchSvg} />
</div>
</div>
)
}
12 changes: 12 additions & 0 deletions src/index.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
:root {
font-family: Inter, system-ui, Avenir, Helvetica, Arial, sans-serif;
font-weight: 500;
}

body {
margin: 0;
display: flex;
place-items: center;
min-width: 320px;
min-height: 100vh;
}
Loading