Skip to content

Commit c8ba07b

Browse files
committed
slight fixes
1 parent b231f55 commit c8ba07b

File tree

5 files changed

+60
-25
lines changed

5 files changed

+60
-25
lines changed

package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@
2727
"@solid-primitives/utils": "^6.2.3",
2828
"@solidjs/meta": "^0.29.4",
2929
"@solidjs/router": "^0.15.2",
30-
"@solidjs/start": "^1.0.10",
30+
"@solidjs/start": "^1.0.11",
31+
"localforage": "^1.10.0",
3132
"lucide-solid": "^0.469.0",
3233
"solid-js": "^1.9.3",
3334
"ua-parser-js": "^2.0.0",

pnpm-lock.yaml

+27-5
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/components/Auth.tsx

+10-8
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
import { cookieStorage, makePersisted } from "@solid-primitives/storage";
22
import { useNavigate, useParams, useSearchParams } from "@solidjs/router";
33
import {
4+
type Accessor,
45
type Component,
56
For,
7+
type Setter,
68
Show,
79
createEffect,
810
createMemo,
@@ -49,18 +51,18 @@ export type AuthRef = {
4951
(props: {
5052
deleteRoad: (roadName: string) => void;
5153
retrieveRoad: (roadID: string) => Promise<RoadResponse | undefined>;
52-
newRoads: string[];
53-
setNewRoads: (newRoads: string[]) => void;
54+
newRoads: Accessor<string[]>;
55+
setNewRoads: Setter<string[]>;
5456
save: (roadID: string) => void;
55-
gettingUserData: boolean;
57+
gettingUserData: Accessor<boolean>;
5658
changeSemester: (year: number) => void;
5759
}): void;
5860
deleteRoad: (roadName: string) => void;
5961
retrieveRoad: (roadID: string) => Promise<RoadResponse | undefined>;
60-
newRoads: string[];
61-
setNewRoads: (newRoads: string[]) => void;
62+
newRoads: Accessor<string[]>;
63+
setNewRoads: Setter<string[]>;
6264
save: (roadID: string) => void;
63-
gettingUserData: boolean;
65+
gettingUserData: Accessor<boolean>;
6466
changeSemester: (year: number) => void;
6567
};
6668

@@ -860,8 +862,8 @@ const Auth: Component<{
860862
props.ref?.({
861863
deleteRoad: deleteRoadInternal,
862864
retrieveRoad,
863-
newRoads: newRoadsRef(),
864-
gettingUserData: gettingUserData(),
865+
newRoads: newRoadsRef,
866+
gettingUserData,
865867
setNewRoads: setNewRoadsRef,
866868
save,
867869
changeSemester,

src/context/component.tsx

+13-7
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,23 @@
1-
import { makePersisted, storageSync } from "@solid-primitives/storage";
1+
import { makePersisted } from "@solid-primitives/storage";
22
import { type ParentComponent, createResource } from "solid-js";
3-
import { createStore, produce, reconcile, unwrap } from "solid-js/store";
3+
import { createStore, produce, reconcile } from "solid-js/store";
4+
import { isServer } from "solid-js/web";
45

5-
import { CourseDataContext, type defaultActions, defaultState } from "./create";
6-
import type { Subject, SubjectFull } from "./types";
6+
import localforage from "localforage";
7+
8+
import {
9+
CourseDataContext,
10+
type defaultActions,
11+
defaultState,
12+
} from "~/context/create";
13+
import type { Subject, SubjectFull } from "~/context/types";
714

815
const CourseDataProvider: ParentComponent = (props) => {
916
const [store, setStore, init] = makePersisted(
1017
createStore(structuredClone(defaultState)),
1118
{
1219
name: "courseRoadStore",
13-
sync: storageSync,
20+
storage: !isServer ? localforage : undefined,
1421
},
1522
);
1623

@@ -248,8 +255,7 @@ const CourseDataProvider: ParentComponent = (props) => {
248255
},
249256

250257
getRoadKeys: () => {
251-
if (!store.roads) return [];
252-
return Object.keys(store.roads);
258+
return Object.getOwnPropertyNames(store.roads);
253259
},
254260

255261
getMatchingAttributes: (gir, hass, ci) => {

src/routes/road/[[road]].tsx

+8-4
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ export default function RoadPage() {
8282
on(activeRoad, (newRoad) => {
8383
if (
8484
store.unretrieved.indexOf(newRoad) >= 0 &&
85-
!authComponentRef?.gettingUserData
85+
!authComponentRef?.gettingUserData()
8686
) {
8787
authComponentRef?.retrieveRoad(newRoad).then(() => {
8888
setRetrieved(newRoad);
@@ -130,7 +130,7 @@ export default function RoadPage() {
130130
ss: SimplifiedSelectedSubjects = Array.from(Array(16), () => []),
131131
overrides: Record<string, number> = {},
132132
) => {
133-
const tempRoadID = `$${authComponentRef?.newRoads.length}$`;
133+
const tempRoadID = `$${authComponentRef?.newRoads().length}$`;
134134
const newContents = {
135135
coursesOfStudy: cos,
136136
selectedSubjects: ss,
@@ -152,10 +152,14 @@ export default function RoadPage() {
152152
});
153153
resetFulfillmentNeeded();
154154
setActiveRoad(tempRoadID);
155-
authComponentRef?.setNewRoads([...authComponentRef.newRoads, tempRoadID]);
155+
console.log(authComponentRef?.newRoads());
156+
authComponentRef?.setNewRoads([...authComponentRef.newRoads(), tempRoadID]);
157+
console.log(authComponentRef?.newRoads());
156158
};
157159

158-
const [roadKeys, setRoadKeys] = createSignal(["$defaultroad$"] as string[]);
160+
// TODO: find a way to make this nicer,
161+
// but creatememo doesnt work for some reason...
162+
const [roadKeys, setRoadKeys] = createSignal(["$defaultroad$"]);
159163
createEffect(() => {
160164
setRoadKeys(getRoadKeys());
161165
});

0 commit comments

Comments
 (0)