-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
472 additions
and
45 deletions.
There are no files selected for viewing
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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
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
20 changes: 20 additions & 0 deletions
20
src/app/action/languages/createLanguage/createLanguage.action.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,20 @@ | ||
import { | ||
DomainLanguageCreateData, | ||
} from 'product-types/dist/language/DomainLanguageCreateData'; | ||
import { request } from '@/app/lib/fetch/request.ts'; | ||
import { | ||
isDomainNotificationLanguageCreateData, | ||
} from 'product-types/dist/notification/notification-data-types/language/DomainNotificationLanguageCreateData'; | ||
|
||
|
||
export const createLanguageAction = function (createData: DomainLanguageCreateData) { | ||
return request( | ||
`v1/language`, | ||
{ | ||
method: 'POST', | ||
body : JSON.stringify(createData), | ||
isJson: true, | ||
}, | ||
isDomainNotificationLanguageCreateData, | ||
); | ||
}; |
16 changes: 16 additions & 0 deletions
16
src/app/action/languages/createLanguageFolder/createLanguageFolder.action.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,16 @@ | ||
import { | ||
DomainLanguageFolderCreateData, | ||
} from 'product-types/dist/language/DomainLanguageFolderCreateData'; | ||
import { request } from '@/app/lib/fetch/request.ts'; | ||
import { | ||
isDomainNotificationLanguageFolderCreateData, | ||
} from 'product-types/dist/notification/notification-data-types/language/DomainNotificationLanguageFolderCreateData'; | ||
|
||
|
||
export const createLanguageFolderAction = function (languageId: string, createData: DomainLanguageFolderCreateData) { | ||
return request( | ||
`v1/language/folder/${ languageId }`, | ||
{ method: 'POST', body: JSON.stringify(createData), isJson: true }, | ||
isDomainNotificationLanguageFolderCreateData, | ||
); | ||
}; |
16 changes: 16 additions & 0 deletions
16
src/app/action/languages/createLanguageWord/createLanguageWord.action.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,16 @@ | ||
import { | ||
DomainLanguageWordCreateData, | ||
} from 'product-types/dist/language/DomainLanguageWordCreateData'; | ||
import { request } from '@/app/lib/fetch/request.ts'; | ||
import { | ||
isDomainNotificationLanguageWordCreateData, | ||
} from 'product-types/dist/notification/notification-data-types/language/DomainNotificationLanguageWordCreateData'; | ||
|
||
|
||
export const createLanguageWordAction = function (folderId: string, createData: DomainLanguageWordCreateData) { | ||
return request( | ||
`v1/language/word/${ folderId }`, | ||
{ method: 'POST', isJson: true, body: JSON.stringify(createData) }, | ||
isDomainNotificationLanguageWordCreateData, | ||
); | ||
}; |
15 changes: 15 additions & 0 deletions
15
src/app/action/languages/getMyLanguageFolderWords/getMyLanguageFolderWords.action.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,15 @@ | ||
import { request } from '@/app/lib/fetch/request.ts'; | ||
import { | ||
DomainLanguageWord, isDomainLanguageWord, | ||
} from 'product-types/dist/language/DomainLanguageWord'; | ||
|
||
|
||
export const getMyLanguageFolderWordsAction = function (folderId: string) { | ||
return request( | ||
`v1/languages/folder/${ folderId }`, | ||
{ method: 'GET' }, | ||
(data: unknown): data is Array<DomainLanguageWord> => { | ||
return Array.isArray(data) && data.every(isDomainLanguageWord); | ||
}, | ||
); | ||
}; |
16 changes: 16 additions & 0 deletions
16
src/app/action/languages/getMyLanguages/getMyLanguages.action.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,16 @@ | ||
import { request } from '@/app/lib/fetch/request.ts'; | ||
import { | ||
DomainLanguageWithFolders, | ||
isDomainLanguageWithFolders, | ||
} from 'product-types/dist/language/DomainLanguageWithFolders'; | ||
|
||
|
||
export const getMyLanguagesAction = function () { | ||
return request( | ||
`v1/languages`, | ||
{ method: 'GET' }, | ||
(data: unknown): data is Array<DomainLanguageWithFolders> => { | ||
return Array.isArray(data) && data.every(isDomainLanguageWithFolders); | ||
}, | ||
); | ||
}; |
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,79 @@ | ||
import { effect, store } from '@vanyamate/sec'; | ||
import { | ||
createLanguageAction, | ||
} from '@/app/action/languages/createLanguage/createLanguage.action.ts'; | ||
import { | ||
DomainLanguageWithFolders, | ||
} from 'product-types/dist/language/DomainLanguageWithFolders'; | ||
import { | ||
getMyLanguagesAction, | ||
} from '@/app/action/languages/getMyLanguages/getMyLanguages.action.ts'; | ||
import { | ||
createLanguageWordAction, | ||
} from '@/app/action/languages/createLanguageWord/createLanguageWord.action.ts'; | ||
import { | ||
createLanguageFolderAction, | ||
} from '@/app/action/languages/createLanguageFolder/createLanguageFolder.action.ts'; | ||
import { | ||
DomainLanguageWord, | ||
} from 'product-types/dist/language/DomainLanguageWord'; | ||
import { | ||
getMyLanguageFolderWordsAction, | ||
} from '@/app/action/languages/getMyLanguageFolderWords/getMyLanguageFolderWords.action.ts'; | ||
|
||
|
||
export const createLanguageEffect = effect(createLanguageAction); | ||
export const createLanguageFolderEffect = effect(createLanguageFolderAction); | ||
export const createLanguageWordEffect = effect(createLanguageWordAction); | ||
export const getMyLanguagesEffect = effect(getMyLanguagesAction); | ||
export const getMyLanguageFolderWordsEffect = effect(getMyLanguageFolderWordsAction); | ||
|
||
|
||
export const $isUserLanguages = store<boolean>(true) | ||
.on(getMyLanguagesEffect, 'onBefore', () => true); | ||
|
||
export const $languagesLoading = store<boolean>(false) | ||
.on(getMyLanguagesEffect, 'onBefore', () => true) | ||
.on(getMyLanguagesEffect, 'onSuccess', () => false); | ||
|
||
export const $languagesList = store<Array<DomainLanguageWithFolders>>([]) | ||
.on(getMyLanguagesEffect, 'onSuccess', (_, { result }) => result) | ||
.on(createLanguageEffect, 'onSuccess', (state, { result }) => { | ||
return $isUserLanguages.get() | ||
? [ ...state, | ||
{ | ||
folders: [], | ||
id : result.language.id, | ||
title : result.language.title, | ||
} ] | ||
: state; | ||
}) | ||
.on(createLanguageFolderEffect, 'onSuccess', (state, { result }) => { | ||
return $isUserLanguages.get() | ||
? state.map( | ||
(language) => | ||
language.id === result.language.id | ||
? { | ||
...language, | ||
folders: [ ...language.folders, result.folder ], | ||
} | ||
: language, | ||
) | ||
: state; | ||
}); | ||
|
||
export const $currentFolderId = store<string>('') | ||
.on(getMyLanguageFolderWordsEffect, 'onSuccess', (_, { args: [ folderId ] }) => folderId); | ||
|
||
export const $languageFolderWordsList = store<Array<DomainLanguageWord>>([]) | ||
.on(getMyLanguageFolderWordsEffect, 'onSuccess', (_, { result }) => result) | ||
.on( | ||
createLanguageWordEffect, | ||
'onSuccess', | ||
(state, { result, args: [ folderId ] }) => { | ||
if ($currentFolderId.get() === folderId) { | ||
return [ ...state, result.word ]; | ||
} | ||
return state; | ||
}, | ||
); |
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,22 @@ | ||
import { FC, lazy, memo, Suspense } from 'react'; | ||
import { | ||
PageLoader, | ||
} from '@/shared/ui-kit/loaders/PageLoader/ui/PageLoader.tsx'; | ||
import { | ||
ErrorBoundary, | ||
} from '@/shared/ui-kit/errors/ErrorBoundary/ui/ErrorBoundary.tsx'; | ||
|
||
|
||
const LanguagesPage = lazy(() => import('./LanguagesPage.tsx').then((data) => ({ | ||
default: data.LanguagesPage, | ||
}))); | ||
|
||
export const LanguagesPageAsync: FC = memo(function LanguagesPageAsync () { | ||
return ( | ||
<Suspense fallback={ <PageLoader/> }> | ||
<ErrorBoundary> | ||
<LanguagesPage/> | ||
</ErrorBoundary> | ||
</Suspense> | ||
); | ||
}); |
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,15 @@ | ||
import { FC, memo } from 'react'; | ||
import { | ||
LanguagesContainer, | ||
} from '@/widgets/language/container/LanguagesContainer/ui/LanguagesContainer.tsx'; | ||
import { useStore } from '@vanyamate/sec-react'; | ||
import { $authUser } from '@/app/model/auth/auth.model.ts'; | ||
|
||
|
||
export const LanguagesPage: FC = memo(function LanguagesPage () { | ||
const user = useStore($authUser); | ||
|
||
return ( | ||
<LanguagesContainer userId={ user.id }/> | ||
); | ||
}); |
5 changes: 5 additions & 0 deletions
5
src/widgets/language/container/LanguagesContainer/ui/LanguagesContainer.module.scss
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,5 @@ | ||
.container { | ||
li { | ||
padding-left : 30px; | ||
} | ||
} |
Oops, something went wrong.