forked from rolling-scopes/rsschool-app
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: add new schedule table (#13) * feat: add new schedule table * chore: refactor cells renderers * chore: refactor renderers * feat: add switcher schedule view mode * feat: add user settings * chore: refactor code - exclude switch * chore: refactor code * chore: refactor code - add uppercase * fix: implement correct localstorage hook * feat: add userSettings button on schedule page * feat: add user settings * refactor: change serialize/deserialize data * refactor: rename files and data * refactor: change tag color styles structure * refactor: rename vars for better readability * refactor: apply memoization to setTagColor * refactor: change structure of TagIcon * refactor: replace settings button, tweak button styles, change storedTagColors type Co-authored-by: notSAINT <60464016+not-SAINT@users.noreply.github.com> Co-authored-by: Aleksandr Sharikov <notsaint.mail@gmail.com>
- Loading branch information
1 parent
46d337d
commit e18ab75
Showing
7 changed files
with
152 additions
and
16,415 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import React, { useCallback } from 'react'; | ||
import TagColorIcon from './TagColorIcon'; | ||
import { Collapse, Tag } from 'antd'; | ||
import { GithubPicker } from 'react-color'; | ||
import { pickerColors, mockedTags as tags, setTagColor, getTagStyle, DEFAULT_COLOR } from './userSettingsHandlers'; | ||
import { useLocalStorage } from 'react-use'; | ||
import { ColorState as IColorState } from 'react-color'; | ||
|
||
const TagColor: React.FC = () => { | ||
const { Panel } = Collapse; | ||
const [storedTagColors, setStoredTagColors] = useLocalStorage<object>('tagColors', DEFAULT_COLOR); | ||
|
||
const memoizedSetTagColor = useCallback( | ||
(e: IColorState, itemName, storedTagColors) => { | ||
setTagColor(e, itemName, setStoredTagColors, storedTagColors); | ||
}, | ||
[storedTagColors], | ||
); | ||
|
||
const collapseTags = ( | ||
<Collapse accordion ghost> | ||
{tags.map((item) => { | ||
return ( | ||
<Panel | ||
header={ | ||
<Tag | ||
style={getTagStyle(item.name, storedTagColors, { cursor: 'pointer' })} | ||
> | ||
{item.name} | ||
</Tag> | ||
} | ||
key={item.name} | ||
> | ||
<GithubPicker | ||
colors={pickerColors} | ||
triangle="hide" | ||
width={'138px'} | ||
onChange={(e) => memoizedSetTagColor(e, item.name, storedTagColors)} | ||
/> | ||
</Panel> | ||
); | ||
})} | ||
</Collapse> | ||
); | ||
|
||
return ( | ||
<Collapse expandIcon={() => <TagColorIcon />}> | ||
<Panel header="Change Tag Color" key="tags"> | ||
{collapseTags} | ||
</Panel> | ||
</Collapse> | ||
); | ||
}; | ||
|
||
export default TagColor; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import { BgColorsOutlined } from '@ant-design/icons'; | ||
import React from 'react'; | ||
|
||
const TagColorIcon = () => <BgColorsOutlined style={{ fontSize: '20px', color: '#08c', textIndent: '-28px' }} />; | ||
|
||
export default TagColorIcon; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 TagColor from './TagColor'; | ||
|
||
|
||
const UserSettings: React.FC = () => { | ||
const [isOpen, setIsOpen] = useState(false); | ||
const showDrawer = () => { | ||
setIsOpen(true); | ||
}; | ||
const onClose = () => { | ||
setIsOpen(false); | ||
}; | ||
|
||
return ( | ||
<> | ||
<Button icon={<SettingOutlined />} title='User settings' size='middle' type="primary" onClick={showDrawer} /> | ||
|
||
<Drawer title="User Settings" placement="right" closable={false} onClose={onClose} visible={isOpen}> | ||
<TagColor /> | ||
</Drawer> | ||
</> | ||
); | ||
}; | ||
|
||
export default UserSettings; |
57 changes: 57 additions & 0 deletions
57
client/src/components/UserSettings/userSettingsHandlers.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import { ColorState as IColorState } from 'react-color'; | ||
import { CSSProperties } from 'react'; | ||
|
||
export const pickerColors = [ | ||
'#ff0000', | ||
'#FF6900', | ||
'#FCCB00', | ||
'#37D67A', | ||
'#308e00', | ||
'#2db7f5', | ||
'#004DCF', | ||
'#a326f4', | ||
'#FA28FF', | ||
'#F78DA7', | ||
]; | ||
|
||
export const DEFAULT_COLOR = { default: '#308e00' }; | ||
|
||
export function setTagColor(e: IColorState, tagName: string, localStorageHook: (value: object) => void, storedTagColors = {}) { | ||
localStorageHook({ ...storedTagColors, [tagName]: e.hex }); | ||
} | ||
|
||
export function getTagColor(tagName: string, storedTagColors: Record<string, string> = {}) { | ||
return storedTagColors[tagName] || DEFAULT_COLOR.default; | ||
} | ||
|
||
export function getTagStyle(tagName: string, storedTagColors = {}, styles?: CSSProperties) { | ||
const tagColor: string = getTagColor(tagName, storedTagColors); | ||
return { | ||
...styles, | ||
borderColor: tagColor, | ||
color: tagColor, | ||
backgroundColor: `${tagColor}10`, | ||
}; | ||
} | ||
|
||
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' }, | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters