s3browser-frontend/src/index.tsx

81 lines
1.8 KiB
TypeScript
Raw Normal View History

2021-07-26 12:54:22 +00:00
import React from "react"
import ReactDOM from "react-dom"
import "./index.scss"
import App from "./App"
import { ApolloClient, ApolloProvider, InMemoryCache } from "@apollo/client"
2021-08-10 09:21:18 +00:00
import "react-contexify/dist/ReactContexify.css"
2021-09-28 14:07:00 +00:00
import ObjID from "./types/ObjID"
2021-07-26 12:54:22 +00:00
const client = new ApolloClient({
2021-08-27 19:17:10 +00:00
uri: "/api/graphql",
2021-09-09 11:56:23 +00:00
cache: new InMemoryCache({
typePolicies:{
2021-09-28 14:07:00 +00:00
File:{
fields:{
id:{
merge(_,incomming){
// HACK: i use the merge function to change the id from a string to ObjID object.
// afaik apollo does not yet support custom scalar types.
if (!incomming){
return incomming
}else if (incomming instanceof ObjID){
return incomming
}else{
return ObjID.fromString(incomming as string)
}
}
}
}
},
Directory:{
fields:{
id:{
merge(_,incomming){
if (!incomming){
return incomming
}else if (incomming instanceof ObjID){
return incomming
}else{
return ObjID.fromString(incomming as string)
}
}
}
}
},
2021-09-09 11:56:23 +00:00
Query: {
fields: {
files: {
merge(existing, incoming){
return incoming
}
},
directorys:{
merge(existing, incoming){
return incoming
}
}
}
}
}
})
2021-07-26 12:54:22 +00:00
})
// Disable drag and drop behaviour on document
function disable(event: DragEvent) {
event.preventDefault()
event.stopPropagation()
}
document.addEventListener("dragenter",disable)
document.addEventListener("dragleave",disable)
document.addEventListener("dragover",disable)
document.addEventListener("drop",disable)
2021-07-26 12:54:22 +00:00
ReactDOM.render(
<React.StrictMode>
<ApolloProvider client={client}>
<App />
</ApolloProvider>
</React.StrictMode>,
document.getElementById("root")
)