Skip to content

Commit

Permalink
feat: add user settings to server db
Browse files Browse the repository at this point in the history
  • Loading branch information
sashtje committed Oct 7, 2023
1 parent d283d53 commit 6d89687
Show file tree
Hide file tree
Showing 11 changed files with 227 additions and 38 deletions.
137 changes: 108 additions & 29 deletions json-server/db.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,9 @@
"views": 1022,
"createdAt": "01.09.2023",
"userId": "1",
"type": ["IT"],
"type": [
"IT"
],
"blocks": [
{
"id": "1",
Expand Down Expand Up @@ -129,7 +131,9 @@
"views": 3005,
"createdAt": "04.09.2023",
"userId": "2",
"type": ["IT"],
"type": [
"IT"
],
"blocks": [
{
"id": "1",
Expand All @@ -151,7 +155,10 @@
"views": 5300,
"createdAt": "05.09.2023",
"userId": "2",
"type": ["IT", "SCIENCE"],
"type": [
"IT",
"SCIENCE"
],
"blocks": [
{
"id": "1",
Expand All @@ -173,7 +180,9 @@
"views": 5307,
"createdAt": "05.08.2023",
"userId": "2",
"type": ["IT"],
"type": [
"IT"
],
"blocks": [
{
"id": "1",
Expand All @@ -195,7 +204,9 @@
"views": 4200,
"createdAt": "01.04.2023",
"userId": "2",
"type": ["IT"],
"type": [
"IT"
],
"blocks": [
{
"id": "1",
Expand All @@ -217,7 +228,9 @@
"views": 600,
"createdAt": "10.09.2023",
"userId": "2",
"type": ["IT"],
"type": [
"IT"
],
"blocks": [
{
"id": "1",
Expand All @@ -239,7 +252,9 @@
"views": 300,
"createdAt": "04.02.2022",
"userId": "2",
"type": ["IT"],
"type": [
"IT"
],
"blocks": [
{
"id": "1",
Expand All @@ -261,7 +276,9 @@
"views": 736,
"createdAt": "25.04.2023",
"userId": "2",
"type": ["IT"],
"type": [
"IT"
],
"blocks": [
{
"id": "1",
Expand All @@ -283,7 +300,9 @@
"views": 347,
"createdAt": "05.11.2022",
"userId": "2",
"type": ["IT"],
"type": [
"IT"
],
"blocks": [
{
"id": "1",
Expand All @@ -305,7 +324,10 @@
"views": 978,
"createdAt": "17.07.2023",
"userId": "2",
"type": ["IT", "SCIENCE"],
"type": [
"IT",
"SCIENCE"
],
"blocks": [
{
"id": "1",
Expand All @@ -327,7 +349,9 @@
"views": 1408,
"createdAt": "23.05.2023",
"userId": "2",
"type": ["IT"],
"type": [
"IT"
],
"blocks": [
{
"id": "1",
Expand All @@ -349,7 +373,9 @@
"views": 248,
"createdAt": "12.12.2022",
"userId": "2",
"type": ["IT"],
"type": [
"IT"
],
"blocks": [
{
"id": "1",
Expand All @@ -371,7 +397,9 @@
"views": 2078,
"createdAt": "27.03.2023",
"userId": "2",
"type": ["IT"],
"type": [
"IT"
],
"blocks": [
{
"id": "1",
Expand All @@ -393,7 +421,9 @@
"views": 3607,
"createdAt": "15.02.2023",
"userId": "2",
"type": ["IT"],
"type": [
"IT"
],
"blocks": [
{
"id": "1",
Expand All @@ -415,7 +445,9 @@
"views": 2900,
"createdAt": "03.10.2023",
"userId": "2",
"type": ["IT"],
"type": [
"IT"
],
"blocks": [
{
"id": "1",
Expand All @@ -437,7 +469,9 @@
"views": 5000,
"createdAt": "19.09.2023",
"userId": "2",
"type": ["IT"],
"type": [
"IT"
],
"blocks": [
{
"id": "1",
Expand All @@ -459,7 +493,9 @@
"views": 3029,
"createdAt": "14.05.2023",
"userId": "2",
"type": ["IT"],
"type": [
"IT"
],
"blocks": [
{
"id": "1",
Expand All @@ -481,7 +517,9 @@
"views": 4038,
"createdAt": "04.08.2023",
"userId": "2",
"type": ["IT"],
"type": [
"IT"
],
"blocks": [
{
"id": "1",
Expand All @@ -503,7 +541,9 @@
"views": 643,
"createdAt": "08.08.2022",
"userId": "2",
"type": ["IT"],
"type": [
"IT"
],
"blocks": [
{
"id": "1",
Expand All @@ -525,7 +565,9 @@
"views": 7389,
"createdAt": "02.12.2022",
"userId": "2",
"type": ["IT"],
"type": [
"IT"
],
"blocks": [
{
"id": "1",
Expand All @@ -547,7 +589,9 @@
"views": 7643,
"createdAt": "05.05.2023",
"userId": "2",
"type": ["IT"],
"type": [
"IT"
],
"blocks": [
{
"id": "1",
Expand All @@ -569,7 +613,10 @@
"views": 3240,
"createdAt": "16.02.2023",
"userId": "2",
"type": ["IT", "SCIENCE"],
"type": [
"IT",
"SCIENCE"
],
"blocks": [
{
"id": "1",
Expand All @@ -591,7 +638,9 @@
"views": 245,
"createdAt": "07.07.2023",
"userId": "2",
"type": ["IT"],
"type": [
"IT"
],
"blocks": [
{
"id": "1",
Expand All @@ -613,7 +662,9 @@
"views": 843,
"createdAt": "12.04.2023",
"userId": "2",
"type": ["IT"],
"type": [
"IT"
],
"blocks": [
{
"id": "1",
Expand All @@ -635,7 +686,9 @@
"views": 845,
"createdAt": "12.06.2023",
"userId": "2",
"type": ["ECONOMICS"],
"type": [
"ECONOMICS"
],
"blocks": [
{
"id": "1",
Expand Down Expand Up @@ -693,33 +746,54 @@
"id": "1",
"username": "admin",
"password": "123",
"roles": ["ADMIN"],
"roles": [
"ADMIN"
],
"features": {
"isArticleRatingEnabled": true,
"isCounterEnabled": true
},
"jsonSettings": {
"theme": "app_orange_theme",
"isFirstVisit": true,
"settingsPageHasBeenOpen": false
},
"avatar": "https://s10.stc.yc.kpcdn.net/share/i/12/12010775/wr-960.webp"
},
{
"id": "2",
"username": "user",
"password": "123",
"roles": ["USER"],
"roles": [
"USER"
],
"features": {
"isArticleRatingEnabled": false,
"isCounterEnabled": false
},
"jsonSettings": {
"theme": "app_dark_theme",
"isFirstVisit": true,
"settingsPageHasBeenOpen": false
},
"avatar": "https://static.toiimg.com/thumb/msid-98919960,width-400,resizemode-4/98919960.jpg"
},
{
"id": "3",
"username": "manager",
"password": "123",
"roles": ["MANAGER"],
"roles": [
"MANAGER"
],
"features": {
"isArticleRatingEnabled": false,
"isCounterEnabled": true
},
"jsonSettings": {
"theme": "app_dark_theme",
"isFirstVisit": true,
"settingsPageHasBeenOpen": false
},
"avatar": "https://static.toiimg.com/thumb/msid-98919960,width-400,resizemode-4/98919960.jpg"
},
{
Expand All @@ -731,6 +805,11 @@
"isArticleRatingEnabled": true,
"isCounterEnabled": false
},
"jsonSettings": {
"theme": "app_dark_theme",
"isFirstVisit": true,
"settingsPageHasBeenOpen": false
},
"avatar": "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcRqNiwgTLa4GOFNV2CXioYgjaEEt4K6sd-_BkWgvANyjxNQ_aEcjstLSmmBUWN2W1ODFLU&usqp=CAU"
}
],
Expand Down Expand Up @@ -825,4 +904,4 @@
"profileId": "2"
}
]
}
}
5 changes: 2 additions & 3 deletions src/app/providers/ThemeProvider/ui/ThemeProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@ import { ReactNode, useMemo, useState } from 'react';

import { ThemeContext } from '@/shared/lib/context/ThemeContext';
import { Theme } from '@/shared/const/theme';
import { LOCAL_STORAGE_THEME_KEY } from '@/shared/const/localStorage';

const defaultTheme = (localStorage.getItem(LOCAL_STORAGE_THEME_KEY) as Theme) || Theme.LIGHT;
import { useJsonSettings } from '@/entities/User';

interface ThemeProviderProps {
children: ReactNode;
Expand All @@ -13,6 +11,7 @@ interface ThemeProviderProps {

export const ThemeProvider = (props: ThemeProviderProps) => {
const { children, initialTheme } = props;
const { theme: defaultTheme = Theme.LIGHT } = useJsonSettings();
const [theme, setTheme] = useState<Theme>(initialTheme || defaultTheme);

const defaultProps = useMemo(
Expand Down
25 changes: 25 additions & 0 deletions src/entities/User/api/userApi.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { rtkApi } from '@/shared/api/rtkApi';

import { JsonSettings } from '../model/types/jsonSettings';
import { User } from '../model/types/user';

interface SetJsonSettingsArg {
userId: string;
jsonSettings: JsonSettings;
}

const userApi = rtkApi.injectEndpoints({
endpoints: (build) => ({
setJsonSettings: build.mutation<User, SetJsonSettingsArg>({
query: ({ userId, jsonSettings }) => ({
url: `/users/${userId}`,
method: 'PATCH',
body: {
jsonSettings,
},
}),
}),
}),
});

export const setJsonSettingsMutation = userApi.endpoints.setJsonSettings.initiate;
Loading

0 comments on commit 6d89687

Please sign in to comment.