Skip to content

Commit

Permalink
feat: Now you can load cards from your stash tabs
Browse files Browse the repository at this point in the history
  • Loading branch information
shonya3 committed May 26, 2023
1 parent 6fb7251 commit 9c4ff22
Show file tree
Hide file tree
Showing 34 changed files with 2,172 additions and 70 deletions.
Binary file added public/InventoryIcon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/currency-tab-icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/essence-tab-icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/fragment-tab-icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/map-tab-icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/premium-tab-icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
13 changes: 12 additions & 1 deletion src-tauri/lib/src/commands.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use divi::{Csv, CsvString, DivinationCardsSample, League, Prices};
use divi::{CardNameAmount, Csv, CsvString, DivinationCardsSample, League, Prices};
use tauri::{command, AppHandle, Manager};

use crate::prices;
Expand All @@ -14,6 +14,17 @@ pub async fn sample(
)
}

#[command]
pub async fn sample_cards(
cards: Vec<CardNameAmount>,
league: League,
) -> Result<DivinationCardsSample, divi::error::MissingHeaders> {
DivinationCardsSample::create(
Csv::CardNameAmountList(cards),
prices::prices(&league).await,
)
}

#[command]
pub async fn chaos(sample: Box<DivinationCardsSample>, min: Option<f32>) -> f32 {
sample.as_ref().chaos(min)
Expand Down
1 change: 0 additions & 1 deletion src-tauri/lib/src/google.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,6 @@ pub struct Identity {
pub async fn google_auth() -> Result<String, String> {
// auth(GoogleProvider::default()).await
let result = GoogleProvider::new().oauth().await;
dbg!(result.clone());
result
}

Expand Down
67 changes: 65 additions & 2 deletions src-tauri/lib/src/poe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@ use std::net::{IpAddr, Ipv4Addr, SocketAddr};

use crate::oauth::{AuthCodeResponse, OAuthProvider};
use axum::{async_trait, extract::Query, response::Html, routing::get, Router};
use divi::League;
use keyring::Entry;
use oauth2::{basic::BasicClient, AccessToken, CsrfToken, PkceCodeChallenge, RedirectUrl, Scope};
use reqwest::Client;
use serde::{Deserialize, Serialize};
use serde_json::Value;
use tauri::command;
use tokio::sync::mpsc;

Expand All @@ -27,6 +30,22 @@ pub fn poe_logout() {
AccessTokenStorage::new().delete().unwrap()
}

#[command]
pub async fn stashes(league: League) -> Value {
let val = PoeProvider::stashes(league).await;
// dbg!(&val);
val
}

#[command]
pub async fn stash(league: League, stash_id: String, substash_id: Option<String>) -> Value {
let val = PoeProvider::stash(league, stash_id, substash_id).await;
// dbg!(&val);
val
}

pub const API_URL: &'static str = "https://api.pathofexile.com";

#[derive(Default)]
pub struct PoeProvider;

Expand All @@ -38,9 +57,53 @@ impl PoeProvider {
pub fn access_token_label() -> String {
format!("{}_access_token", { Self::PROVIDER_LABEL })
}
}

impl PoeProvider {
async fn stash(league: League, stash_id: String, substash_id: Option<String>) -> Value {
let url = match substash_id {
Some(substash_id) => {
format!("{}/stash/{}/{}/{}", API_URL, league, stash_id, substash_id)
}
None => format!("{}/stash/{}/{}", API_URL, league, stash_id),
};

dbg!(&url);
Client::new()
.get(url)
.header(
"Authorization",
format!("Bearer {}", { AccessTokenStorage::new().get().unwrap() }),
)
.header(
"User-Agent",
"OAuth divicards/0.1.8 (contact: poeshonya3@gmail.com)",
)
.send()
.await
.unwrap()
.json::<Value>()
.await
.unwrap()
}

async fn stashes(league: League) -> Value {
Client::new()
.get(format!("{}/stash/{}", API_URL, league))
.header(
"Authorization",
format!("Bearer {}", { AccessTokenStorage::new().get().unwrap() }),
)
.header(
"User-Agent",
"OAuth divicards/0.1.8 (contact: poeshonya3@gmail.com)",
)
.send()
.await
.unwrap()
.json::<Value>()
.await
.unwrap()
}

async fn fetch_token(
code: &str,
pkce_verifier: &str,
Expand Down
5 changes: 4 additions & 1 deletion src-tauri/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ async fn main() {
commands::chaos,
commands::merge,
commands::league,
commands::sample_cards,
discord::discord_auth,
discord::discord_authenticated,
discord::discord_identity,
Expand All @@ -50,7 +51,9 @@ async fn main() {
google::google_identity,
poe::poe_auth,
poe::poe_logout,
poe::poe_authenticated
poe::poe_authenticated,
poe::stashes,
poe::stash
])
.run(tauri::generate_context!())
.expect("error while running tauri application");
Expand Down
70 changes: 33 additions & 37 deletions src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,18 @@ import { useFileCardsStore } from './stores/fileCards';
import { storeToRefs } from 'pinia';
import { ref } from 'vue';
import { useAutoAnimate } from './composables/useAutoAnimate';
import HelpTip from './components/HelpTip.vue';
import { usePoeOAuth2Store } from './stores/poeOAuth2Store';
import PoeAuth from './components/PoeAuth.vue';
import StashesMainComponent from './components/stashes/StashesMainComponent.vue';
import DropFilesMessage from './components/DropFilesMessage.vue';
const filesStore = useFileCardsStore();
const { fileCards: files, selectedFiles, mergedFile } = storeToRefs(filesStore);
const { deleteFile, addCards, deleteAllFiles, merge, deleteMergedFile, downloadAll } = filesStore;
const poeOAuthStore = usePoeOAuth2Store();
const { loggedIn } = storeToRefs(poeOAuthStore);
const filesTemplateRef = ref<HTMLElement | null>(null);
useAutoAnimate(filesTemplateRef);
Expand All @@ -19,42 +24,35 @@ const onDrop = (e: DragEvent) => {
if (dropFiles) addCards(Array.from(dropFiles));
};
const { loggedIn, name } = storeToRefs(usePoeOAuth2Store());
const { login, logout, checkLoggedIn, init } = usePoeOAuth2Store();
const stashes = ref([]);
init();
const stashVisible = ref(false);
const openStashWindow = () => {
if (loggedIn.value) {
stashVisible.value = true;
} else {
poeOAuthStore.login().then(() => {
if (loggedIn.value) {
stashVisible.value = true;
}
});
}
};
</script>

<template>
<div v-if="loggedIn">
<p>{{ name }}</p>
<p>Logged in</p>
<button @click="logout">Logout</button>
</div>
<div v-else>
<button @click="login">Login</button>
</div>

<div v-if="loggedIn">
<pre>{{ stashes }}</pre>
<button>Stashes</button>
</div>

<div
@drop.prevent="onDrop"
@dragenter="(e: DragEvent) => e.preventDefault()"
@dragover="(e: DragEvent) => e.preventDefault()"
class="drag"
>
<div style="display: flex; gap: 1rem">
<div class="drop">Drop files <span>Here!</span></div>
<HelpTip>
<p>Excel, .csv or just .txt</p>
<p>Required headers: name and amount</p>
<img src="/simple.png" alt="" />
</HelpTip>
<header class="header">
<DropFilesMessage />
<button @click="openStashWindow()">Load from stash</button>
<PoeAuth />
</header>

<div v-if="loggedIn && stashVisible">
<StashesMainComponent @close="stashVisible = false" />
</div>

<Transition>
Expand Down Expand Up @@ -90,6 +88,12 @@ init();
</template>

<style scoped>
.header {
display: flex;
justify-content: space-between;
margin-bottom: 3rem;
}
.v-enter-active,
.v-leave-active {
transition: opacity 0.5s ease;
Expand All @@ -112,10 +116,7 @@ init();
.drag--active {
filter: hue-rotate(120deg);
}
.drop {
font-size: 3rem;
margin-bottom: 1rem;
}
.files {
display: flex;
flex-wrap: wrap;
Expand All @@ -127,9 +128,4 @@ init();
padding: 0.4rem;
font-size: 1.4rem;
}
.drop > span {
color: deeppink;
font-weight: 700;
}
</style>
6 changes: 5 additions & 1 deletion src/command.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import { invoke } from '@tauri-apps/api';
import { DivinationCardsSample, League, DiscordIdentity, GoogleIdentity } from './types';
import { DivinationCardsSample, League, DiscordIdentity, GoogleIdentity, leagues, CardNameAmount } from './types';
import { StashesResponseData, StashResponseData } from './poe/types';

export interface Commands {
sample: (args: { csv: string; league: League }) => DivinationCardsSample;
sample_cards: (args: { cards: CardNameAmount[]; league: League }) => DivinationCardsSample;
chaos: (args: { sample: DivinationCardsSample; min: number }) => number;
merge: (args: { samples: DivinationCardsSample[] }) => DivinationCardsSample;
league: (args: { sample: DivinationCardsSample; league: League }) => DivinationCardsSample;
Expand All @@ -15,6 +17,8 @@ export interface Commands {
poe_auth: () => string;
poe_authenticated: () => boolean;
poe_logout: () => void;
stashes: (args: { league: League }) => StashesResponseData;
stash: (args: { league: League; stashId: string; subStashId?: string }) => StashResponseData;
}

const { format } = new Intl.NumberFormat();
Expand Down
5 changes: 3 additions & 2 deletions src/components/BasePopup.vue
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ onUnmounted(() => {
display: flex;
justify-content: center;
align-items: center;
z-index: 3;
}
.backdrop {
opacity: 70%;
Expand All @@ -67,7 +68,7 @@ onUnmounted(() => {
left: 0;
position: absolute;
z-index: 2;
z-index: 3;
}
.popup_content {
Expand All @@ -84,6 +85,6 @@ onUnmounted(() => {
z-index: 10;
top: 0;
z-index: 3;
z-index: 4;
}
</style>
6 changes: 6 additions & 0 deletions src/components/DivTable/DivTable.vue
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ const order = ref<SortState>({
amount: 'asc',
price: 'asc',
sum: 'asc',
name: 'asc',
});
watch(
Expand Down Expand Up @@ -113,6 +114,11 @@ onMounted(() => {
</th>
<th>
<span class="column__name"> Name </span>
<order-triangle
:active="order.activeColumn === 'name'"
:order="order.name"
@click="toggleOrder('name')"
/>
</th>
<th>
<span class="column__name"> Price </span>
Expand Down
10 changes: 10 additions & 0 deletions src/components/DivTable/orderBy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,18 @@ export const bySum = (order: Order, cards: DivinationCardRecord[]) => {
});
};

export const byName = (order: Order, cards: DivinationCardRecord[]) => {
return cards.sort((a, b) => {
if (order === 'asc') return a.name < b.name ? -1 : 1;
if (order === 'desc') return a.name > b.name ? -1 : 1;
throw new Error('invalid order');
});
};

export const orderBy = (column: Column, order: Order, cards: DivinationCardRecord[]): DivinationCardRecord[] => {
switch (column) {
case 'name':
return byName(order, cards);
case 'price':
return byPrice(order, cards);
case 'amount':
Expand Down
2 changes: 1 addition & 1 deletion src/components/DivTable/types.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Order } from '../../types';

export type Column = 'price' | 'amount' | 'sum';
export type Column = 'price' | 'amount' | 'sum' | 'name';
export type SortState = {
[col in Column]: Order;
} & { activeColumn: Column };
26 changes: 26 additions & 0 deletions src/components/DropFilesMessage.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<script setup lang="ts">
import HelpTip from './HelpTip.vue';
</script>

<template>
<div style="display: flex; gap: 1rem">
<div class="drop">Drop files <span>Here!</span></div>
<HelpTip>
<p>Excel, .csv or just .txt</p>
<p>Required headers: name and amount</p>
<img src="/simple.png" alt="" />
</HelpTip>
</div>
</template>

<style scoped>
.drop {
font-size: 3rem;
margin-bottom: 1rem;
}
.drop > span {
color: deeppink;
font-weight: 700;
}
</style>
Loading

0 comments on commit 9c4ff22

Please sign in to comment.