Skip to content

Commit

Permalink
fix link-type templates
Browse files Browse the repository at this point in the history
  • Loading branch information
c12i committed May 29, 2024
1 parent 81a607e commit 36e9780
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ const {{pascal_case entry_type.name}}Detail: FC<{{pascal_case entry_type.name}}D
fn_name: 'delete_{{snake_case entry_type.name}}',
payload: {{camel_case entry_type.name}}Hash,
});
on{{pascal_case entry_type.name}}Deleted({{camel_case entry_type.name}}Hash)
on{{pascal_case entry_type.name}}Deleted && on{{pascal_case entry_type.name}}Deleted({{camel_case entry_type.name}}Hash)
} catch (e) {
setError(e as HolochainError)
} finally {
Expand Down Expand Up @@ -134,7 +134,7 @@ const {{pascal_case entry_type.name}}Detail: FC<{{pascal_case entry_type.name}}D

interface {{pascal_case entry_type.name}}DetailProps {
{{camel_case entry_type.name}}Hash: Uint8Array
on{{pascal_case entry_type.name}}Deleted: ({{camel_case entry_type.name}}Hash: Uint8Array) => void
on{{pascal_case entry_type.name}}Deleted?: ({{camel_case entry_type.name}}Hash: Uint8Array) => void
}

export default {{pascal_case entry_type.name}}Detail;
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
import { FC, useCallback, useState, useEffect, useContext } from 'react';
import { Link, HolochainError, AppSignalCb } from '@holochain/client';

import {{pascal_case ../entry_type.name}}Detail from './{{pascal_case ../entry_type.name}}Detail';
import {{pascal_case from_referenceable.name}}Detail from './{{pascal_case from_referenceable.name}}Detail';
import type { {{pascal_case ../coordinator_zome_manifest.name}}Signal } from './types';
import { HolochainContext } from '../../contexts/HolochainContext';

const {{pascal_case (plural ../entry_type.name)}}For{{pascal_case linked_from.name}}: FC<{{pascal_case (plural ../entry_type.name)}}For{{pascal_case linked_from.name}}Props> = ({{{camel_case linked_from.singular_arg}}}) => {
const {{pascal_case (plural from_referenceable.name)}}For{{pascal_case to_referenceable.name}}: FC<{{pascal_case (plural from_referenceable.name)}}For{{pascal_case to_referenceable.name}}Props> = ({ {{camel_case to_referenceable.singular_arg}} }) => {
const {client} = useContext(HolochainContext);
const [hashes, setHashes] = useState<Uint8Array[]>([]);
const [loading, setLoading] = useState(false);
const [error, setError] = useState<HolochainError | undefined>();

const fetch{{pascal_case (plural ../entry_type.name)}} = useCallback(async () => {
const fetch{{pascal_case (plural from_referenceable.name)}} = useCallback(async () => {
setLoading(true)
try {
const links: Link[] = await client?.callZome({
cap_secret: null,
role_name: '{{../dna_role_name}}',
zome_name: '{{../coordinator_zome_manifest.name}}',
fn_name: 'get_{{snake_case (plural ../entry_type.name)}}_for_{{snake_case linked_from.name}}',
payload: {{camel_case linked_from.singular_arg}}
role_name: '{{dna_role_name}}',
zome_name: '{{snake_case coordinator_zome_manifest.name}}',
fn_name: 'get_{{snake_case (plural from_referenceable.name)}}_for_{{snake_case to_referenceable.name}}',
payload: {{camel_case to_referenceable.singular_arg}},
});
setHashes(links.map((l) => l.target));
} catch (e) {
Expand All @@ -30,17 +30,18 @@ const {{pascal_case (plural ../entry_type.name)}}For{{pascal_case linked_from.na
}, [client]);

useEffect(() => {
fetch{{pascal_case (plural ../entry_type.name)}}();
fetch{{pascal_case (plural from_referenceable.name)}}();

const handleSignal: AppSignalCb = async (signal) => {
if (signal.zome_name !== '{{../coordinator_zome_manifest.name}}') return;
const payload = signal.payload as {{pascal_case ../coordinator_zome_manifest.name}}Signal;
if (!(payload.type === 'EntryCreated' && payload.app_entry.type === '{{pascal_case ../entry_type.name}}')) return;
await fetch{{pascal_case (plural ../entry_type.name)}}();
if (signal.zome_name !== '{{coordinator_zome_manifest.name}}') return;
const payload = signal.payload as {{pascal_case coordinator_zome_manifest.name}}Signal;
if (payload.type !== 'LinkCreated') return;
if (payload.link_type !== '{{pascal_case bidirectional}}') return;
await fetch{{pascal_case (plural from_referenceable.name)}}();
};

client?.on('signal', handleSignal);
}, [client, fetch{{pascal_case (plural ../entry_type.name)}}]);
}, [client, fetch{{pascal_case (plural from_referenceable.name)}}]);

if (loading) {
return <div>loading...</div>;
Expand All @@ -49,22 +50,22 @@ const {{pascal_case (plural ../entry_type.name)}}For{{pascal_case linked_from.na
return (
<div>
{error ? (
<span>Error fetching the {{plural ../entry_type.name}}: {error.message}</span>
<span>Error fetching {{lower_case (plural from_referenceable.name)}}: {error.data.data}.</span>
) : hashes.length > 0 ? (
<div>
{hashes.map((hash, i) => (
<{{pascal_case ../entry_type.name}}Detail key={i} {{camel_case ../entry_type.name}}Hash={hash} on{{pascal_case ../entry_type.name}}Deleted={fetch{{pascal_case (plural ../entry_type.name)}}} />
<{{pascal_case from_referenceable.name}}Detail key={i} {{camel_case from_referenceable.name}}Hash={hash} />
))}
</div>
) : (
<span>No {{plural ../entry_type.name}} found for this {{lower_case linked_from.name}}.</span>
<span>No {{lower_case (plural from_referenceable.name)}} found for this {{lower_case to_referenceable.name}}.</span>
)}
</div>
);
};

interface {{pascal_case (plural ../entry_type.name)}}For{{pascal_case linked_from.name}}Props {
{{camel_case linked_from.singular_arg}}: Uint8Array
interface {{pascal_case (plural from_referenceable.name)}}For{{pascal_case to_referenceable.name}}Props {
{{camel_case to_referenceable.singular_arg}}: Uint8Array
}

export default {{pascal_case (plural ../entry_type.name)}}For{{pascal_case linked_from.name}};
export default {{pascal_case (plural from_referenceable.name)}}For{{pascal_case to_referenceable.name}};
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
import { FC, useCallback, useState, useEffect, useContext } from 'react';
import { Link, HolochainError, AppSignalCb } from '@holochain/client';

import {{pascal_case ../entry_type.name}}Detail from './{{pascal_case ../entry_type.name}}Detail';
import {{pascal_case to_referenceable.name}}Detail from './{{pascal_case to_referenceable.name}}Detail';
import type { {{pascal_case ../coordinator_zome_manifest.name}}Signal } from './types';
import { HolochainContext } from '../../contexts/HolochainContext';

const {{pascal_case (plural from_referenceable.name)}}For{{pascal_case to_referenceable.name}}: FC<{{pascal_case (plural ../entry_type.name)}}For{{pascal_case linked_from.name}}Props> = ({{{camel_case to_referenceable.singular_arg}}}) => {
const {{pascal_case (plural to_referenceable.name)}}For{{pascal_case from_referenceable.name}}: FC<{{pascal_case (plural to_referenceable.name)}}For{{pascal_case from_referenceable.name}}Props > = ({ {{camel_case from_referenceable.singular_arg}} }) => {
const {client} = useContext(HolochainContext);
const [hashes, setHashes] = useState<Uint8Array[]>([]);
const [loading, setLoading] = useState(false);
const [error, setError] = useState<HolochainError | undefined>();

const fetch{{pascal_case (plural from_referenceable.name)}}For{{pascal_case to_referenceable.name}} = useCallback(async () => {
const fetch{{pascal_case (plural to_referenceable.name)}} = useCallback(async () => {
setLoading(true)
try {
const links: Link[] = await client?.callZome({
cap_secret: null,
role_name: '{{dna_role_name}}',
zome_name: '{{snake_case coordinator_zome_manifest.name}}',
fn_name: 'get_{{snake_case (plural from_referenceable.name)}}_for_{{snake_case to_referenceable.name}}',
payload: {{camel_case to_referenceable.singular_arg}},
zome_name: '{{coordinator_zome_manifest.name}}',
fn_name: 'get_{{snake_case (plural to_referenceable.name)}}_for_{{snake_case from_referenceable.name}}',
payload: {{camel_case from_referenceable.singular_arg}},
});
setHashes(links.map((l) => l.target));
} catch (e) {
Expand All @@ -30,18 +30,18 @@ const {{pascal_case (plural from_referenceable.name)}}For{{pascal_case to_refere
}, [client]);

useEffect(() => {
fetch{{pascal_case (plural from_referenceable.name)}}For{{pascal_case to_referenceable.name}}();
fetch{{pascal_case (plural to_referenceable.name)}}();

const handleSignal: AppSignalCb = async (signal) => {
if (signal.zome_name !== '{{coordinator_zome_manifest.name}}') return;
const payload = signal.payload as {{pascal_case coordinator_zome_manifest.name}}Signal;
if (payload.type !== 'LinkCreated') return;
if (payload.link_type !== '{{pascal_case bidirectional}}') return;
await fetch{{pascal_case (plural from_referenceable.name)}}For{{pascal_case to_referenceable.name}}();
await fetch{{pascal_case (plural to_referenceable.name)}}();
};

client?.on('signal', handleSignal);
}, [client, fetch{{pascal_case (plural from_referenceable.name)}}For{{pascal_case to_referenceable.name}}]);
}, [client, fetch{{pascal_case (plural to_referenceable.name)}}]);

if (loading) {
return <div>loading...</div>;
Expand All @@ -50,22 +50,22 @@ const {{pascal_case (plural from_referenceable.name)}}For{{pascal_case to_refere
return (
<div>
{error ? (
<span>Error fetching {{lower_case (plural from_referenceable.name)}}: {error.message}</span>
<span>Error fetching {{lower_case (plural to_referenceable.name)}}: {error.message}</span>
) : hashes.length > 0 ? (
<div>
{hashes.map((hash, i) => (
<{{pascal_case ../entry_type.name}}Detail key={i} {{camel_case ../entry_type.name}}Hash={hash} on{{pascal_case ../entry_type.name}}Deleted={fetch{{pascal_case (plural ../entry_type.name)}}} />
<{{pascal_case to_referenceable.name}}Detail key={i} {{camel_case to_referenceable.name}}Hash={hash} />
))}
</div>
) : (
<span>No {{lower_case (plural from_referenceable.name)}} found for this {{lower_case to_referenceable.name}}.</span>
<span>No {{lower_case (plural to_referenceable.name)}} found for this {{lower_case from_referenceable.name}}.</span>
)}
</div>
);
};

interface {{pascal_case (plural from_referenceable.name)}}For{{pascal_case to_referenceable.name}}Props {
{{camel_case to_referenceable.singular_arg}}: Uint8Array
interface {{pascal_case (plural to_referenceable.name)}}For{{pascal_case from_referenceable.name}}Props {
{{camel_case from_referenceable.singular_arg}}: Uint8Array
}

export default {{pascal_case (plural from_referenceable.name)}}For{{pascal_case to_referenceable.name}};
export default {{pascal_case (plural to_referenceable.name)}}For{{pascal_case from_referenceable.name}};

0 comments on commit 36e9780

Please sign in to comment.