-
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.
Showing
14 changed files
with
340 additions
and
72 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 was deleted.
Oops, something went wrong.
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 @@ | ||
import { $, component$, useContext, useSignal, useTask$ } from "@builder.io/qwik"; | ||
import { Button } from "~/components/button"; | ||
import { AppContext } from "~/stores/appContext"; | ||
import { DeckCreationContext } from "~/stores/deckCreationContext"; | ||
|
||
interface DeckImporterProps { | ||
isOpen: boolean; | ||
onClose: () => void; | ||
} | ||
|
||
export const DeckImporter = component$<DeckImporterProps>(({ isOpen, onClose }) => { | ||
const dialogRef = useSignal<HTMLDialogElement>(); | ||
const textAreaRef = useSignal<HTMLTextAreaElement>(); | ||
|
||
// context | ||
const c = useContext(DeckCreationContext); | ||
const app = useContext(AppContext); | ||
|
||
// HANDLERS | ||
const handleImport = $(async () => { | ||
await c.cleanDeck(); | ||
|
||
try { | ||
const text = textAreaRef.value?.value; | ||
if (!text) { | ||
onClose(); | ||
return; | ||
} | ||
|
||
app.isLoading = true; | ||
await c.importDeck(text); | ||
} catch (e) { | ||
console.error(e); | ||
} finally { | ||
app.isLoading = false; | ||
onClose(); | ||
} | ||
}) | ||
|
||
// EFFECTS | ||
useTask$(({ track }) => { | ||
track(() => isOpen); | ||
if (!isOpen) { | ||
dialogRef.value?.close(); | ||
} else { | ||
dialogRef.value?.showModal(); | ||
} | ||
}) | ||
|
||
return ( | ||
<dialog ref={dialogRef} class="p-4 container max-w-xl"> | ||
<textarea disabled={app.isLoading} ref={textAreaRef} class="w-full h-full p-4" rows={10} placeholder="Paste your deck here..."/> | ||
<div class="flex items-center justify-end gap-2"> | ||
<Button disabled={app.isLoading} onClick$={() => onClose()}>Cancel</Button> | ||
<Button disabled={app.isLoading} onClick$={() => handleImport()}>Import</Button> | ||
</div> | ||
</dialog> | ||
); | ||
|
||
}) |
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,14 @@ | ||
import { RequestEventBase, server$ } from "@builder.io/qwik-city"; | ||
import { ImportDeckRequest } from "~/models/application/ImportCardItem"; | ||
import { DeckState } from "~/models/Deck"; | ||
import { DeckRepository } from "~/providers/repositories/DeckRepository"; | ||
|
||
type FetchDeckImport = (this: RequestEventBase, deckImportRequest: ImportDeckRequest) => Promise<DeckState> | ||
|
||
export const fetchDeckImport = server$<FetchDeckImport>(async function (deckImportRequest) { | ||
const deckRepo = new DeckRepository(this); | ||
|
||
const deck = await deckRepo.getDeckByImport(deckImportRequest); | ||
|
||
return deck; | ||
}) |
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,10 @@ | ||
export interface ImportCardItem { | ||
name: string; | ||
quantity: number; | ||
} | ||
|
||
export interface ImportDeckRequest { | ||
realm: ImportCardItem[]; | ||
treasure: ImportCardItem[]; | ||
side: ImportCardItem[]; | ||
} |
Oops, something went wrong.