Skip to content

Commit

Permalink
feat: Download as general tab
Browse files Browse the repository at this point in the history
  • Loading branch information
shonya3 committed Apr 15, 2024
1 parent 9718ed7 commit 44c91de
Show file tree
Hide file tree
Showing 8 changed files with 159 additions and 55 deletions.
10 changes: 10 additions & 0 deletions packages/app/src-tauri/lib/src/poe/stash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,16 @@ pub async fn sample_from_tab(
Ok(sample)
}

#[instrument]
#[command]
pub async fn tab_with_items(
league: League,
stash_id: String,
version: State<'_, AppVersion>,
) -> Result<TabWithItems, Error> {
StashAPI::tab_with_items(&league, stash_id, None, version.inner()).await
}

#[instrument]
#[command]
pub async fn stashes(league: League, version: State<'_, AppVersion>) -> Result<Value, Error> {
Expand Down
1 change: 1 addition & 0 deletions packages/app/src-tauri/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ async fn main() {
poe::auth::poe_logout,
poe::stash::stashes,
poe::stash::sample_from_tab,
poe::stash::tab_with_items,
google::auth::google_auth,
google::auth::google_logout,
google::auth::google_identity,
Expand Down
35 changes: 34 additions & 1 deletion packages/app/src/App.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<script setup lang="ts">
import { ref, onMounted } from 'vue';
import { ref, onMounted, Ref } from 'vue';
import { StashLoader } from './StashLoader';
import { command } from './command';
Expand Down Expand Up @@ -27,6 +27,7 @@ import { BasePopupElement } from '@divicards/wc/src/wc/base-popup';
import UpdateChangelog from './components/UpdateChangelog.vue';
import NativeBrowserLink from './components/NativeBrowserLink.vue';
import { useAppVersion } from './composables/useAppVersion';
import { TabWithItems } from '@divicards/shared/poe.types';
const sampleStore = useSampleStore();
const authStore = useAuthStore();
Expand All @@ -36,6 +37,8 @@ const tablePreferences = useTablePreferencesStore();
const stashVisible = ref(false);
const { releaseUrl, tag } = useAppVersion();
const tabsWithItems: Ref<TabWithItems[]> = ref<TabWithItems[]>([]);
const changelogPopupRef = ref<BasePopupElement | null>(null);
const formPopupExportRef = ref<BasePopupElement | null>(null);
const samplesContainerRef = ref<HTMLElement | null>(null);
Expand Down Expand Up @@ -134,6 +137,12 @@ const onSubmit = async ({
formPopupExportRef.value?.hide();
}
};
const onTabWithItemsLoaded = (name: string, tab: TabWithItems, league: League) => {
console.log({ name, tab, league });
tab.items.sort((a, b) => (b.stackSize ?? 0) - (a.stackSize ?? 0));
tabsWithItems.value.push(tab);
};
</script>

<template>
Expand Down Expand Up @@ -174,6 +183,7 @@ const onSubmit = async ({
<StashesView
:stashLoader="stashLoader"
@sample-from-tab="sampleStore.addSample"
@tab-with-items-loaded="onTabWithItemsLoaded"
@close="stashVisible = false"
/>
</div>
Expand Down Expand Up @@ -203,6 +213,29 @@ const onSubmit = async ({
</div>
</div>
<ul v-for="tab in tabsWithItems">
<li>
{{ tab.name }}
<details>
<summary>{{ tab.name }}</summary>
<table id="cards" class="table is-bordered is-narrow is-hoverable">
<thead>
<tr>
<th>Card</th>
<th>Count</th>
</tr>
</thead>
<tbody>
<tr v-for="item in tab.items">
<td>{{ item.baseType }}</td>
<td>{{ item.stackSize }}</td>
</tr>
</tbody>
</table>
</details>
</li>
</ul>
<Transition>
<div ref="filesTemplateRef" class="samples" v-show="sampleStore.sampleCards.length">
<SampleCard
Expand Down
6 changes: 5 additions & 1 deletion packages/app/src/StashLoader.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
import { IStashLoader } from '@divicards/shared/IStashLoader';
import { NoItemsTab } from '@divicards/shared/poe.types';
import { NoItemsTab, TabWithItems } from '@divicards/shared/poe.types';
import { DivinationCardsSample, League } from '@divicards/shared/types';
import { command } from './command';

export class StashLoader implements IStashLoader {
tab(tabId: string, league: string): Promise<TabWithItems> {
return command('tab_with_items', { league, stashId: tabId });
}

sampleFromTab(tabId: string, league: League): Promise<DivinationCardsSample> {
return command('sample_from_tab', { league, stashId: tabId });
}
Expand Down
3 changes: 2 additions & 1 deletion packages/app/src/command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
TablePreferences,
Column,
} from '@divicards/shared/types';
import { NoItemsTab } from '@divicards/shared/poe.types';
import { NoItemsTab, TabWithItems } from '@divicards/shared/poe.types';

export type SampleData = string | CardNameAmount[];
export type ValueRange = {
Expand Down Expand Up @@ -41,6 +41,7 @@ export interface Commands {
stashes: (args: { league: League }) => { stashes: NoItemsTab[] };
sample_into_csv: (args: { sample: DivinationCardsSample; preferences: Preferences }) => string;
sample_from_tab: (args: { league: League; stashId: string; subStashId?: string }) => DivinationCardsSample;
tab_with_items: (args: { league: League; stashId: string }) => TabWithItems;
}

const { format } = new Intl.NumberFormat();
Expand Down
7 changes: 7 additions & 0 deletions packages/app/src/components/StashesView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@ import { StashesViewElement, Events } from '@divicards/wc/src/wc/stashes/stashes
import { ACTIVE_LEAGUE } from '@divicards/shared/lib';
import type { StashesViewProps } from '@divicards/wc/src/wc/stashes/stashes-view';
import type { DivinationCardsSample, League } from '@divicards/shared/types';
import { TabWithItems } from '@divicards/shared/poe.types';
StashesViewElement.define();
withDefaults(defineProps<StashesViewProps>(), { league: ACTIVE_LEAGUE });
const emit = defineEmits<{
close: [];
'update:selectedTabs': [Set<string>];
'sample-from-tab': [string, DivinationCardsSample, League];
'tab-with-items-loaded': [string, TabWithItems, League];
}>();
const onUpdSelectedTabs = (e: CustomEvent<Set<string>>) => {
Expand All @@ -18,6 +20,10 @@ const onUpdSelectedTabs = (e: CustomEvent<Set<string>>) => {
const onSampleFromTab = (e: CustomEvent<Events['sample-from-tab']>) => {
emit('sample-from-tab', e.detail.name, e.detail.sample, e.detail.league);
};
const onTabWithItemsLoaded = (e: CustomEvent<Events['tab-with-items-loaded']>) => {
emit('tab-with-items-loaded', e.detail.name, e.detail.tab, e.detail.league);
};
</script>

<template>
Expand All @@ -27,5 +33,6 @@ const onSampleFromTab = (e: CustomEvent<Events['sample-from-tab']>) => {
@close="$emit('close')"
@upd:selectedTabs="onUpdSelectedTabs"
@sample-from-tab="onSampleFromTab"
@tab-with-items-loaded="onTabWithItemsLoaded"
></wc-stashes-view>
</template>
1 change: 1 addition & 0 deletions packages/shared/IStashLoader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { DivinationCardsSample, League } from './types';
export interface IStashLoader {
tabs(league: League): Promise<NoItemsTab[]>;
sampleFromTab(tabId: string, league: League): Promise<DivinationCardsSample>;
tab: (tabId: string, league: League) => Promise<TabWithItems>;
}

export interface IDefaultStashLoader {
Expand Down
Loading

0 comments on commit 44c91de

Please sign in to comment.