-
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.
refactor(frontend): Apply hexagonal architecture in frontend as well
- Loading branch information
Showing
29 changed files
with
540 additions
and
213 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
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,20 @@ | ||
'use client'; | ||
|
||
import { ProfileDataSPI } from '@/modules/profiles/core/domain'; | ||
import React, { createContext, useMemo } from 'react'; | ||
import { createProfileDataAdapter } from '@/modules/profiles/infrastructure/profile-data-adapter'; | ||
|
||
type DIContextState = { | ||
profileDataSPI: ProfileDataSPI; | ||
}; | ||
|
||
export const DIContext = createContext<DIContextState>({} as DIContextState); | ||
|
||
export const DIContextProvider = ({ children }: React.PropsWithChildren) => { | ||
const profileDataSPI = useMemo(() => createProfileDataAdapter(), []); | ||
return ( | ||
<DIContext.Provider value={{ profileDataSPI }}> | ||
{children} | ||
</DIContext.Provider> | ||
); | ||
}; |
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,34 @@ | ||
'use client'; | ||
|
||
import useSWR, { Fetcher } from 'swr'; | ||
import { ProfileSet } from '@/modules/profiles/core/domain'; | ||
import { useContext } from 'react'; | ||
import { DIContext } from '@/context/di-context'; | ||
import { getProfiles } from '@/modules/profiles/application/get-profiles'; | ||
|
||
export const useProfileSet = () => { | ||
const context = useContext(DIContext); | ||
if (!context) { | ||
throw new Error('useProfileSet must be used inside the DIContextProvider'); | ||
} | ||
|
||
const fetcher: Fetcher<ProfileSet, string> = async () => { | ||
const result = await getProfiles(context.profileDataSPI); | ||
if (result.isErr()) { | ||
throw result.unwrapErr(); | ||
} | ||
|
||
return result.unwrap(); | ||
}; | ||
|
||
const { data, error, isLoading } = useSWR<ProfileSet, Error>( | ||
'get_profiles', | ||
fetcher | ||
); | ||
|
||
return { | ||
profileSet: data, | ||
error, | ||
isLoading, | ||
}; | ||
}; |
Oops, something went wrong.