-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
make breadcrumb appear faster #2234 #2243
Merged
Merged
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
f97c1f1
remove extra fetches of breadcrumbs data
andreymikhadyuk 0f49b31
create useAllUserCommonMemberInfo hook
andreymikhadyuk 77a3311
create useGovernanceListByCommonIds hook
andreymikhadyuk b3d8bc4
add logic to fetch breadcrumbs item's projects
andreymikhadyuk 8ba67f2
add logic to display add space button
andreymikhadyuk 0c600df
reuse commons and projects from sidenav in breadcrumbs
andreymikhadyuk b84ba8a
add loader to breadcrumbs menu
andreymikhadyuk f411c98
create ActiveFeedBreadcrumbsItem component
andreymikhadyuk 7577090
fix breadcrumbs related reducers
andreymikhadyuk d6f7c27
fix active breadcrumbs items
andreymikhadyuk c91dec2
revert breadcrumbs items type
andreymikhadyuk 3733875
add comment to the addOrUpdateProjectInBreadcrumbs reducer
andreymikhadyuk a01f32e
fix FeedBreadcrumbsItem's base item building
andreymikhadyuk 742d3fc
optimize breadcrumbs configuration using existing data
andreymikhadyuk 7d47273
fix projects in sidenav fetch on item click from breadcrumbs
andreymikhadyuk 6e1ba0d
fix projects in sidenav fetch on item click from breadcrumbs
andreymikhadyuk File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
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,87 @@ | ||
import { useEffect, useState } from "react"; | ||
import { useSelector } from "react-redux"; | ||
import { selectUser } from "@/pages/Auth/store/selectors"; | ||
import { CommonService } from "@/services"; | ||
import { Awaited, LoadingState } from "@/shared/interfaces"; | ||
|
||
type State = LoadingState<Awaited< | ||
ReturnType<typeof CommonService.getAllUserCommonMemberInfo> | ||
> | null>; | ||
|
||
type Return = State; | ||
|
||
export const useAllUserCommonMemberInfo = (): Return => { | ||
const user = useSelector(selectUser()); | ||
const userId = user?.uid; | ||
const [state, setState] = useState<State>({ | ||
loading: true, | ||
fetched: false, | ||
data: null, | ||
}); | ||
|
||
useEffect(() => { | ||
if (!userId) { | ||
return; | ||
} | ||
|
||
const unsubscribe = CommonService.subscribeToAllUserCommonMemberInfo( | ||
userId, | ||
(data) => { | ||
setState((currentState) => { | ||
if (!currentState.data || currentState.data.length === 0) { | ||
return { | ||
loading: false, | ||
fetched: true, | ||
data: data.map((item) => ({ | ||
...item.commonMember, | ||
commonId: item.commonId, | ||
})), | ||
}; | ||
} | ||
|
||
const nextData = [...currentState.data]; | ||
|
||
data.forEach((item) => { | ||
const itemIndex = nextData.findIndex( | ||
({ commonId }) => commonId === item.commonId, | ||
); | ||
|
||
if (itemIndex === -1) { | ||
nextData.push({ | ||
...item.commonMember, | ||
commonId: item.commonId, | ||
}); | ||
return; | ||
} | ||
|
||
if (item.statuses.isRemoved) { | ||
nextData.splice(itemIndex, 1); | ||
} else { | ||
nextData[itemIndex] = { | ||
...item.commonMember, | ||
commonId: item.commonId, | ||
}; | ||
} | ||
}); | ||
|
||
return { | ||
loading: false, | ||
fetched: true, | ||
data: nextData, | ||
}; | ||
}); | ||
}, | ||
); | ||
|
||
return () => { | ||
unsubscribe(); | ||
setState({ | ||
loading: true, | ||
fetched: false, | ||
data: null, | ||
}); | ||
}; | ||
}, [userId]); | ||
|
||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
import { useEffect, useState } from "react"; | ||
import { CommonService } from "@/services"; | ||
import { LoadingState } from "@/shared/interfaces"; | ||
import { Common } from "@/shared/models"; | ||
|
||
type State = LoadingState<Common[] | null>; | ||
|
||
type Return = State; | ||
|
||
export const useCommonsByDirectParentId = (parentCommonId?: string): Return => { | ||
const [state, setState] = useState<State>({ | ||
loading: true, | ||
fetched: false, | ||
data: null, | ||
}); | ||
|
||
useEffect(() => { | ||
if (!parentCommonId) { | ||
return; | ||
} | ||
|
||
const unsubscribe = CommonService.subscribeToCommonsByDirectParentId( | ||
parentCommonId, | ||
(data) => { | ||
setState((currentState) => { | ||
if (!currentState.data || currentState.data.length === 0) { | ||
return { | ||
loading: false, | ||
fetched: true, | ||
data: data.map((item) => item.common), | ||
}; | ||
} | ||
|
||
const nextData = [...currentState.data]; | ||
|
||
data.forEach((item) => { | ||
const itemIndex = nextData.findIndex( | ||
({ id }) => id === item.common.id, | ||
); | ||
|
||
if (itemIndex === -1) { | ||
nextData.push(item.common); | ||
return; | ||
} | ||
|
||
if (item.statuses.isRemoved) { | ||
nextData.splice(itemIndex, 1); | ||
} else { | ||
nextData[itemIndex] = item.common; | ||
} | ||
}); | ||
|
||
return { | ||
loading: false, | ||
fetched: true, | ||
data: nextData, | ||
}; | ||
}); | ||
}, | ||
); | ||
|
||
return () => { | ||
unsubscribe(); | ||
setState({ | ||
loading: true, | ||
fetched: false, | ||
data: null, | ||
}); | ||
}; | ||
}, [parentCommonId]); | ||
|
||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import { useEffect, useState } from "react"; | ||
import { GovernanceService } from "@/services"; | ||
import { LoadingState } from "@/shared/interfaces"; | ||
import { Governance } from "@/shared/models"; | ||
|
||
type State = LoadingState<Governance[] | null>; | ||
|
||
type Return = State; | ||
|
||
export const useGovernanceListByCommonIds = (commonIds: string[]): Return => { | ||
const [state, setState] = useState<State>({ | ||
loading: true, | ||
fetched: false, | ||
data: null, | ||
}); | ||
|
||
useEffect(() => { | ||
if (commonIds.length === 0) { | ||
return; | ||
} | ||
|
||
const unsubscribe = GovernanceService.subscribeToGovernanceListByCommonIds( | ||
commonIds, | ||
(data) => { | ||
setState((currentState) => { | ||
if (!currentState.data || currentState.data.length === 0) { | ||
return { | ||
loading: false, | ||
fetched: true, | ||
data: data.map((item) => item.governance), | ||
}; | ||
} | ||
|
||
const nextData = [...currentState.data]; | ||
|
||
data.forEach((item) => { | ||
const itemIndex = nextData.findIndex( | ||
({ id }) => id === item.governance.id, | ||
); | ||
|
||
if (itemIndex === -1) { | ||
nextData.push(item.governance); | ||
return; | ||
} | ||
|
||
if (item.statuses.isRemoved) { | ||
nextData.splice(itemIndex, 1); | ||
} else { | ||
nextData[itemIndex] = item.governance; | ||
} | ||
}); | ||
|
||
return { | ||
loading: false, | ||
fetched: true, | ||
data: nextData, | ||
}; | ||
}); | ||
}, | ||
); | ||
|
||
return unsubscribe; | ||
}, [commonIds]); | ||
|
||
return state; | ||
}; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You have pretty similar code in all newly created hooks. It would be great if you create a reusable helper function for that (if it's possible)