Skip to content

Commit

Permalink
Make serice-worker ignore API + fix #506
Browse files Browse the repository at this point in the history
  • Loading branch information
viktorstrate committed Sep 26, 2021
1 parent 7799674 commit 344d554
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 28 deletions.
1 change: 0 additions & 1 deletion ui/package.json
Expand Up @@ -71,7 +71,6 @@
"@testing-library/jest-dom": "^5.14.1",
"@testing-library/react": "^12.0.0",
"@testing-library/user-event": "^13.1.9",
"apollo": "^2.33.4",
"husky": "^6.0.0",
"i18next-parser": "^4.2.0",
"lint-staged": "^11.0.1",
Expand Down
12 changes: 2 additions & 10 deletions ui/src/components/photoGallery/PhotoGallery.tsx
@@ -1,4 +1,4 @@
import React, { useContext, useEffect } from 'react'
import React, { useContext } from 'react'
import styled from 'styled-components'
import { MediaThumbnail, MediaPlaceholder } from './MediaThumbnail'
import PresentView from './presentView/PresentView'
Expand Down Expand Up @@ -52,15 +52,6 @@ const PhotoGallery = ({ mediaState, dispatchMedia }: PhotoGalleryProps) => {
const { media, activeIndex, presenting } = mediaState

const { updateSidebar } = useContext(SidebarContext)
useEffect(() => {
if (mediaState.activeIndex != -1) {
updateSidebar(
<MediaSidebar media={mediaState.media[mediaState.activeIndex]} />
)
} else {
updateSidebar(null)
}
}, [activeIndex])

let photoElements = []
if (media) {
Expand All @@ -77,6 +68,7 @@ const PhotoGallery = ({ mediaState, dispatchMedia }: PhotoGalleryProps) => {
type: 'selectImage',
index,
})
updateSidebar(<MediaSidebar media={mediaState.media[index]} />)
}}
clickFavorite={() => {
toggleFavoriteAction({
Expand Down
14 changes: 1 addition & 13 deletions ui/src/components/timelineGallery/TimelineGallery.tsx
@@ -1,4 +1,4 @@
import React, { useRef, useEffect, useReducer, useContext } from 'react'
import React, { useRef, useEffect, useReducer } from 'react'
import PropTypes from 'prop-types'
import { useQuery, gql } from '@apollo/client'
import TimelineGroupDate from './TimelineGroupDate'
Expand All @@ -16,8 +16,6 @@ import {
getActiveTimelineImage as getActiveTimelineMedia,
timelineGalleryReducer,
} from './timelineGalleryReducer'
import MediaSidebar from '../sidebar/MediaSidebar'
import { SidebarContext } from '../sidebar/Sidebar'
import { urlPresentModeSetupHook } from '../photoGallery/photoGalleryReducer'
import TimelineFilters from './TimelineFilters'
import client from '../../apolloClient'
Expand Down Expand Up @@ -78,7 +76,6 @@ export type TimelineGroupAlbum = {

const TimelineGallery = () => {
const { t } = useTranslation()
const { updateSidebar } = useContext(SidebarContext)

const { getParam, setParam } = useURLParameters()

Expand Down Expand Up @@ -130,15 +127,6 @@ const TimelineGallery = () => {
})
}, [data])

useEffect(() => {
const activeMedia = getActiveTimelineMedia({ mediaState })
if (activeMedia) {
updateSidebar(<MediaSidebar media={activeMedia} />)
} else {
updateSidebar(null)
}
}, [mediaState.activeIndex])

useEffect(() => {
;(async () => {
await client.resetStore()
Expand Down
7 changes: 6 additions & 1 deletion ui/src/components/timelineGallery/TimelineGroupAlbum.tsx
@@ -1,11 +1,13 @@
import React from 'react'
import React, { useContext } from 'react'
import { Link } from 'react-router-dom'
import { MediaThumbnail } from '../photoGallery/MediaThumbnail'
import { PhotoFiller } from '../photoGallery/PhotoGallery'
import {
toggleFavoriteAction,
useMarkFavoriteMutation,
} from '../photoGallery/photoGalleryMutations'
import MediaSidebar from '../sidebar/MediaSidebar'
import { SidebarContext } from '../sidebar/Sidebar'
import {
getActiveTimelineImage,
openTimelinePresentMode,
Expand Down Expand Up @@ -34,6 +36,8 @@ const TimelineGroupAlbum = ({

const [markFavorite] = useMarkFavoriteMutation()

const { updateSidebar } = useContext(SidebarContext)

const mediaElms = media.map((media, index) => (
<MediaThumbnail
key={media.id}
Expand All @@ -47,6 +51,7 @@ const TimelineGroupAlbum = ({
media: index,
},
})
updateSidebar(<MediaSidebar media={media} />)
}}
clickPresent={() => {
openTimelinePresentMode({
Expand Down
9 changes: 6 additions & 3 deletions ui/src/service-worker.ts
Expand Up @@ -22,9 +22,7 @@ clientsClaim()
// Their URLs are injected into the manifest variable below.
// This variable must be present somewhere in your service worker file,
// even if you decide not to use precaching. See https://cra.link/PWA
precacheAndRoute(self.__WB_MANIFEST, {
ignoreURLParametersMatching: [/^\/api\/.*/],
})
precacheAndRoute(self.__WB_MANIFEST)

// Set up App Shell-style routing, so that all navigation requests
// are fulfilled with your index.html shell. Learn more at
Expand All @@ -43,6 +41,11 @@ registerRoute(
return false
}

// Skip API requests
if (url.pathname.startsWith('/api/')) {
return false
}

// If this looks like a URL for a resource, because it contains
// a file extension, skip.
if (url.pathname.match(fileExtensionRegexp)) {
Expand Down

0 comments on commit 344d554

Please sign in to comment.