Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions packages/client/src/workspaces/contexts/ThothInterfaceProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,23 @@ import { usePubSub } from '../../contexts/PubSubProvider'
import { useFetchFromImageCacheMutation } from '@/state/api/visualGenerationsApi'
import { useGetSpellQuery, useRunSpellMutation } from '@/state/api/spells'
import { useAuth } from '@/contexts/AuthProvider'
import { useDispatch } from 'react-redux'
import { closeTab } from '@/state/tabs'
import { useNavigate } from 'react-router'

const Context = createContext<EditorContext>(undefined!)

export const useThothInterface = () => useContext(Context)

const ThothInterfaceProvider = ({ children, tab }) => {
const dispatch = useDispatch()
const navigate = useNavigate()
const { events, publish, subscribe } = usePubSub()
const spellRef = useRef<Spell | null>(null)
const [fetchFromImageCache] = useFetchFromImageCacheMutation()
const { user } = useAuth()
const [_runSpell] = useRunSpellMutation()
const { data: _spell } = useGetSpellQuery(
const { data: _spell, isError: _isSpellError } = useGetSpellQuery(
{
spellId: tab.spellId,
userId: user?.id as string,
Expand All @@ -34,9 +39,16 @@ const ThothInterfaceProvider = ({ children, tab }) => {
)

useEffect(() => {
console.log();

if (!_spell && _isSpellError) {
dispatch(closeTab(tab.id))
navigate('/home')
return
}
if (!_spell) return
spellRef.current = _spell
}, [_spell])
}, [_spell, _isSpellError])

const {
$PLAYTEST_INPUT,
Expand Down
9 changes: 1 addition & 8 deletions packages/server/src/routes/spells/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -303,14 +303,7 @@ const getSpellHandler = async (ctx: Koa.Context) => {
})

if (!spell) {
const newSpell = await creatorToolsDatabase.spells.create({
userId: ctx.state.user?.id ?? ctx.query.userId,
name,
graph: { id: '[email protected]', nodes: {} },
gameState: {},
modules: [],
})
ctx.body = newSpell
throw new Error('Spell not found')
} else {
let userId = ctx.state.user?.id ?? ctx.query.userId
if (spell?.userId !== userId) throw new Error('spell not found')
Expand Down