Pubkey filter for event log.
This commit is contained in:
@@ -8,6 +8,12 @@
|
||||
<script defer src="event_log.build.js"></script>
|
||||
<link rel="stylesheet" href="options.build.css">
|
||||
<title>Event Log</title>
|
||||
|
||||
<style>
|
||||
label {
|
||||
display: block;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
|
||||
<body class="text-fuchsia-900 p-3.5 lg:p-32" x-data="eventLog">
|
||||
@@ -20,7 +26,7 @@
|
||||
<div class="section">
|
||||
<div class="section-header">Filters</div>
|
||||
|
||||
<div class="grid grid-cols-2 lg:grid-cols-4 gap-4">
|
||||
<div class="grid grid-cols-2 xl:grid-cols-4 gap-4">
|
||||
<div>
|
||||
<label for="view">View</label>
|
||||
<select id="view" class="input" x-model="view" @change="reload">
|
||||
@@ -81,6 +87,21 @@
|
||||
</template>
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<div x-show="view === 'pubkey'">
|
||||
<label for="profiles">Profiles</label>
|
||||
<select id="profiles" class="input" x-model="profile" @change="pkFromProfile">
|
||||
<option value=""></option>
|
||||
<template x-for="p in profileNames">
|
||||
<option :value="p" x-text="p"></option>
|
||||
</template>
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<div x-show="view === 'pubkey'">
|
||||
<label for="pubkey">Pubkey</label>
|
||||
<input type="text" class="input" x-model="pubkey" @input.debounce="reload">
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import Alpine from 'alpinejs';
|
||||
import { getPublicKey } from 'nostr-tools';
|
||||
import { getHosts, sortByIndex } from './db';
|
||||
import { KINDS } from './utils';
|
||||
import { getProfiles, KINDS } from './utils';
|
||||
|
||||
Alpine.data('eventLog', () => ({
|
||||
kinds: KINDS,
|
||||
@@ -10,6 +11,9 @@ Alpine.data('eventLog', () => ({
|
||||
sort: 'asc',
|
||||
allHosts: [],
|
||||
host: '',
|
||||
allProfiles: [],
|
||||
profile: '',
|
||||
pubkey: '',
|
||||
|
||||
// date view
|
||||
fromCreatedAt: '2008-10-31',
|
||||
@@ -33,6 +37,12 @@ Alpine.data('eventLog', () => ({
|
||||
);
|
||||
this.events = events;
|
||||
getHosts().then(hosts => (this.allHosts = hosts));
|
||||
const profiles = await getProfiles();
|
||||
console.log(profiles);
|
||||
this.allProfiles = profiles.map(profile => ({
|
||||
name: profile.name,
|
||||
pubkey: getPublicKey(profile.privKey),
|
||||
}));
|
||||
},
|
||||
|
||||
quickKindSelect() {
|
||||
@@ -43,6 +53,13 @@ Alpine.data('eventLog', () => ({
|
||||
this.reload();
|
||||
},
|
||||
|
||||
pkFromProfile() {
|
||||
this.pubkey = this.allProfiles.find(
|
||||
({ name }) => name === this.profile
|
||||
).pubkey;
|
||||
this.reload();
|
||||
},
|
||||
|
||||
// Properties
|
||||
|
||||
get fromTime() {
|
||||
@@ -55,6 +72,10 @@ Alpine.data('eventLog', () => ({
|
||||
return Math.floor(dt.getTime() / 1000);
|
||||
},
|
||||
|
||||
get profileNames() {
|
||||
return this.allProfiles.map(p => p.name);
|
||||
},
|
||||
|
||||
get keyRange() {
|
||||
switch (this.view) {
|
||||
case 'created_at':
|
||||
@@ -66,6 +87,11 @@ Alpine.data('eventLog', () => ({
|
||||
case 'host':
|
||||
if (this.host.length === 0) return null;
|
||||
return IDBKeyRange.only(this.host);
|
||||
|
||||
case 'pubkey':
|
||||
if (this.pubkey.length === 0) return null;
|
||||
return IDBKeyRange.only(this.pubkey);
|
||||
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user