Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "intuition-chrome-extension",
"displayName": "Intuition Chrome Extension",
"version": "0.1.44",
"version": "0.1.45",
"description": "",
"author": "THP-Lab.org",
"scripts": {
Expand Down
43 changes: 29 additions & 14 deletions src/components/AtomForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,22 +71,37 @@ const AtomForm = forwardRef<AtomFormHandle, AtomFormProps>(function AtomForm(
}
}, [description])

useEffect(() => {
if (!rawUrl) return;

try {
const input = /^https?:\/\//i.test(rawUrl) ? rawUrl : `https://${rawUrl}`;
const parsed = new URL(input);
useEffect(() => {
if (!rawUrl) return;

try {
const input = /^https?:\/\//i.test(rawUrl) ? rawUrl : `https://${rawUrl}`;
const parsed = new URL(input);

const hostnameWhithoutWWW = parsed.hostname.replace(/^www\./i, '');

let candidate: string;
if (linkType === "domain") {
candidate = `${parsed.protocol}//${hostnameWhithoutWWW}`;
} else {
candidate =
`${parsed.protocol}//${hostnameWhithoutWWW}` +
`${parsed.pathname}${parsed.search}${parsed.hash}`;
}

if (linkType === "domain") {
setUrl(`https://${parsed.hostname}/`);
} else {
setUrl(parsed.href);
}
} catch {
setUrl(rawUrl);
if (candidate.endsWith("/") && !candidate.match(/^https?:\/\/[^/]+\/$/)) {
candidate = candidate.slice(0, -1);
}
}, [rawUrl, linkType]);

setUrl(candidate);
} catch {
let fallback = rawUrl
.replace(/^https?:\/\/www\./i, match => match.replace(/www\./i, ""))
.replace(/\/$/, "");

setUrl(fallback);
}
}, [rawUrl, linkType]);


async function handleSubmit(e: React.FormEvent) {
Expand Down
34 changes: 20 additions & 14 deletions src/graphql/src/generated/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11205,7 +11205,7 @@ export type GetClaimsByAddressQuery = {
}

export type GetClaimsByUriQueryVariables = Exact<{
uri?: InputMaybe<Scalars["String"]["input"]>
uriRegex?: InputMaybe<Scalars["String"]["input"]>
address?: InputMaybe<Scalars["String"]["input"]>
}>

Expand Down Expand Up @@ -15335,9 +15335,9 @@ useGetClaimsByAddressQuery.fetcher = (
)

export const GetClaimsByUriDocument = `
query GetClaimsByUri($uri: String, $address: String) {
query GetClaimsByUri($uriRegex: String, $address: String) {
atoms(
where: {_or: [{data: {_eq: $uri}}, {value: {thing: {url: {_eq: $uri}}}}, {value: {person: {url: {_eq: $uri}}}}, {value: {organization: {url: {_eq: $uri}}}}, {value: {book: {url: {_eq: $uri}}}}]}
where: {_or: [{data: {_iregex: $uriRegex}}, {value: {thing: {url: {_iregex: $uriRegex}}}}, {value: {person: {url: {_iregex: $uriRegex}}}}, {value: {organization: {url: {_iregex: $uriRegex}}}}, {value: {book: {url: {_iregex: $uriRegex}}}}]}
) {
as_object_claims_aggregate {
aggregate {
Expand Down Expand Up @@ -25906,7 +25906,10 @@ export const GetClaimsByUri = {
variableDefinitions: [
{
kind: "VariableDefinition",
variable: { kind: "Variable", name: { kind: "Name", value: "uri" } },
variable: {
kind: "Variable",
name: { kind: "Name", value: "uriRegex" }
},
type: { kind: "NamedType", name: { kind: "Name", value: "String" } }
},
{
Expand Down Expand Up @@ -25948,10 +25951,13 @@ export const GetClaimsByUri = {
fields: [
{
kind: "ObjectField",
name: { kind: "Name", value: "_eq" },
name: { kind: "Name", value: "_iregex" },
value: {
kind: "Variable",
name: { kind: "Name", value: "uri" }
name: {
kind: "Name",
value: "uriRegex"
}
}
}
]
Expand Down Expand Up @@ -25987,13 +25993,13 @@ export const GetClaimsByUri = {
kind: "ObjectField",
name: {
kind: "Name",
value: "_eq"
value: "_iregex"
},
value: {
kind: "Variable",
name: {
kind: "Name",
value: "uri"
value: "uriRegex"
}
}
}
Expand Down Expand Up @@ -26036,13 +26042,13 @@ export const GetClaimsByUri = {
kind: "ObjectField",
name: {
kind: "Name",
value: "_eq"
value: "_iregex"
},
value: {
kind: "Variable",
name: {
kind: "Name",
value: "uri"
value: "uriRegex"
}
}
}
Expand Down Expand Up @@ -26088,13 +26094,13 @@ export const GetClaimsByUri = {
kind: "ObjectField",
name: {
kind: "Name",
value: "_eq"
value: "_iregex"
},
value: {
kind: "Variable",
name: {
kind: "Name",
value: "uri"
value: "uriRegex"
}
}
}
Expand Down Expand Up @@ -26137,13 +26143,13 @@ export const GetClaimsByUri = {
kind: "ObjectField",
name: {
kind: "Name",
value: "_eq"
value: "_iregex"
},
value: {
kind: "Variable",
name: {
kind: "Name",
value: "uri"
value: "uriRegex"
}
}
}
Expand Down
32 changes: 19 additions & 13 deletions src/graphql/src/generated/subscriptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11225,7 +11225,7 @@ export type GetClaimsByAddressQuery = {
}

export type GetClaimsByUriQueryVariables = Exact<{
uri?: InputMaybe<Scalars["String"]["input"]>
uriRegex?: InputMaybe<Scalars["String"]["input"]>
address?: InputMaybe<Scalars["String"]["input"]>
}>

Expand Down Expand Up @@ -21535,7 +21535,10 @@ export const GetClaimsByUriDocument = {
variableDefinitions: [
{
kind: "VariableDefinition",
variable: { kind: "Variable", name: { kind: "Name", value: "uri" } },
variable: {
kind: "Variable",
name: { kind: "Name", value: "uriRegex" }
},
type: { kind: "NamedType", name: { kind: "Name", value: "String" } }
},
{
Expand Down Expand Up @@ -21577,10 +21580,13 @@ export const GetClaimsByUriDocument = {
fields: [
{
kind: "ObjectField",
name: { kind: "Name", value: "_eq" },
name: { kind: "Name", value: "_iregex" },
value: {
kind: "Variable",
name: { kind: "Name", value: "uri" }
name: {
kind: "Name",
value: "uriRegex"
}
}
}
]
Expand Down Expand Up @@ -21616,13 +21622,13 @@ export const GetClaimsByUriDocument = {
kind: "ObjectField",
name: {
kind: "Name",
value: "_eq"
value: "_iregex"
},
value: {
kind: "Variable",
name: {
kind: "Name",
value: "uri"
value: "uriRegex"
}
}
}
Expand Down Expand Up @@ -21665,13 +21671,13 @@ export const GetClaimsByUriDocument = {
kind: "ObjectField",
name: {
kind: "Name",
value: "_eq"
value: "_iregex"
},
value: {
kind: "Variable",
name: {
kind: "Name",
value: "uri"
value: "uriRegex"
}
}
}
Expand Down Expand Up @@ -21717,13 +21723,13 @@ export const GetClaimsByUriDocument = {
kind: "ObjectField",
name: {
kind: "Name",
value: "_eq"
value: "_iregex"
},
value: {
kind: "Variable",
name: {
kind: "Name",
value: "uri"
value: "uriRegex"
}
}
}
Expand Down Expand Up @@ -21766,13 +21772,13 @@ export const GetClaimsByUriDocument = {
kind: "ObjectField",
name: {
kind: "Name",
value: "_eq"
value: "_iregex"
},
value: {
kind: "Variable",
name: {
kind: "Name",
value: "uri"
value: "uriRegex"
}
}
}
Expand Down Expand Up @@ -22552,7 +22558,7 @@ export const GetClaimsByUriDocument = {
* @example
* const { data, loading, error } = useGetClaimsByUriQuery({
* variables: {
* uri: // value for 'uri'
* uriRegex: // value for 'uriRegex'
* address: // value for 'address'
* },
* });
Expand Down
12 changes: 6 additions & 6 deletions src/graphql/src/queries/claims.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,15 @@ query GetClaimsByAddress($address: String) {
}
}

query GetClaimsByUri($uri: String, $address: String) {
query GetClaimsByUri($uriRegex: String, $address: String) {
atoms(
where: {
_or: [
{ data: { _eq: $uri } }
{ value: { thing: { url: { _eq: $uri } } } }
{ value: { person: { url: { _eq: $uri } } } }
{ value: { organization: { url: { _eq: $uri } } } }
{ value: { book: { url: { _eq: $uri } } } }
{ data: { _iregex: $uriRegex } }
{ value: { thing: { url: { _iregex: $uriRegex } } } }
{ value: { person: { url: { _iregex: $uriRegex } } } }
{ value: { organization: { url: { _iregex: $uriRegex } } } }
{ value: { book: { url: { _iregex: $uriRegex } } } }
]
}
) {
Expand Down
59 changes: 50 additions & 9 deletions src/pages/Home.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,34 @@ import ClaimRowLite from "~src/components/ui/ClaimRowLite";
import AtomCard from "~src/components/AtomCard";
import EyeComponent from "~/src/components/3D/EyeComponent"

function normalizeUrl(input: string): string {
try {
const u = new URL(input)
let hostname = u.hostname.toLowerCase()
if (hostname.startsWith("www.")) hostname = hostname.slice(4)
let pathname = u.pathname
if (pathname.endsWith("/") && pathname.length > 1) {
pathname = pathname.slice(0, -1)
}
return `https://${hostname}${pathname}${u.search}${u.hash}`
} catch {
return input
}
}

function buildUriRegex(rawUrl: string): string {
const canonical = normalizeUrl(rawUrl)
let withoutProto = canonical.replace(/^https?:\/\//, "")

if (withoutProto.endsWith("/")) {
withoutProto = withoutProto.slice(0, -1)
}
const escaped = withoutProto.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")

return `^https?:\\/\\/(?:www\\.)?${escaped}\\/?$`
}


function Home() {
const { theme } = useTheme()
const [currentUrl, setCurrentUrl] = useState<string>("")
Expand All @@ -25,21 +53,34 @@ function Home() {
console.log(tab.url)
return tab.url
}

const refreshUrl = () => {
getCurrentUrl().then((url) => setCurrentUrl(url || ""))
}
useEffect(() => {
refreshUrl()
chrome.tabs.onUpdated.addListener(() => {
refreshUrl()
getCurrentUrl().then((url) => {
if (url) {
setCurrentUrl(normalizeUrl(url))
} else {
setCurrentUrl("")
}
})
}

chrome.tabs.onActivated.addListener(() => {
refreshUrl()
useEffect(() => {
getCurrentUrl().then((url) => {
if (url) setCurrentUrl(normalizeUrl(url))
})
chrome.tabs.onUpdated.addListener(refreshUrl)
chrome.tabs.onActivated.addListener(refreshUrl)
return () => {
chrome.tabs.onUpdated.removeListener(refreshUrl)
chrome.tabs.onActivated.removeListener(refreshUrl)
}
}, [])

const { data, isLoading, error } = useGetClaimsByUriQuery({uri: currentUrl, address: walletAddress })
const uriRegex = buildUriRegex(currentUrl)
console.log("normalized URL:", currentUrl)
console.log("uriRegex:", uriRegex)

const { data, isLoading, error } = useGetClaimsByUriQuery({uriRegex, address: walletAddress })
const atoms = data?.atoms ?? []
console.log("current wallet address:", walletAddress);
console.log("Data :", data)
Expand Down