Skip to content

Commit

Permalink
fix: remove IndexedDB (#98)
Browse files Browse the repository at this point in the history
  • Loading branch information
EehMauro authored Nov 25, 2024
1 parent f533515 commit 83f2a6d
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 71 deletions.
33 changes: 1 addition & 32 deletions frontend/src/pages/_app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,38 +25,7 @@ const client = new ApolloClient({
export default function App({ Component, pageProps }: AppPropsWithLayout) {
const { select, selected } = useChallengeStore();

const storeApiUrl = (db: IDBDatabase) => {
const tx = db.transaction('FILE_DATA', 'readwrite').objectStore('FILE_DATA').put(
{
contents: new TextEncoder().encode(process.env.API_URL),
timestamp: new Date(),
mode: 33206,
},
'/userfs/godot/app_userdata/visualizer/api_url'
);
tx.onsuccess = () => select(0);
tx.onerror = () => select(0);
}

useEffect(() => {
try {
const request = window.indexedDB.open('/userfs');
request.onupgradeneeded = (event) => {
const db = request.result;
db.createObjectStore('FILE_DATA');
const tx = (event.target as any).transaction;
tx.oncomplete = () => storeApiUrl(db);
tx.onerror = () => select(0);
};
request.onsuccess = () => {
const db = request.result;
storeApiUrl(db);
}
request.onerror = () => select(0);
} catch (error) {
select(0);
}
}, []);
useEffect(() => select(0), []);

return (
<ApolloProvider client={client}>
Expand Down
33 changes: 1 addition & 32 deletions frontend/src/stores/challenge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,36 +21,5 @@ export const useChallengeStore = create<ChallengeStoreState>((set, get) => ({
network: 'preview',
}],
current: () => get().challenges[get().selected!],
select: (index: number) => {
try {
const storePolicyId = (db: IDBDatabase) => {
const tx = db.transaction('FILE_DATA', 'readwrite').objectStore('FILE_DATA').put(
{
contents: new TextEncoder().encode(get().challenges[index].policyId),
timestamp: new Date(),
mode: 33206,
},
'/userfs/godot/app_userdata/visualizer/api_url'
);
tx.onsuccess = () => set(() => ({ selected: index }));
tx.onerror = () => set(() => ({ selected: index }));
}

set(() => ({ selected: null }));
const request = window.indexedDB.open('/userfs');
request.onupgradeneeded = (event) => {
const db = request.result;
db.createObjectStore('FILE_DATA');
const tx = (event.target as any).transaction;
tx.oncomplete = () => storePolicyId(db);
tx.onerror = () => set(() => ({ selected: index }));
};
request.onsuccess = () => {
const db = request.result;
storePolicyId(db);
};
} catch (error) {
set(() => ({ selected: index }));
}
},
select: (index: number) => set(() => ({ selected: index })),
}));
14 changes: 7 additions & 7 deletions godot-visualizer/scripts/main.gd
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,13 @@ func _process(delta: float) -> void:


func _ready():
if OS.is_userfs_persistent():
var stored_api_url = FileAccess.open("user://api_url", FileAccess.READ).get_as_text()
if stored_api_url.length() > 0:
api_url = stored_api_url + "/graphql"
var stored_shipyard_policy_id = FileAccess.open("user://shipyard_policy_id", FileAccess.READ).get_as_text()
if stored_shipyard_policy_id.length() > 0:
shipyard_policy_id = stored_shipyard_policy_id
#if OS.is_userfs_persistent():
#var stored_api_url = FileAccess.open("user://api_url", FileAccess.READ).get_as_text()
#if stored_api_url.length() > 0:
#api_url = stored_api_url + "/graphql"
#var stored_shipyard_policy_id = FileAccess.open("user://shipyard_policy_id", FileAccess.READ).get_as_text()
#if stored_shipyard_policy_id.length() > 0:
#shipyard_policy_id = stored_shipyard_policy_id

$HTTPRequest.request_completed.connect(_on_request_completed)
$HTTPRequest.request(api_url, headers, HTTPClient.METHOD_POST, JSON.stringify({ "query": query % [radius, shipyard_policy_id] }))
Expand Down

0 comments on commit 83f2a6d

Please sign in to comment.