-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
24 changed files
with
818 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { FC } from 'react'; | ||
import SpellForm from "@/widgets/Spell/SpellForm"; | ||
|
||
const SpellCreate: FC = () => { | ||
return ( | ||
<div className='main__block block_column p_40 w_100p'> | ||
<h3 className='mb_30'>Конструктор заклинаний</h3> | ||
|
||
<div className="block_row gap_20 w_100p technique__wrap"> | ||
<SpellForm/> | ||
</div> | ||
</div> | ||
); | ||
}; | ||
|
||
export default SpellCreate; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { FC } from 'react'; | ||
import { useParams } from "react-router-dom"; | ||
import SpellForm from "@/widgets/Spell/SpellForm"; | ||
|
||
const SpellEdit: FC = () => { | ||
const { id } = useParams() | ||
|
||
return ( | ||
<div className='main__block block_column p_40 w_100p'> | ||
<h3 className='mb_30'>Редактирование заклинания</h3> | ||
|
||
<div className="block_row gap_20 w_100p technique__wrap"> | ||
<SpellForm id={ id ? Number(id) : undefined }/> | ||
</div> | ||
</div> | ||
); | ||
}; | ||
|
||
export default SpellEdit; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import React, { FC, useEffect, useState } from 'react'; | ||
import { SpellType } from "@/shared/types/spell"; | ||
import Table from "@/shared/ui/Table/Table"; | ||
import { SpellColumn } from "@/widgets/Spell/Spell.column"; | ||
import { Link } from "react-router-dom"; | ||
import { pathRoutes } from "@/app"; | ||
import { MenuItem, Select } from "@mui/material"; | ||
import { useSpellFilter } from "@/shared/store/Spell"; | ||
import { useSpellStore } from "@/shared/store/SpellStore"; | ||
import { ElementDamage } from "@/widgets"; | ||
|
||
const SpellList: FC = () => { | ||
const [filterList, setFilterList] = useState<SpellType[] | []>([]) | ||
|
||
const { spellList } = useSpellStore() | ||
const { filter, setFilter } = useSpellFilter() | ||
|
||
useEffect(() => { | ||
if (filter.type_damage) { | ||
setFilterList(spellList.filter((spell) => spell.type_damage === filter.type_damage)) | ||
} else if (filter.name) { | ||
setFilterList(spellList.filter((spell) => { | ||
return spell.name.toLowerCase().includes(filter.name?.toLowerCase() || '') | ||
})) | ||
} else { | ||
setFilterList(spellList) | ||
} | ||
}, [filter, spellList]); | ||
|
||
return ( | ||
<div className='main__block block_column p_40 w_100p'> | ||
<h3 className='mb_30'>Список заклинаний</h3> | ||
|
||
<div className='block_row w_100p'> | ||
<div className="block_column align-start w_100p"> | ||
<label>Раса</label> | ||
<input className='w_100p' type='text' placeholder='Поиск по названию..' | ||
onChange={ (e) => setFilter({ ...filter, name: e.target.value }) }/> | ||
</div> | ||
|
||
<div className="block_column align-start w_100p"> | ||
<label>Стихия</label> | ||
<Select className='w_100p' value={ filter.type_damage } onChange={ (e) => setFilter({ ...filter, type_damage: e.target.value }) }> | ||
<MenuItem value=''>Любая стихия</MenuItem> | ||
{ ElementDamage.map(({ value, label, disabled }) => { | ||
if (!disabled) return <MenuItem value={ value } key={ value } disabled={ disabled }>{ label }</MenuItem> | ||
}) } | ||
</Select> | ||
</div> | ||
</div> | ||
|
||
<Table rows={ filterList } columns={ SpellColumn } style={ { isHeader: true } }/> | ||
|
||
<div className="block_row justify-end w_100p mt_10"> | ||
<Link to={ pathRoutes.spell.create }> | ||
<button className='button'>Создать</button> | ||
</Link> | ||
</div> | ||
</div> | ||
); | ||
}; | ||
|
||
export default SpellList; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export * from './SpellCreate' | ||
export * from './SpellEdit' | ||
export * from './SpellList' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
export * from './arena' | ||
export * from './axios' | ||
export * from './class' | ||
export * from './enemy' | ||
export * from './event' | ||
export * from './hero' | ||
export * from './item' | ||
export * from './race' | ||
export * from './spell' | ||
export * from './team' | ||
export * from './technique' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,129 @@ | ||
import { AxiosResponse } from "axios"; | ||
import axiosInstance from "@/shared/api/axios"; | ||
import { SpellBranchType, SpellEffectType, SpellType } from "@/shared/types/spell"; | ||
|
||
type allSpellQueryType = { | ||
hidden?: boolean, | ||
race_id?: number | ||
class_id?: number, | ||
hero_id?: number, | ||
} | ||
|
||
export const fetchAllSpell = async ({ race_id, class_id, hidden, hero_id }: allSpellQueryType) => { | ||
const response: AxiosResponse<SpellType[]> = await axiosInstance.get( | ||
`/spell`, | ||
{ | ||
params: { race_id, class_id, hidden, hero_id } | ||
} | ||
) | ||
|
||
return response | ||
} | ||
|
||
export const fetchOneSpell = async (spell_id: number) => { | ||
const response: AxiosResponse<SpellType> = await axiosInstance.get( | ||
`/spell/${ spell_id }`, | ||
) | ||
|
||
return response | ||
} | ||
|
||
export const createSpell = async (spell: SpellType) => { | ||
const response: AxiosResponse<SpellType> = await axiosInstance.post( | ||
`/spell`, | ||
{ ...spell }, | ||
) | ||
|
||
return response | ||
} | ||
|
||
export const updateSpell = async (spell: SpellType, spell_id: number) => { | ||
const response: AxiosResponse<SpellType> = await axiosInstance.put( | ||
`/spell/${ spell_id }`, | ||
{ ...spell }, | ||
) | ||
|
||
return response | ||
} | ||
|
||
|
||
// Effects | ||
export const fetchAllSpellEffect = async (spell_id: number) => { | ||
const response: AxiosResponse<SpellType[]> = await axiosInstance.get( | ||
`/spell/${ spell_id }/effect`, | ||
) | ||
|
||
return response | ||
} | ||
|
||
export const createSpellEffect = async (effect: SpellEffectType, spell_id: number) => { | ||
const response: AxiosResponse<SpellType> = await axiosInstance.post( | ||
`/spell/${ spell_id }/effect`, | ||
{ ...effect }, | ||
) | ||
|
||
return response | ||
} | ||
|
||
export const updateSpellEffect = async (effect: SpellEffectType, effect_id: number, spell_id: number) => { | ||
const response: AxiosResponse<SpellType> = await axiosInstance.put( | ||
`/spell/${ spell_id }/effect/${ effect_id }`, | ||
{ ...effect }, | ||
) | ||
|
||
return response | ||
} | ||
|
||
|
||
export const deleteSpellEffect = async (effect_id: number, spell_id: number) => { | ||
const response: AxiosResponse<SpellType[]> = await axiosInstance.delete( | ||
`/spell/${ spell_id }/effect/${ effect_id }`, | ||
) | ||
|
||
return response | ||
} | ||
|
||
|
||
// Branch | ||
export const fetchAllBranchSpell = async () => { | ||
const response: AxiosResponse<SpellBranchType[]> = await axiosInstance.get( | ||
`/spell/branch/`, | ||
) | ||
|
||
return response | ||
} | ||
|
||
export const fetchOneBranchSpell = async (branch_id: number) => { | ||
const response: AxiosResponse<SpellBranchType> = await axiosInstance.get( | ||
`/spell/branch/${ branch_id }`, | ||
) | ||
|
||
return response | ||
} | ||
|
||
export const createBranchSpell = async (data: SpellBranchType) => { | ||
const response: AxiosResponse<SpellBranchType> = await axiosInstance.post( | ||
`/spell/branch`, | ||
{ ...data }, | ||
) | ||
|
||
return response | ||
} | ||
|
||
export const updateBranchSpell = async (data: SpellBranchType, branch_id: number) => { | ||
const response: AxiosResponse<SpellBranchType> = await axiosInstance.put( | ||
`/spell/branch/${ branch_id }`, | ||
{ ...data }, | ||
) | ||
|
||
return response | ||
} | ||
|
||
|
||
export const deleteBranchSpell = async (branch_id: number) => { | ||
const response: AxiosResponse = await axiosInstance.delete( | ||
`/spell/branch/${ branch_id }`, | ||
) | ||
|
||
return response | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { SpellBranchType } from "@/shared/types"; | ||
import { create } from "zustand"; | ||
import { fetchAllBranchSpell } from "@/shared/api/spell"; | ||
|
||
interface SpellBranchState { | ||
spellBranchList: SpellBranchType[] | ||
getSpellBranchList: () => Promise<void> | ||
clearSpellBranchList: () => void | ||
} | ||
|
||
export const useSpellBranchStore = create<SpellBranchState>((set, get) => ({ | ||
spellBranchList: [], | ||
getSpellBranchList: async () => { | ||
const res = await fetchAllBranchSpell() | ||
if (res.data) set({ spellBranchList: res.data }) | ||
}, | ||
clearSpellBranchList: () => set({ spellBranchList: [] }), | ||
})) |
Oops, something went wrong.