-
Notifications
You must be signed in to change notification settings - Fork 1
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
Feature/s 10 user settings #19
Changes from 5 commits
2c90bb5
cfb2aae
370550d
c9bcb8e
bb91baa
1ab28c2
e6af8a3
d95e8b7
1b6dc81
6e312db
e352821
183c164
f880ac1
8e6cdf8
8b03023
a4e306b
2497ac0
0593f33
f84aeda
2468187
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import React from 'react'; | ||
import { Collapse, Tag } from 'antd'; | ||
import { BgColorsOutlined } from '@ant-design/icons'; | ||
import { GithubPicker } from 'react-color'; | ||
import { pickerColors, mockedTags as tags, setTagColor, getTagColor, DEFAULT_COLOR } from './userSettingsHandlers'; | ||
import { useLocalStorage } from 'react-use'; | ||
|
||
const SettingsTagColor: React.FC = () => { | ||
const { Panel } = Collapse; | ||
const defaultTagColor = JSON.stringify({ default: DEFAULT_COLOR }); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. According to the source code of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done, removed unnecessary things |
||
const [storedTagColors, setStoredTagColors] = useLocalStorage<string>('tagColors', defaultTagColor); | ||
|
||
const collapseTags = ( | ||
<Collapse accordion ghost> | ||
{tags.map((item) => { | ||
return ( | ||
<Panel | ||
header={ | ||
<Tag | ||
style={{ | ||
cursor: 'pointer', | ||
borderColor: getTagColor(item.name, storedTagColors), | ||
color: getTagColor(item.name, storedTagColors), | ||
backgroundColor: `${getTagColor(item.name, storedTagColors)}10`, | ||
}} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's move these 4 lines of the code to it's own function and call There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Made a new function. It returns an object with styles |
||
> | ||
{item.name} | ||
</Tag> | ||
} | ||
key={item.name} | ||
> | ||
<GithubPicker | ||
colors={pickerColors} | ||
triangle="hide" | ||
width={'138px'} | ||
onChange={(e) => setTagColor(e, item.name, setStoredTagColors, storedTagColors)} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's consider using There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
/> | ||
</Panel> | ||
); | ||
})} | ||
</Collapse> | ||
); | ||
|
||
return ( | ||
<Collapse expandIcon={() => <BgColorsOutlined style={{ fontSize: '20px', color: '#08c' }} />}> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. WDYT about moving There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. made a new component |
||
<Panel header="Change Tag Color" key="tags"> | ||
{collapseTags} | ||
</Panel> | ||
</Collapse> | ||
); | ||
}; | ||
|
||
export default SettingsTagColor; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import React, { useState } from 'react'; | ||
import { Button, Drawer } from 'antd'; | ||
import { SettingOutlined } from '@ant-design/icons'; | ||
import SettingsTagColor from './SettingsTagColor'; | ||
|
||
|
||
const UserSettings: React.FC = () => { | ||
const [isVisible, setIsVisible] = useState(false); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. let's replace with There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. and it's done |
||
const showDrawer = () => { | ||
setIsVisible(true); | ||
}; | ||
const onClose = () => { | ||
setIsVisible(false); | ||
}; | ||
|
||
return ( | ||
<> | ||
<Button icon={<SettingOutlined />} title='User settings' size='large' type="primary" onClick={showDrawer}/> | ||
|
||
<Drawer title="User Settings" placement="right" closable={false} onClose={onClose} visible={isVisible}> | ||
<SettingsTagColor /> | ||
</Drawer> | ||
</> | ||
); | ||
}; | ||
|
||
export default UserSettings; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import { ColorState as IColorState } from 'react-color'; | ||
|
||
export const pickerColors = [ | ||
'#ff0000', | ||
'#FF6900', | ||
'#FCCB00', | ||
'#37D67A', | ||
'#308e00', | ||
'#2db7f5', | ||
'#004DCF', | ||
'#a326f4', | ||
'#FA28FF', | ||
'#F78DA7', | ||
]; | ||
|
||
export const DEFAULT_COLOR = '#308e00'; | ||
|
||
export function setTagColor(e: IColorState, tagName: string, localStorageHook: (value: string) => void, storedTagColors: string | undefined) { | ||
const parsedTagColors = JSON.parse(<string>storedTagColors) || {}; | ||
parsedTagColors[tagName] = e.hex; | ||
localStorageHook(JSON.stringify(parsedTagColors)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can be just: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You're right! Done |
||
} | ||
|
||
export function getTagColor(tagName: string, storedTagColors: string | undefined) { | ||
const parsedTagColors = JSON.parse(<string>(storedTagColors)) || {}; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We can remove JSON.parse and JSON.stringify here too. Also let's move getter and setter to TagSettings file. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Removed unnecessary things. Why should we move getter and setter to |
||
return parsedTagColors[tagName] || DEFAULT_COLOR; | ||
} | ||
|
||
export const mockedTags = [ | ||
{ name: 'deadline' }, | ||
{ name: 'test' }, | ||
{ name: 'jstask' }, | ||
{ name: 'htmltask' }, | ||
{ name: 'externaltask' }, | ||
{ name: 'selfeducation' }, | ||
{ name: 'codewars' }, | ||
{ name: 'codejam' }, | ||
{ name: 'newtask' }, | ||
{ name: 'lecture' }, | ||
{ name: 'lecture_online' }, | ||
{ name: 'lecture_offline' }, | ||
{ name: 'lecture_mixed' }, | ||
{ name: 'lecture_self_study' }, | ||
{ name: 'info' }, | ||
{ name: 'warmup' }, | ||
{ name: 'meetup' }, | ||
{ name: 'workshop' }, | ||
{ name: 'interview' }, | ||
]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think
TagColor
file name will be a better option. It will avoid duplications and shorten import paths at least.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
and it's done too