Skip to content

Commit b91fb21

Browse files
ZabeehUllahmujtabaidrees94
authored andcommitted
fix: localStorage is undefined
1 parent d6c6b03 commit b91fb21

4 files changed

Lines changed: 23 additions & 17 deletions

File tree

app/layout.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,13 @@ export default function RootLayout({
2727
<AuthProvider>
2828
<Navbar />
2929
<ProjectProvider>
30-
<Suspense fallback={<div className="flex justify-center items-center h-screen">Loading...</div>}>
30+
<Suspense fallback={<div className="flex justify-center items-center h-screen bg-white dark:bg-black">
31+
<div className="flex space-x-2">
32+
<div className="w-4 h-4 bg-teal-600 rounded-full animate-bounce [animation-delay:-0.3s]"></div>
33+
<div className="w-4 h-4 bg-teal-600 rounded-full animate-bounce [animation-delay:-0.15s]"></div>
34+
<div className="w-4 h-4 bg-teal-600 rounded-full animate-bounce"></div>
35+
</div>
36+
</div>}>
3137
{children}
3238
</Suspense>
3339
</ProjectProvider>

app/page.tsx

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,9 @@ export default function DashboardPage() {
6060
const [isLoading, setIsLoading] = useState(false)
6161
const [error, setError] = useState<string | null>(null)
6262
const [currentQuestionIndex, setCurrentQuestionIndex] = useState(0)
63-
const [projectName, setProjectName] = useState("")
64-
const [projectWebsite, setProjectWebsite] = useState("")
6563
const [expandedSection, setExpandedSection] = useState("customize")
6664
const [showRoulette, setShowRoulette] = useState(true)
67-
const { app, setApp } = useAppStore() // use for edit flow
65+
const { app } = useAppStore() // use for edit flow
6866
const { addProject, project } = useProjects() // use for secrt flow
6967

7068
const { routeToDashboard } = useAuth()
@@ -288,10 +286,6 @@ export default function DashboardPage() {
288286
}
289287
}, [id, app]);
290288

291-
292-
293-
console.log("Questions", questions)
294-
295289
const logout = () => {
296290
localStorage.clear()
297291
router.push("/")

components/WidgetCard.tsx

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -95,11 +95,19 @@ export default function WidgetCard({
9595
const [customPlatformsDisable, setCustomPlatformsDisable] = useState(false)
9696
const [isLoading, setIsLoading] = useState(false)
9797
const [isReturningUser, setIsReturningUser] = useState(false)
98-
98+
const [isWidget, setIsWidget] = useState<boolean>(false)
99+
99100
const { app, setApp } = useAppStore() // use for edit flow
100101
const searchParams = useSearchParams()
101102
const id = searchParams.get("id")
102103

104+
useEffect(() => {
105+
const config = window?.localStorage.getItem("widgetConfig")
106+
if (config) {
107+
setIsWidget(true)
108+
}
109+
}, [])
110+
103111
const handleAddQuestion = (type: QuestionType) => {
104112
if (questions.length == 3) return
105113
const id = Date.now()
@@ -307,7 +315,7 @@ export default function WidgetCard({
307315
tags: cat.tags.filter((tag) => tag.id !== tagId),
308316
}
309317
: cat,
310-
),
318+
),
311319
}
312320
}
313321
return q
@@ -462,7 +470,6 @@ export default function WidgetCard({
462470
addUrl()
463471
}
464472

465-
const savedConfig = localStorage.getItem("widgetConfig")
466473

467474
useEffect(() => {
468475
const getUniversalProfiles = async () => {
@@ -506,7 +513,7 @@ export default function WidgetCard({
506513
]
507514

508515
setProfileTypes(updatedProfilesWithCustom)
509-
516+
const savedConfig = window?.localStorage.getItem("widgetConfig")
510517
// Set the first profile as selected if it exists
511518
if (updatedProfilesWithCustom.length > 0 && !savedConfig) {
512519
setSelectedProfileType(updatedProfilesWithCustom[0])
@@ -1105,12 +1112,12 @@ export default function WidgetCard({
11051112
savedAt: new Date().getTime(), // Add timestamp
11061113
}
11071114

1108-
localStorage.setItem("widgetConfig", JSON.stringify(configData))
1115+
window?.localStorage.setItem("widgetConfig", JSON.stringify(configData))
11091116
alert("Configuration saved successfully! Your progress will be restored when you return.")
11101117
}
11111118

11121119
const resetConfig = () => {
1113-
localStorage.removeItem("widgetConfig")
1120+
window?.localStorage.removeItem("widgetConfig")
11141121
// Reset to default values
11151122
setCustomizationData({
11161123
general: {
@@ -1139,7 +1146,7 @@ export default function WidgetCard({
11391146
useEffect(() => {
11401147
// Don't load saved config if we're in edit mode (id exists)
11411148
if (!id) {
1142-
const savedConfig = localStorage.getItem("widgetConfig")
1149+
const savedConfig = window?.localStorage.getItem("widgetConfig")
11431150
if (savedConfig) {
11441151
const parsedConfig = JSON.parse(savedConfig)
11451152

@@ -1165,7 +1172,6 @@ export default function WidgetCard({
11651172
}
11661173
}, [id])
11671174

1168-
const isWidget = localStorage.getItem("widgetConfig")
11691175

11701176
// Add a new function to check if any data has been modified from default values
11711177
const hasUserEnteredData = () => {

lib/orbis-utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ const orbisdb = new OrbisDB({
3232
// const query = selectStatement.build()
3333
// console.log("Query that will be run", query)
3434
const result= await selectStatement.run();
35-
console.log("Result", result)
35+
// console.log("Result", result)
3636
// console.log(result);
3737
// columns: Array<string>
3838
// rows: Array<T | Record<string, any>>

0 commit comments

Comments
 (0)