Add manual add for challanges

This commit is contained in:
2025-12-16 03:27:57 +07:00
parent a199952383
commit fe6012b7a3
2 changed files with 269 additions and 41 deletions

View File

@@ -32,6 +32,16 @@ const EVENT_ICONS: Record<EventType, React.ReactNode> = {
game_choice: <Gamepad2 className="w-4 h-4" />,
}
// Default durations for events (in minutes)
const DEFAULT_DURATIONS: Record<EventType, number | null> = {
golden_hour: 45,
common_enemy: null, // Until all complete
double_risk: 120,
jackpot: null, // 1 spin
swap: 60,
game_choice: 120,
}
export function EventControl({
marathonId,
activeEvent,
@@ -42,9 +52,17 @@ export function EventControl({
const confirm = useConfirm()
const [selectedType, setSelectedType] = useState<EventType>('golden_hour')
const [selectedChallengeId, setSelectedChallengeId] = useState<number | null>(null)
const [durationMinutes, setDurationMinutes] = useState<number | ''>(45)
const [isStarting, setIsStarting] = useState(false)
const [isStopping, setIsStopping] = useState(false)
// Update duration when event type changes
const handleTypeChange = (type: EventType) => {
setSelectedType(type)
const defaultDuration = DEFAULT_DURATIONS[type]
setDurationMinutes(defaultDuration ?? '')
}
const handleStart = async () => {
if (selectedType === 'common_enemy' && !selectedChallengeId) {
toast.warning('Выберите челлендж для события "Общий враг"')
@@ -55,6 +73,7 @@ export function EventControl({
try {
await eventsApi.start(marathonId, {
type: selectedType,
duration_minutes: durationMinutes || undefined,
challenge_id: selectedType === 'common_enemy' ? selectedChallengeId ?? undefined : undefined,
})
onEventChange()
@@ -119,7 +138,7 @@ export function EventControl({
{EVENT_TYPES.map((type) => (
<button
key={type}
onClick={() => setSelectedType(type)}
onClick={() => handleTypeChange(type)}
className={`
p-3 rounded-lg border-2 transition-all text-left
${selectedType === type
@@ -138,6 +157,27 @@ export function EventControl({
))}
</div>
{/* Duration setting */}
{DEFAULT_DURATIONS[selectedType] !== null && (
<div>
<label className="block text-sm font-medium text-gray-300 mb-2">
Длительность (минуты)
</label>
<input
type="number"
value={durationMinutes}
onChange={(e) => setDurationMinutes(e.target.value ? parseInt(e.target.value) : '')}
min={1}
max={480}
placeholder={`По умолчанию: ${DEFAULT_DURATIONS[selectedType]}`}
className="w-full p-2 bg-gray-700 border border-gray-600 rounded-lg text-white"
/>
<p className="text-xs text-gray-500 mt-1">
Оставьте пустым для значения по умолчанию ({DEFAULT_DURATIONS[selectedType]} мин)
</p>
</div>
)}
{selectedType === 'common_enemy' && challenges && challenges.length > 0 && (
<div>
<label className="block text-sm font-medium text-gray-300 mb-2">