Skip to content

Commit

Permalink
fix sw path and errors
Browse files Browse the repository at this point in the history
  • Loading branch information
sliterok committed Mar 9, 2024
1 parent 4991a57 commit fb6bc4b
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 24 deletions.
9 changes: 9 additions & 0 deletions src/db/helpers.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
import { BPTreeCondition } from 'src/impl/bptree/BPTree'
import { IFetchDb } from './types'

const swFailCodes = new Set([501, 405])

export const dbFetch: IFetchDb = async (url, body) => {
const response = await fetch(url, { body: JSON.stringify(body), method: 'POST' })
if (swFailCodes.has(response.status)) return
return response.json()
}

export function getQueryFromCondition(type: string, val: string) {
let op: keyof BPTreeCondition<any> | void = undefined
Expand Down
7 changes: 0 additions & 7 deletions src/helpers.ts

This file was deleted.

20 changes: 3 additions & 17 deletions src/routes/UserGrid.tsx
Original file line number Diff line number Diff line change
@@ -1,31 +1,18 @@
import { ClientSuspense, useMutation, useQuery } from 'rakkasjs'
import { useEffect, useState } from 'react'
import { ICommandInput, IInsertInput, IQueryInput } from 'src/db/types'
import { dbFetch } from 'src/helpers'
import { IUser } from 'src/types'

import Chance from 'chance'
// const createWorker = () => {
// if (typeof Worker !== 'undefined')
// return new Worker(import.meta.env.MODE === 'production' ? '/sw.js' : '/dev-sw.js?dev-sw', {
// type: import.meta.env.MODE === 'production' ? 'classic' : 'module',
// })
// }

import { AgGridReact, AgGridReactProps } from 'ag-grid-react'
import 'ag-grid-community/styles//ag-grid.css'
import 'ag-grid-community/styles//ag-theme-quartz.css'
import deepmerge from 'deepmerge'
import { getQueryFromCondition } from 'src/db/helpers'
import { getQueryFromCondition, dbFetch } from 'src/db/helpers'
import { diff } from 'deep-object-diff'

const chance = new Chance()
async function initWorker() {
// eslint-disable-next-line ssr-friendly/no-dom-globals-in-module-scope
if (typeof navigator !== 'undefined' && 'serviceWorker' in navigator) {
await navigator.serviceWorker.register(import.meta.env.MODE === 'production' ? '/sw.js' : '/dev-sw.js?dev-sw', {
type: import.meta.env.MODE === 'production' ? 'classic' : 'module',
})
}
}

const columnDefs: AgGridReactProps['columnDefs'] = [
{ headerName: 'ID', field: 'id', filter: true },
Expand All @@ -35,7 +22,6 @@ const columnDefs: AgGridReactProps['columnDefs'] = [
{ headerName: 'address', field: 'address', filter: true },
]

initWorker()
export default function MainLayout() {
const [isAndQuery, setIsAndQuery] = useState(true)
const [searchInput, setSearchInput] = useState('')
Expand Down
11 changes: 11 additions & 0 deletions src/routes/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,17 @@ body {
margin: 0
}`

async function initWorker() {
// eslint-disable-next-line ssr-friendly/no-dom-globals-in-module-scope
if (typeof navigator !== 'undefined' && 'serviceWorker' in navigator) {
await navigator.serviceWorker.register(import.meta.env.MODE === 'production' ? 'sw.js' : '/dev-sw.js?dev-sw', {
type: import.meta.env.MODE === 'production' ? 'classic' : 'module',
})
}
}

initWorker()

export default function Layout({ children }: LayoutProps) {
return (
<>
Expand Down

0 comments on commit fb6bc4b

Please sign in to comment.