Skip to content

Commit 76e727c

Browse files
committed
fix: same storage interface
1 parent f430326 commit 76e727c

File tree

23 files changed

+825
-1096
lines changed

23 files changed

+825
-1096
lines changed

public/codes/package/axios/invest-app/js/components/InvestmentCard.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import Investments from '../lib/investments';
22
import InvestmentForm from './InvestmentForm';
33
import { $ } from '../lib/dom';
44
import { formatCurrency, formatDate } from '../lib/format';
5+
import { HSOverlay } from 'preline';
56

67
function create(investment) {
78
const card = `
@@ -46,7 +47,6 @@ function create(investment) {
4647
<div class="absolute bottom-4 right-4 inline-flex">
4748
<span
4849
class="icon-trash mr-1 text-gray-400 hover:text-gray-700 cursor-pointer"
49-
data-hs-overlay="#hs-basic-modal"
5050
>
5151
<span
5252
class="iconify"
@@ -56,7 +56,6 @@ function create(investment) {
5656
</span>
5757
<span
5858
class="icon-pencil text-gray-400 hover:text-gray-700 cursor-pointer"
59-
data-hs-overlay="#investment-drawer"
6059
>
6160
<span
6261
class="iconify"
@@ -73,14 +72,18 @@ function create(investment) {
7372
$(`#investment-${investment.id} .icon-pencil`).onclick = () => {
7473
InvestmentForm.setValues(investment);
7574

76-
InvestmentForm.handleSubmit((investment) => Investments.update(investment));
75+
InvestmentForm.handleSubmit(Investments.update);
76+
77+
HSOverlay.open('#investment-drawer');
7778
};
7879

7980
$(`#investment-${investment.id} .icon-trash`).onclick = () => {
8081
$(`.modal .investment-name`).innerText = investment.name;
8182

8283
$(`.modal .remove-investment-btn`).onclick = () =>
8384
Investments.remove(investment);
85+
86+
HSOverlay.open('#hs-basic-modal');
8487
};
8588
}
8689

public/codes/package/axios/invest-app/js/lib/investments.js

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,15 @@ async function create(investment) {
1818
async function update(investment) {
1919
const { id } = investment;
2020

21-
const updatedInvestment = await Storage.update(
22-
`investments?id=eq.${id}`,
23-
investment
24-
);
21+
const updatedInvestment = await Storage.update('investments', id, investment);
2522

2623
InvestmentCard.update(updatedInvestment);
2724
}
2825

2926
async function remove(investment) {
3027
const { id } = investment;
3128

32-
Storage.remove(`investments?id=eq.${id}`);
29+
Storage.remove('investments', id);
3330

3431
InvestmentCard.remove(id);
3532
}

public/codes/package/axios/invest-app/js/services/storage.js

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,27 @@ async function create(resource, data) {
66
return createdData?.[0];
77
}
88

9-
async function read(resource) {
9+
async function read(resource, id) {
10+
if (id) {
11+
resource = `${resource}?id=eq.${id}`;
12+
}
13+
1014
const { data } = await API.get(resource);
1115

1216
return data;
1317
}
1418

15-
async function update(resource, data) {
19+
async function update(resource, id, data) {
20+
resource = `${resource}?id=eq.${id}`;
21+
1622
const { data: updatedData } = await API.patch(resource, data);
1723

1824
return updatedData?.[0];
1925
}
2026

21-
async function remove(resource) {
27+
async function remove(resource, id) {
28+
resource = `${resource}?id=eq.${id}`;
29+
2230
const { error } = await API.delete(resource);
2331

2432
if (error) {

0 commit comments

Comments
 (0)