refactor: move entitylisting to upend.js, dry, formatting

feat/type-attributes
Tomáš Mládek 2023-05-20 22:33:22 +02:00
parent 51ba6f8772
commit d9753018d6
6 changed files with 34 additions and 35 deletions

View File

@ -106,3 +106,17 @@ export interface StoreInfo {
paths: { added: number; valid: boolean; path: string }[];
}[];
}
export type EntityInfo =
| {
t: "Hash" | "Uuid";
}
| {
t: "Attribute" | "Url";
c: string;
};
export interface EntityListing {
entity: EntityInfo;
entries: ListingResult;
}

View File

@ -1,6 +1,6 @@
<script lang="ts">
import browser from "webextension-polyfill";
import type { VaultInfo } from "upend/types";
import type { EntityListing, VaultInfo } from "upend/types";
import { cleanInstanceUrl, instanceUrlStore } from "./common";
import { onMount } from "svelte";
import "./main.scss";
@ -55,25 +55,24 @@
}
async function openAsUrl() {
opening = true;
try {
const address = (await (
await fetch(`${$cleanInstanceUrl}/api/address?url=${currentUrl}`)
).json()) as string;
visit(address);
} catch (err) {
openError = processError(err);
}
open("url");
}
async function openContent() {
open("url_content");
}
async function open(key: string) {
opening = true;
try {
const address = (await (
await fetch(
`${$cleanInstanceUrl}/api/address?url_content=${currentUrl}`
)
await fetch(`${$cleanInstanceUrl}/api/address?${key}=${currentUrl}`)
).json()) as string;
// const obj = (await (
// await fetch(`${$cleanInstanceUrl}/api/obj/${address}`)
// ).json()) as EntityListing;
visit(address);
} catch (err) {
openError = processError(err);
@ -89,7 +88,6 @@
$: primaryActionLabel = primaryAction ? primaryAction[0] : "...";
function performPrimaryAction() {
console.log({ primaryAction });
primaryAction[1]();
}

View File

@ -4,7 +4,6 @@
import HashBadge from "./HashBadge.svelte";
import Ellipsis from "../utils/Ellipsis.svelte";
import UpLink from "./UpLink.svelte";
import { useEntity, type EntityInfo } from "../../lib/entity";
import { API_URL, nativeOpen as nativeOpenApi } from "../../lib/api";
import { readable, type Readable } from "svelte/store";
import { notify, UpNotification } from "../../notifications";
@ -13,6 +12,8 @@
import type { BrowseContext } from "../../util/browse";
import type { UpObject } from "upend";
import { i18n } from "../../i18n";
import type { EntityInfo } from "upend/types";
import { useEntity } from "src/lib/entity";
const dispatch = createEventDispatcher();
export let address: string;
@ -174,8 +175,8 @@
}
.type {
font-size: .66em;
opacity: .7;
font-size: 0.66em;
opacity: 0.7;
}
}

View File

@ -1,24 +1,10 @@
// import { useSWR } from "sswr";
import { derived, type Readable } from "svelte/store";
import { UpListing, UpObject } from "upend";
import type { ListingResult } from "upend/types";
import type { ListingResult, EntityListing, EntityInfo } from "upend/types";
import { useSWR } from "../util/fetch";
import { API_URL } from "./api";
export type EntityInfo =
| {
t: "Hash" | "Uuid";
}
| {
t: "Attribute" | "Url";
c: string;
};
export interface EntityListing {
entity: EntityInfo;
entries: ListingResult;
}
export function useEntity(address: string) {
const { data, error, revalidate } = useSWR<EntityListing, unknown>(
`${API_URL}/obj/${address}`

View File

@ -1,4 +1,4 @@
import type { EntityInfo } from "src/lib/entity";
import type { EntityInfo } from "upend/types";
import type { UpObject } from "upend";
import { GROUP_TYPE_ADDR } from "upend/constants";

View File

@ -12560,8 +12560,8 @@ __metadata:
"upend@file:../tools/upend_js::locator=upend-kestrel%40workspace%3A.":
version: 0.0.1
resolution: "upend@file:../tools/upend_js#../tools/upend_js::hash=4c6736&locator=upend-kestrel%40workspace%3A."
checksum: 65175c69f6281820b0b6072a3c2e3d7c4705b7f158f68d9934dfe091b0da5c21ad02f01b5c90469196486b7cc7929bd3cf993b03b58b9f21b7527abcd7fedcf6
resolution: "upend@file:../tools/upend_js#../tools/upend_js::hash=9eb5fd&locator=upend-kestrel%40workspace%3A."
checksum: 03e1fe88abd8f6963e450e820c3d8a0b231aebdbe8e18c04d212adb6f3c3b820bf805705a9cc5d9643667257b94cd2c0a7a723fe547965f50496eaccb0b6e9e9
languageName: node
linkType: hard