Skip to content

Commit

Permalink
Add the Ability to remove websites
Browse files Browse the repository at this point in the history
  • Loading branch information
strseb committed Aug 21, 2024
1 parent 771ed42 commit 21c9725
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 4 deletions.
3 changes: 3 additions & 0 deletions src/assets/img/delete-gray.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 6 additions & 0 deletions src/ui/settingsPage/settingsPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,16 @@ export class SettingsPage extends LitElement {
<mz-context-table
.contexts=${filteredList}
.serverList=${this.serverList}
.onRemoveOrigin=${this.removeOrigin.bind(this)}
></mz-context-table>
</main>
`;
}
removeOrigin(origin){
this.proxyHandler.then(handler => {
handler.removeContextForOrigin(origin);
})
}

static styles = css`
${fontSizing}
Expand Down
14 changes: 10 additions & 4 deletions src/ui/settingsPage/tableElement.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,15 @@ export class ContextTable extends LitElement {
contexts: { type: Array },
sortingKey: { type: String },
sortingAcending: { type: Boolean },
onRemoveOrigin: {type: Function}
};
constructor() {
super();
this.serverList = [];
this.contexts = [];
this.sortingKey = "origin";
this.sortingAcending = true;
this.onRemoveOrigin = ()=>{};
}
sorters = {
origin: (a, b) => a.origin.localeCompare(b.origin),
Expand Down Expand Up @@ -59,7 +61,7 @@ export class ContextTable extends LitElement {
this.sortingAcending,
this.#setSorting.bind(this)
)}
${sortedList.map((c) => tableRow(c, this.serverList))}
${sortedList.map((c) => tableRow(c, this.serverList, this.onRemoveOrigin))}
</table>
${noElementPlaceHolder(this.contexts)}
</div>
Expand Down Expand Up @@ -239,12 +241,13 @@ export const tableHeading = (
Location
</button>
</th>
<th></th>
</tr>
`;
};

export const noElementPlaceHolder = (contexts = new Map()) => {
if (contexts.size != 0) {
export const noElementPlaceHolder = (contexts = []) => {
if (contexts.length != 0) {
return null;
}
return html`
Expand All @@ -262,7 +265,7 @@ export const noElementPlaceHolder = (contexts = new Map()) => {
/**
* @param {SiteContext} ctx
*/
export const tableRow = (ctx, serverList) => {
export const tableRow = (ctx, serverList, removeOrigin) => {
const name = ctx.excluded
? ""
: Utils.nameFor(ctx.countryCode, ctx.cityCode, serverList);
Expand All @@ -275,6 +278,9 @@ export const tableRow = (ctx, serverList) => {
${ctx.excluded ? "OFF" : "ON"}
</td>
<td>${name}</td>
<td class="delete">
<button class="deleteBtn" @click=${()=>{removeOrigin(ctx.origin)}}>remove</button>
</td>
</tr>
`;
};

0 comments on commit 21c9725

Please sign in to comment.