-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support Warhammer app text imports (#1394)
* Update deps * Add sample/tests * Add cleanWarhammerAppText * Add another test army * First stab at UI element * First shot at it working! * Improved import (send to s3 on error, log to GA) * Add app_banner * Update Subscribe.tsx * Update .prettierrc
- Loading branch information
1 parent
f9d3776
commit bcd1846
Showing
22 changed files
with
1,633 additions
and
83 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
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,77 @@ | ||
import { PreferenceApi } from 'api/preferenceApi' | ||
import GenericButton from 'components/input/generic_button' | ||
import { useAppStatus } from 'context/useAppStatus' | ||
import React, { useState } from 'react' | ||
import { IImportedArmy, TXT_FILE, WARHAMMER_APP } from 'types/import' | ||
import { logEvent } from 'utils/analytics' | ||
import { isValidFactionName } from 'utils/armyUtils' | ||
import { hasErrorOrWarning } from 'utils/import/warnings' | ||
import { getWarhammerAppArmy } from 'utils/warhammer_app/getWarhammerAppArmy' | ||
import { cleanWarhammerAppText } from 'utils/warhammer_app/warhammerAppUtils' | ||
|
||
const BADGE_CLASS = `badge badge-pill badge-` | ||
|
||
interface IImportTextAreaProps { | ||
handleDrop: (army: IImportedArmy) => void | ||
} | ||
|
||
export const ImportTextarea: React.FC<IImportTextAreaProps> = ({ handleDrop }) => { | ||
const { isOnline } = useAppStatus() | ||
const [text, setText] = useState('') | ||
|
||
const handleImport = () => { | ||
// parse the text and then send it back as an army | ||
const cleanedText = cleanWarhammerAppText(text) | ||
const army = getWarhammerAppArmy(cleanedText) | ||
|
||
if (isOnline && hasErrorOrWarning(army.errors)) { | ||
const payload = { | ||
fileTxt: text, | ||
parser: WARHAMMER_APP, | ||
fileType: TXT_FILE, | ||
} | ||
Promise.resolve(PreferenceApi.createErrorFile(payload)) | ||
} | ||
|
||
if (isOnline && isValidFactionName(army.factionName)) { | ||
logEvent(`Import${WARHAMMER_APP}-${army.factionName}`) | ||
} | ||
|
||
return handleDrop(army) | ||
} | ||
|
||
return ( | ||
<> | ||
<div className="row"> | ||
<div className="col-12"> | ||
<div className="form-group"> | ||
<textarea | ||
name="ImportTextarea" | ||
id="ImportTextarea" | ||
className={'ImportTextarea'} | ||
placeholder={'Or paste your Warhammer App list here'} | ||
onChange={e => { | ||
e.preventDefault() | ||
setText(e.target.value) | ||
}} | ||
value={text} | ||
/> | ||
</div> | ||
</div> | ||
{text && ( | ||
<div className="col-12 pb-3 ml-3"> | ||
<div className="btn-group" role="group"> | ||
<GenericButton className={`${BADGE_CLASS}success mr-1`} type="button" onClick={handleImport}> | ||
Import | ||
</GenericButton> | ||
|
||
<GenericButton className={`${BADGE_CLASS}danger mr-1`} onClick={() => setText('')}> | ||
Clear | ||
</GenericButton> | ||
</div> | ||
</div> | ||
)} | ||
</div> | ||
</> | ||
) | ||
} |
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,60 @@ | ||
Army Name: Fyreslayers1 | ||
Army Notes: Some notes go here | ||
Army Faction: Fyreslayers | ||
Subfaction: Greyfyrd | ||
Battlepack: Pitched Battles | ||
Points Limit: 2000 pts | ||
General: Auric Runefather | ||
|
||
Units | ||
Auric Runefather (General) | ||
Battlefield Role: Leader | ||
Enhancements | ||
Command Traits: Destroyer of Foes | ||
Artefacts of Power: Helm of Obsidia | ||
Points Cost: 100 pts | ||
Bundo Whalebiter (Ally) | ||
Battlefield Role: Battleline, Behemoth, Leader | ||
Points Cost: 490 pts | ||
Fjul-Grimnir | ||
Battlefield Role: Leader | ||
Points Cost: 150 pts | ||
Auric Runemaster | ||
Battlefield Role: Leader | ||
Points Cost: 115 pts | ||
Auric Runesmiter | ||
Battlefield Role: Leader | ||
Enhancements | ||
Artefacts of Power: Ancestor Helm | ||
Prayers: Prayer Of Ash | ||
Points Cost: 120 pts | ||
Auric Runesmiter on Magmadroth | ||
Battlefield Role: Behemoth, Leader | ||
Points Cost: 275 pts | ||
Auric Runeson | ||
Battlefield Role: Leader | ||
Enhancements | ||
Artefacts of Power: Helm of Obsidia | ||
Points Cost: 90 pts | ||
Auric Runeson on Magmadroth | ||
Battlefield Role: Behemoth, Leader | ||
Points Cost: 240 pts | ||
Battlesmith | ||
Battlefield Role: Leader | ||
Enhancements | ||
Artefacts of Power: Draught of Magmalt Ale | ||
Points Cost: 125 pts | ||
Fjul-Grimnir | ||
Battlefield Role: Leader | ||
Points Cost: 150 pts | ||
Warden King (Ally) | ||
Battlefield Role: Leader | ||
Points Cost: 100 pts | ||
|
||
Core Battalions | ||
Alpha-Beast Pack | ||
Alpha-Beast Pack | ||
Battle Regiment | ||
|
||
Total Points: 1805 pts | ||
Invalid: Created with Warhammer Age of Sigmar: The App |
Oops, something went wrong.