diff --git a/components/image.js b/components/image.js
index 337c8730..08fdc0fb 100644
--- a/components/image.js
+++ b/components/image.js
@@ -1,5 +1,5 @@
import styles from './text.module.css'
-import { Fragment, useState, useEffect, useMemo, useCallback, useRef, createContext, useContext } from 'react'
+import { Fragment, useState, useEffect, useMemo, useCallback, useRef } from 'react'
import { IMGPROXY_URL_REGEXP } from '../lib/url'
import { useShowModal } from './modal'
import { useMe } from './me'
@@ -7,81 +7,7 @@ import { Dropdown } from 'react-bootstrap'
import { UPLOAD_TYPES_ALLOW } from '../lib/constants'
import { useToast } from './toast'
import gql from 'graphql-tag'
-import { useMutation, useQuery } from '@apollo/client'
-import { extractUrls } from '../lib/md'
-
-const ImageContext = createContext({ unsubmitted: [] })
-
-const imageIdToUrl = id => `https://${process.env.NEXT_PUBLIC_AWS_UPLOAD_BUCKET}.s3.amazonaws.com/${id}`
-
-export function ImageProvider ({ me, children }) {
- const { data, loading } = useQuery(
- gql`
- query images($submitted: Boolean) {
- me {
- images(submitted: $submitted) {
- id
- createdAt
- updatedAt
- type
- size
- width
- height
- itemId
- }
- }
- }`, {
- variables: { submitted: false }
- }
- )
- const [deleteImage] = useMutation(gql`
- mutation deleteImage($id: ID!) {
- deleteImage(id: $id)
- }`, {
- onCompleted: (_, options) => {
- const id = options.variables.id
- setUnsubmittedImages(prev => prev.filter(img => img.id !== id))
- }
- })
- const [unsubmittedImages, setUnsubmittedImages] = useState([])
-
- const markImagesAsSubmitted = useCallback((text) => {
- // mark images from S3 included in the text as submitted on the client
- const urls = extractUrls(text)
- const s3UrlPrefix = `https://${process.env.NEXT_PUBLIC_AWS_UPLOAD_BUCKET}.s3.amazonaws.com/`
- urls
- .filter(url => url.startsWith(s3UrlPrefix))
- .forEach(url => {
- const s3Key = url.split('/').pop()
- setUnsubmittedImages(prev => prev.filter(img => img.id !== s3Key))
- })
- }, [setUnsubmittedImages])
-
- useEffect(() => {
- const images = data?.me?.images
- if (images) {
- setUnsubmittedImages(images.map(img => ({ ...img, url: imageIdToUrl(img.id) })))
- }
- }, [setUnsubmittedImages, loading])
-
- const contextValue = {
- unsubmittedImages,
- setUnsubmittedImages,
- deleteImage,
- markImagesAsSubmitted
- }
-
- return (
-
- {children}
-
- )
-}
-
-export function useImages () {
- const images = useContext(ImageContext)
- return images
-}
+import { useMutation } from '@apollo/client'
export function decodeOriginalUrl (imgproxyUrl) {
const parts = imgproxyUrl.split('/')
@@ -228,6 +154,7 @@ export function ImageUpload ({ children, className, onSelect, onSuccess }) {
const img = new window.Image()
img.src = window.URL.createObjectURL(file)
img.onload = async () => {
+ onSelect?.(file)
let data
const variables = {
type: file.type,
diff --git a/components/job-form.js b/components/job-form.js
index 6f9b02de..2856ceac 100644
--- a/components/job-form.js
+++ b/components/job-form.js
@@ -18,7 +18,6 @@ import ActionTooltip from './action-tooltip'
import { jobSchema } from '../lib/validate'
import CancelButton from './cancel-button'
import { MAX_TITLE_LENGTH } from '../lib/constants'
-import { useImages } from './image'
function satsMin2Mo (minute) {
return minute * 30 * 24 * 60
@@ -41,7 +40,6 @@ export default function JobForm ({ item, sub }) {
const storageKeyPrefix = item ? undefined : `${sub.name}-job`
const router = useRouter()
const [logoId, setLogoId] = useState(item?.uploadId)
- const { markImagesAsSubmitted } = useImages()
const [upsertJob] = useMutation(gql`
mutation upsertJob($sub: String!, $id: ID, $title: String!, $company: String!, $location: String,
$remote: Boolean, $text: String!, $url: String!, $maxBid: Int!, $status: String, $logo: Int, $hash: String, $hmac: String) {
@@ -51,11 +49,7 @@ export default function JobForm ({ item, sub }) {
id
text
}
- }`, {
- onCompleted ({ upsertJob: { text } }) {
- markImagesAsSubmitted(text)
- }
- }
+ }`
)
const onSubmit = useCallback(
diff --git a/components/link-form.js b/components/link-form.js
index cc73185f..f7cc7bf4 100644
--- a/components/link-form.js
+++ b/components/link-form.js
@@ -17,7 +17,6 @@ import CancelButton from './cancel-button'
import { normalizeForwards } from '../lib/form'
import { MAX_TITLE_LENGTH } from '../lib/constants'
import { useMe } from './me'
-import { useImages } from './image'
export function LinkForm ({ item, sub, editThreshold, children }) {
const router = useRouter()
@@ -53,7 +52,6 @@ export function LinkForm ({ item, sub, editThreshold, children }) {
}
}
}`)
- const { markImagesAsSubmitted } = useImages
const related = []
for (const item of relatedData?.related?.items || []) {
@@ -77,12 +75,7 @@ export function LinkForm ({ item, sub, editThreshold, children }) {
id
text
}
- }`,
- {
- onCompleted ({ upsertLink: { text } }) {
- markImagesAsSubmitted(text)
- }
- }
+ }`
)
const onSubmit = useCallback(
diff --git a/components/poll-form.js b/components/poll-form.js
index 257b6986..fcf62773 100644
--- a/components/poll-form.js
+++ b/components/poll-form.js
@@ -13,14 +13,12 @@ import CancelButton from './cancel-button'
import { useCallback } from 'react'
import { normalizeForwards } from '../lib/form'
import { useMe } from './me'
-import { useImages } from './image'
export function PollForm ({ item, sub, editThreshold, children }) {
const router = useRouter()
const client = useApolloClient()
const me = useMe()
const schema = pollSchema({ client, me, existingBoost: item?.boost })
- const { markImagesAsSubmitted } = useImages()
const [upsertPoll] = useMutation(
gql`
@@ -31,11 +29,7 @@ export function PollForm ({ item, sub, editThreshold, children }) {
id
text
}
- }`, {
- onCompleted ({ upsertPoll: { text } }) {
- markImagesAsSubmitted(text)
- }
- }
+ }`
)
const onSubmit = useCallback(
diff --git a/components/reply.js b/components/reply.js
index 12a6903c..e863a199 100644
--- a/components/reply.js
+++ b/components/reply.js
@@ -11,7 +11,6 @@ import { commentSchema } from '../lib/validate'
import Info from './info'
import { quote } from '../lib/md'
import { COMMENT_DEPTH_LIMIT } from '../lib/constants'
-import { useImages } from './image'
export function ReplyOnAnotherPage ({ item }) {
const path = item.path.split('.')
@@ -50,7 +49,6 @@ export default forwardRef(function Reply ({ item, onSuccess, replyOpen, children
const parentId = item.id
const replyInput = useRef(null)
const formInnerRef = useRef()
- const { markImagesAsSubmitted } = useImages()
// Start block to handle iOS Safari's weird selection clearing behavior
const savedRange = useRef()
@@ -118,9 +116,6 @@ export default forwardRef(function Reply ({ item, onSuccess, replyOpen, children
}
}
}`, {
- onCompleted ({ upsertComment: { text } }) {
- markImagesAsSubmitted(text)
- },
update (cache, { data: { upsertComment } }) {
cache.modify({
id: `Item:${parentId}`,
diff --git a/pages/_app.js b/pages/_app.js
index a29ef1f3..e41b9c18 100644
--- a/pages/_app.js
+++ b/pages/_app.js
@@ -17,7 +17,6 @@ import { SSR } from '../lib/constants'
import NProgress from 'nprogress'
import 'nprogress/nprogress.css'
import { LoggerProvider } from '../components/logger'
-import { ImageProvider } from '../components/image'
NProgress.configure({
showSpinner: false
@@ -90,23 +89,21 @@ export default function MyApp ({ Component, pageProps: { ...props } }) {
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+