Skip to content

Commit

Permalink
Merge pull request #599 from Ekep-Obasi/admin-settings-area
Browse files Browse the repository at this point in the history
feat: refactor settings to new Settings cog and implement admin/non-a…
  • Loading branch information
Rassl authored Nov 17, 2023
2 parents f114a3a + a8115e2 commit 2761387
Show file tree
Hide file tree
Showing 9 changed files with 382 additions and 7 deletions.
1 change: 1 addition & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ module.exports = {
'no-unused-expressions': 'off',
'no-use-before-define': 'off',
'no-useless-constructor': 'off',
'no-console': ['warn', { allow: ['warn', 'error'] }],
'padding-line-between-statements': [
'error',
{ blankLine: 'always', next: 'return', prev: '*' },
Expand Down
4 changes: 2 additions & 2 deletions src/components/App/ActionsToolbar/GraphViewControl/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export const GraphViewControl = () => {
}

return (
<Wrapper>
<Wrapper direction="column">
{graphStyles.map((i) => (
<Flex key={i} className={clsx('icon', { active: graphStyle === i })} onClick={() => changeGraphType(i)}>
{IconsMapper[i]}
Expand All @@ -44,7 +44,7 @@ export const GraphViewControl = () => {
const Wrapper = styled(Flex).attrs({
direction: 'row',
align: 'center',
justify: 'flex-start',
justify: 'space-between',
})`
padding: 6px 6px 6px 11px;
background: ${colors.BG1};
Expand Down
18 changes: 13 additions & 5 deletions src/components/App/MainToolbar/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import styled from 'styled-components'
import AddContentIcon from '~/components/Icons/AddContentIcon'
import AddSourceIcon from '~/components/Icons/AddSourceIcon'
import SentimentDataIcon from '~/components/Icons/SentimentDataIcon'
import SettingsIcon from '~/components/Icons/SettingsIcon'
import SourcesTableIcon from '~/components/Icons/SourcesTableIcon'
import { Flex } from '~/components/common/Flex'
Expand All @@ -15,14 +16,15 @@ export const MainToolbar = () => {
const { open: openSourcesModal } = useModal('sourcesTable')
const { open: openContentAddModal } = useModal('addContent')
const { open: openSourceAddModal } = useModal('addSource')
const { open: openSettingsModal } = useModal('settings')

const handleOpenSidebar = (tab: SecondarySidebarActiveTab) => {
setSecondarySidebarActiveTab(tab)
}

return (
<Wrapper>
<LogoButton onClick={() => handleOpenSidebar('about')}>
<LogoButton>
<img alt="Second brain" src="logo.svg" />
</LogoButton>
<ActionButton onClick={openContentAddModal}>
Expand All @@ -43,11 +45,17 @@ export const MainToolbar = () => {
</IconWrapper>
<Text>Source Table</Text>
</ActionButton>
<ActionButton>
<ActionButton id="cy-open-sentiment-data" onClick={() => handleOpenSidebar('sentiment')}>
<IconWrapper>
<SentimentDataIcon />
</IconWrapper>
<Text>Sentiment Data</Text>
</ActionButton>
<ActionButton onClick={openSettingsModal}>
<IconWrapper>
<SettingsIcon />
</IconWrapper>
<Text>Settings</Text>
<Text>Change Display</Text>
</ActionButton>
</Wrapper>
)
Expand Down Expand Up @@ -108,7 +116,7 @@ const ActionButton = styled(Flex).attrs({
border-radius: 4px;
background: #000;
box-shadow: 0px 4px 8px 0px rgba(0, 0, 0, 0.25);
position absolute;
position: absolute;
left: 90%;
z-index: 99;
white-space: nowrap;
Expand All @@ -120,7 +128,7 @@ const ActionButton = styled(Flex).attrs({
}
&:hover {
color: ${colors.white};
color: ${colors.white};
&:before {
width: 3px;
Expand Down
2 changes: 2 additions & 0 deletions src/components/App/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import { E2ETests } from '~/utils/tests'
import version from '~/utils/versionHelper'
import { AddContentModal } from '../AddContentModal'
import { AddSourceModal } from '../AddSourceModal'
import { SettingsModal } from '../SettingsModal'
import { SourcesTableModal } from '../SourcesTableModal'
import { Preloader } from '../Universe/Preloader'
import { ActionsToolbar } from './ActionsToolbar'
Expand Down Expand Up @@ -166,6 +167,7 @@ export const App = () => {

<AddContentModal />
<AddSourceModal />
<SettingsModal />

<Toasts />

Expand Down
27 changes: 27 additions & 0 deletions src/components/SettingsModal/Appearance/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import styled from 'styled-components'
import { GraphViewControl } from '~/components/App/ActionsToolbar/GraphViewControl'
import { Button } from '~/components/Button'
import { Flex } from '~/components/common/Flex'
import { Text } from '~/components/common/Text'

export const Appearance = () => (
<Wrapper direction="column">
<StyledText>Default graph view:</StyledText>
<GraphViewControl />
<Flex mt={308}>
<Button kind="big">Save changes</Button>
</Flex>
</Wrapper>
)

const Wrapper = styled(Flex)`
display: flex;
gap: 10px;
padding: 36px;
`

const StyledText = styled(Text)`
font-family: Barlow;
font-size: 13px;
font-weight: 400;
`
112 changes: 112 additions & 0 deletions src/components/SettingsModal/General/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
import { FC } from 'react'
import { FormProvider, useForm } from 'react-hook-form'
import { ClipLoader } from 'react-spinners'
import styled from 'styled-components'
import { Button } from '~/components/Button'
import { Flex } from '~/components/common/Flex'
import { TextInput } from '~/components/common/TextInput'
import { requiredRule } from '~/constants'
import { TAboutParams, postAboutData } from '~/network/fetchSourcesData'
import { colors } from '~/utils/colors'

type Props = {
initialValues: TAboutParams
}

export const General: FC<Props> = ({ initialValues }) => {
const form = useForm<TAboutParams>({ defaultValues: initialValues, mode: 'onSubmit' })
const { isSubmitting } = form.formState

const onSubmit = form.handleSubmit(async (data) => {
try {
await postAboutData(data)
} catch (error) {
console.warn(error)
}
})

return (
<FormProvider {...form}>
<StyledForm id="add-node-form" onSubmit={onSubmit}>
<>
<Flex>
<Flex pt={20}>
<TextInput
id="cy-about-title-id"
label="Graph Title"
maxLength={50}
name="title"
placeholder="Type graph title here..."
rules={{
...requiredRule,
}}
/>
</Flex>
<Flex pt={20}>
<TextInput
id="cy-about-id"
label="Graph Description"
maxLength={50}
name="description"
placeholder="Type graph description here..."
rules={{
...requiredRule,
}}
/>
</Flex>
<Flex pt={20}>
<TextInput
id="cy-about-mission_statement-id"
label="Mission Statement"
maxLength={50}
name="mission_statement"
placeholder="Type mission statement here..."
rules={{
...requiredRule,
}}
/>
</Flex>
<Flex pt={20}>
<TextInput
id="cy-about-search_term-id"
label="Search Term"
maxLength={50}
name="search_term"
placeholder="Type search term here..."
rules={{
...requiredRule,
}}
/>
</Flex>
</Flex>

<Flex my={36} py={24}>
{isSubmitting ? (
<SubmitLoader>
<ClipLoader color={colors.white} size={20} />
</SubmitLoader>
) : (
<Button disabled={isSubmitting} id="add-node-submit-cta" kind="big" type="submit">
Save changes
</Button>
)}
</Flex>
</>
</StyledForm>
</FormProvider>
)
}

const SubmitLoader = styled(Flex).attrs({
align: 'center',
background: 'primaryButton',
borderRadius: 8,
justify: 'center',
})`
padding: 16px 24px;
opacity: 0.5;
`

const StyledForm = styled.form`
padding: 36px;
`
Loading

0 comments on commit 2761387

Please sign in to comment.