Skip to content

Commit c5d71fb

Browse files
author
Luke Schierer
committed
mayor table loads, and is formatted somewhat reasonably considering the options I forgot
1 parent dcfc328 commit c5d71fb

File tree

3 files changed

+20
-16
lines changed

3 files changed

+20
-16
lines changed

packages/web/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
<top-nav></top-nav>
1919
</sp-theme>
2020
<main>
21-
<mayor-table CvsName='./public/CSVs/attack_mayors.csv'></mayor-table>
21+
<mayor-table csv="attack_mayors.csv"></mayor-table>
2222
</main>
2323

2424
<script type="module" src="./lib/index.js"></script>

packages/web/lib/components/mayor_table.ts

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import { PropertyValues } from "lit/development";
1616
@customElement("mayor-table")
1717
export class MayorTable extends Table {
1818

19-
@property({type: String, reflect: true})
19+
@property({type: String, reflect: true, attribute: "csv"})
2020
public CsvName: string;
2121

2222
@state()
@@ -65,26 +65,29 @@ export class MayorTable extends Table {
6565
protected async getMayors() {
6666
console.log('fetching mayors');
6767
if (this.fetchingMayors) {
68-
console.log('already done')
68+
console.log('already done');
6969
return;
70-
} else{
70+
} else {
7171
this.fetchingMayors = true;
7272
fetch(this.CsvUrl)
73-
.then((response) => response.text())
74-
.then((t) => {
75-
const r = dsv.csvParse(t);
76-
const c = r.columns;
77-
this._ids = JSON.parse(JSON.stringify(c));
78-
console.log(`items are ${JSON.stringify(r)}`);
79-
console.log(`ids are ${this._ids}`);
80-
this._items = r;
81-
}).then(() =>{
82-
this.fetchMayorsComplete = true;
83-
return true;
84-
});
73+
.then((response) => {
74+
if (response.ok) return response.text();
75+
else throw new Error('Status code error :' + response.status);
76+
}).then((t) => {
77+
const r = dsv.csvParse(t);
78+
const c = r.columns;
79+
this._ids = JSON.parse(JSON.stringify(c));
80+
console.log(`items are ${JSON.stringify(r)}`);
81+
console.log(`ids are ${this._ids}`);
82+
this._items = r;
83+
}).then(() => {
84+
this.fetchMayorsComplete = true;
85+
return true;
86+
}).catch((error) => console.log(error));
8587
}
8688
}
8789

90+
8891
private async initTable() {
8992
console.log('in the initTable function');
9093

packages/web/tsconfig.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
"lib": ["es2017", "dom", "dom.iterable"],
88
"strict": true,
99
"esModuleInterop": false,
10+
"useDefineForClassFields": false,
1011
"allowSyntheticDefaultImports": true,
1112
"experimentalDecorators": true,
1213
"importHelpers": true,

0 commit comments

Comments
 (0)