|
8 | 8 | createMemo,
|
9 | 9 | createResource,
|
10 | 10 | createSignal,
|
| 11 | + on, |
11 | 12 | } from "solid-js";
|
12 | 13 | import { createToast } from "../components/ShowToasts";
|
13 | 14 | import { redirect, useSearchParams } from "@solidjs/router";
|
@@ -55,7 +56,7 @@ export const UserContextWrapper = (props: UserStoreContextProps) => {
|
55 | 56 | const apiHost = import.meta.env.VITE_API_HOST as string;
|
56 | 57 |
|
57 | 58 | const trieve = useTrieve();
|
58 |
| - const [searchParams] = useSearchParams(); |
| 59 | + const [searchParams, setSearchParams] = useSearchParams(); |
59 | 60 |
|
60 | 61 | const [user, setUser] = createSignal<SlimUser | null>(null);
|
61 | 62 | const [isNewUser, setIsNewUser] = createSignal(false);
|
@@ -103,9 +104,11 @@ export const UserContextWrapper = (props: UserStoreContextProps) => {
|
103 | 104 | window.localStorage.setItem("trieve:user", JSON.stringify(data));
|
104 | 105 |
|
105 | 106 | // Grab org id from localstorage
|
106 |
| - const possibleOrgId = window.localStorage.getItem( |
107 |
| - `${data.id}:selectedOrg`, |
108 |
| - ); |
| 107 | + let possibleOrgId = window.localStorage.getItem(`${data.id}:selectedOrg`); |
| 108 | + if (searchParams["org"]) { |
| 109 | + possibleOrgId = searchParams["org"]; |
| 110 | + } |
| 111 | + |
109 | 112 | if (possibleOrgId) {
|
110 | 113 | const matchingOrg = data.orgs.find((org) => org.id === possibleOrgId);
|
111 | 114 | if (matchingOrg) {
|
@@ -162,6 +165,13 @@ export const UserContextWrapper = (props: UserStoreContextProps) => {
|
162 | 165 | }
|
163 | 166 | };
|
164 | 167 |
|
| 168 | + // Set the orgid in the query params |
| 169 | + createEffect( |
| 170 | + on(selectedOrgId, (orgId) => { |
| 171 | + setSearchParams({ ...searchParams, org: orgId }); |
| 172 | + }), |
| 173 | + ); |
| 174 | + |
165 | 175 | const setSelectedOrg = (orgId: string) => {
|
166 | 176 | localStorage.setItem(`${user()?.id}:selectedOrg`, orgId);
|
167 | 177 | const org = user()?.orgs.find((org) => org.id === orgId);
|
@@ -211,9 +221,6 @@ export const UserContextWrapper = (props: UserStoreContextProps) => {
|
211 | 221 | }}
|
212 | 222 | >
|
213 | 223 | {props.children}
|
214 |
| - <Show when={isNewUser()}> |
215 |
| - <div>New user!!</div> |
216 |
| - </Show> |
217 | 224 | </UserContext.Provider>
|
218 | 225 | )}
|
219 | 226 | </Show>
|
|
0 commit comments