diff --git a/client/src/components/Settings/OtherSettings/OtherSettings.tsx b/client/src/components/Settings/OtherSettings/OtherSettings.tsx index afaf072..1ca0d83 100644 --- a/client/src/components/Settings/OtherSettings/OtherSettings.tsx +++ b/client/src/components/Settings/OtherSettings/OtherSettings.tsx @@ -13,7 +13,6 @@ import { import { GlobalState, NewNotification, - Query, SettingsForm, } from '../../../interfaces'; @@ -26,7 +25,6 @@ import classes from './OtherSettings.module.css'; // Utils import { searchConfig } from '../../../utility'; -import { queries } from '../../../utility/searchQueries.json'; interface ComponentProps { createNotification: (notification: NewNotification) => void; @@ -45,15 +43,12 @@ const OtherSettings = (props: ComponentProps): JSX.Element => { hideHeader: 0, hideApps: 0, hideCategories: 0, - hideSearch: 0, - defaultSearchProvider: 'd', useOrdering: 'createdAt', appsSameTab: 0, bookmarksSameTab: 0, - searchSameTab: 0, - dockerApps: 1, - kubernetesApps: 1, - unpinStoppedApps: 1, + dockerApps: 0, + kubernetesApps: 0, + unpinStoppedApps: 0, }); // Get config @@ -65,12 +60,9 @@ const OtherSettings = (props: ComponentProps): JSX.Element => { hideHeader: searchConfig('hideHeader', 0), hideApps: searchConfig('hideApps', 0), hideCategories: searchConfig('hideCategories', 0), - hideSearch: searchConfig('hideSearch', 0), - defaultSearchProvider: searchConfig('defaultSearchProvider', 'd'), useOrdering: searchConfig('useOrdering', 'createdAt'), appsSameTab: searchConfig('appsSameTab', 0), bookmarksSameTab: searchConfig('bookmarksSameTab', 0), - searchSameTab: searchConfig('searchSameTab', 0), dockerApps: searchConfig('dockerApps', 0), kubernetesApps: searchConfig('kubernetesApps', 0), unpinStoppedApps: searchConfig('unpinStoppedApps', 0), @@ -168,35 +160,6 @@ const OtherSettings = (props: ComponentProps): JSX.Element => { Custom order - - Default Search Provider - inputChangeHandler(e)} - > - {queries.map((query: Query, idx) => ( - - {query.name} - - ))} - - - - - Open search results in the same tab - - inputChangeHandler(e, true)} - > - True - False - - Open applications in the same tab { {/* MODULES OPTIONS */} Modules - - Hide search bar - inputChangeHandler(e, true)} - > - True - False - - Hide greeting and date void; + updateConfig: (formData: SearchForm) => void; + loading: boolean; +} + +const SearchSettings = (props: Props): JSX.Element => { + // Initial state + const [formData, setFormData] = useState({ + hideSearch: 0, + defaultSearchProvider: 'l', + searchSameTab: 0, + }); + + // Get config + useEffect(() => { + setFormData({ + hideSearch: searchConfig('hideSearch', 0), + defaultSearchProvider: searchConfig('defaultSearchProvider', 'd'), + searchSameTab: searchConfig('searchSameTab', 0), + }); + }, [props.loading]); + + // Form handler + const formSubmitHandler = async (e: FormEvent) => { + e.preventDefault(); + + // Save settings + await props.updateConfig(formData); + }; + + // Input handler + const inputChangeHandler = ( + e: ChangeEvent, + isNumber?: boolean + ) => { + let value: string | number = e.target.value; + + if (isNumber) { + value = parseFloat(value); + } + + setFormData({ + ...formData, + [e.target.name]: value, + }); + }; + + return ( + formSubmitHandler(e)}> + + Default Search Provider + inputChangeHandler(e)} + > + {queries.map((query: Query, idx) => ( + + {query.name} + + ))} + + + + + Open search results in the same tab + + inputChangeHandler(e, true)} + > + True + False + + + + Hide search bar + inputChangeHandler(e, true)} + > + True + False + + + Save changes + + ); +}; + +const mapStateToProps = (state: GlobalState) => { + return { + loading: state.config.loading, + }; +}; + +const actions = { + createNotification, + updateConfig, +}; + +export default connect(mapStateToProps, actions)(SearchSettings); diff --git a/client/src/components/Settings/Settings.tsx b/client/src/components/Settings/Settings.tsx index b1eb300..5df8ec6 100644 --- a/client/src/components/Settings/Settings.tsx +++ b/client/src/components/Settings/Settings.tsx @@ -1,73 +1,61 @@ +// import { NavLink, Link, Switch, Route } from 'react-router-dom'; +// Typescript +import { Route as SettingsRoute } from '../../interfaces'; + +// CSS import classes from './Settings.module.css'; -import { Container } from '../UI/Layout/Layout'; -import Headline from '../UI/Headlines/Headline/Headline'; - +// Components import Themer from '../Themer/Themer'; import WeatherSettings from './WeatherSettings/WeatherSettings'; import OtherSettings from './OtherSettings/OtherSettings'; import AppDetails from './AppDetails/AppDetails'; import StyleSettings from './StyleSettings/StyleSettings'; +import SearchSettings from './SearchSettings/SearchSettings'; + +// UI +import { Container } from '../UI/Layout/Layout'; +import Headline from '../UI/Headlines/Headline/Headline'; + +// Data +import { routes } from './settings.json'; const Settings = (): JSX.Element => { return ( - Go back} - /> + Go back} /> + {/* NAVIGATION MENU */} - - Theme - - - Weather - - - Other - - - CSS - - - App - + {routes.map(({ name, dest }: SettingsRoute, idx) => ( + + {name} + + ))} + + {/* ROUTES */} - - - - - + + + + + + - ) -} + ); +}; -export default Settings; \ No newline at end of file +export default Settings; diff --git a/client/src/components/Settings/settings.json b/client/src/components/Settings/settings.json new file mode 100644 index 0000000..3cc24e9 --- /dev/null +++ b/client/src/components/Settings/settings.json @@ -0,0 +1,28 @@ +{ + "routes": [ + { + "name": "Theme", + "dest": "/settings" + }, + { + "name": "Weather", + "dest": "/settings/weather" + }, + { + "name": "Search", + "dest": "/settings/search" + }, + { + "name": "Other", + "dest": "/settings/other" + }, + { + "name": "CSS", + "dest": "/settings/css" + }, + { + "name": "App", + "dest": "/settings/app" + } + ] +} diff --git a/client/src/interfaces/Forms.ts b/client/src/interfaces/Forms.ts index 177821d..22856be 100644 --- a/client/src/interfaces/Forms.ts +++ b/client/src/interfaces/Forms.ts @@ -5,6 +5,12 @@ export interface WeatherForm { isCelsius: number; } +export interface SearchForm { + hideSearch: number; + defaultSearchProvider: string; + searchSameTab: number; +} + export interface SettingsForm { customTitle: string; pinAppsByDefault: number; @@ -12,12 +18,12 @@ export interface SettingsForm { hideHeader: number; hideApps: number; hideCategories: number; - hideSearch: number; - defaultSearchProvider: string; + // hideSearch: number; + // defaultSearchProvider: string; useOrdering: string; appsSameTab: number; bookmarksSameTab: number; - searchSameTab: number; + // searchSameTab: number; dockerApps: number; kubernetesApps: number; unpinStoppedApps: number; diff --git a/client/src/interfaces/Route.ts b/client/src/interfaces/Route.ts new file mode 100644 index 0000000..9d571dd --- /dev/null +++ b/client/src/interfaces/Route.ts @@ -0,0 +1,4 @@ +export interface Route { + name: string; + dest: string; +} diff --git a/client/src/interfaces/index.ts b/client/src/interfaces/index.ts index 6892fb5..b9683dd 100644 --- a/client/src/interfaces/index.ts +++ b/client/src/interfaces/index.ts @@ -10,3 +10,4 @@ export * from './Config'; export * from './Forms'; export * from './Query'; export * from './SearchResult'; +export * from './Route';