Skip to content

Commit

Permalink
fix: Use get() instead of 'this' in Zustand stores (#2250)
Browse files Browse the repository at this point in the history
  • Loading branch information
DafyddLlyr authored Oct 1, 2023
1 parent 8d39f6f commit 05a973f
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 6 deletions.
5 changes: 2 additions & 3 deletions editor.planx.uk/src/pages/FlowEditor/lib/store/team.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export const teamStore: StateCreator<TeamStore, [], [], TeamStore> = (
boundaryBBox: get().boundaryBBox,
}),

async initTeamStore(teamSlugFromURLParams) {
initTeamStore: async (teamSlugFromURLParams) => {
const slug = teamSlugFromURLParams || await getTeamFromDomain(window.location.hostname)
const { data } = await client.query({
query: gql`
Expand Down Expand Up @@ -86,7 +86,6 @@ export const teamStore: StateCreator<TeamStore, [], [], TeamStore> = (
const team = data.teams[0];

if (!team) throw new Error("Team not found");

this.setTeam(team);
get().setTeam(team);
},
});
4 changes: 2 additions & 2 deletions editor.planx.uk/src/pages/FlowEditor/lib/store/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export const userStore: StateCreator<UserStore, [], [], UserStore> = (
);
},

async initUserStore(jwt: string) {
initUserStore: async (jwt: string) => {
const email = (jwtDecode(jwt) as any)["email"];
const users = await client.query({
query: gql`
Expand Down Expand Up @@ -87,6 +87,6 @@ export const userStore: StateCreator<UserStore, [], [], UserStore> = (
const user: User = users.data.users[0];
if (!user) throw new Error(`Failed to get user ${email}`);

this.setUser(user);
get().setUser(user);
},
});
2 changes: 1 addition & 1 deletion editor.planx.uk/src/routes/views/team.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export const teamView = async (req: NaviRequest) => {
try {
await initTeamStore(req.params.team);
} catch (error) {
throw new NotFoundError("Team not found");
throw new NotFoundError(`Team not found: ${error}`);
}
}

Expand Down

0 comments on commit 05a973f

Please sign in to comment.