Skip to content

Commit 972feee

Browse files
authored
feat: zettel references (#87)
* feat: zettel references input * feat: add references page
1 parent 9c625e6 commit 972feee

19 files changed

+1496
-1109
lines changed

.husky/commit-msg

-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1 @@
1-
#!/usr/bin/env sh
2-
. "$(dirname -- "$0")/_/husky.sh"
3-
41
pnpm commitlint --edit

.husky/pre-commit

-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
#!/usr/bin/env sh
2-
. "$(dirname -- "$0")/_/husky.sh"
3-
41
pnpm syncpack:list
52
pnpm lint-staged
63
pnpm run build-graph

.ncurc.js

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
11
module.exports = {
2-
reject: ['next', 'typescript'],
2+
reject: [
3+
/**
4+
* https://github.com/vercel/next.js/issues/61116
5+
*/
6+
'next',
7+
'typescript',
8+
],
39
};

apps/tereza/.env.Production

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
NEXT_PUBLIC_ENVIRONMENT=Production
12
NEXT_PUBLIC_USER_POOL_ID=us-east-1_VTH2qhNx4
23
NEXT_PUBLIC_APP_CLIENT_ID=3e01h8f1qtdoinbdebqv69j949
34
NEXT_PUBLIC_REGION=us-east-1

apps/tereza/.env.Staging

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
NEXT_PUBLIC_ENVIRONMENT=Staging
12
NEXT_PUBLIC_USER_POOL_ID=us-east-2_xa2k7Tam6
23
NEXT_PUBLIC_APP_CLIENT_ID=76cflrh2rrh1u7lh923eg1i9ia
34
NEXT_PUBLIC_REGION=us-east-2

apps/tereza/package.json

+11-7
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,17 @@
1414
},
1515
"dependencies": {
1616
"@aws-amplify/adapter-nextjs": "^1.0.13",
17+
"@emotion/react": "^11.11.3",
1718
"@tereza-tech/components": "workspace:^",
18-
"@ttoss/forms": "^0.21.9",
19-
"@ttoss/react-auth": "^1.7.25",
20-
"@ttoss/react-i18n": "^1.25.8",
21-
"@ttoss/react-notifications": "^1.24.24",
19+
"@ttoss/components": "^1.30.1",
20+
"@ttoss/forms": "^0.22.1",
21+
"@ttoss/react-auth": "^1.7.27",
22+
"@ttoss/react-hooks": "^1.25.2",
23+
"@ttoss/react-i18n": "^1.26.0",
24+
"@ttoss/react-icons": "^0.3.0",
25+
"@ttoss/react-notifications": "^1.24.25",
2226
"@ttoss/relay-amplify": "^0.5.5",
23-
"@ttoss/ui": "^4.0.7",
27+
"@ttoss/ui": "^4.1.0",
2428
"aws-amplify": "^6.0.13",
2529
"date-fns": "^3.3.1",
2630
"next": "14.0.4",
@@ -33,8 +37,8 @@
3337
"devDependencies": {
3438
"@ttoss/config": "^1.31.4",
3539
"@ttoss/i18n-cli": "^0.7.5",
36-
"@types/node": "^20.11.10",
37-
"@types/react": "^18.2.48",
40+
"@types/node": "^20.11.16",
41+
"@types/react": "^18.2.52",
3842
"@types/react-dom": "^18.2.18",
3943
"babel-plugin-relay": "^16.2.0",
4044
"graphql": "^16.8.1",

apps/tereza/schema/schema.graphql

+49
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,10 @@ enum SortConnectionJournalHistoryEnum {
6363
NEWEST
6464
}
6565

66+
enum SortConnectionReferenceEnum {
67+
CREATED_AT_DESC
68+
}
69+
6670
enum SortConnectionZettelNoteEnum {
6771
CREATED_AT_DESC
6872
}
@@ -237,6 +241,22 @@ type QueryJournal {
237241
}
238242

239243
type QueryZettel {
244+
references(
245+
"""Forward pagination argument for returning at most first edges"""
246+
first: Int
247+
248+
"""Forward pagination argument for returning at most first edges"""
249+
after: String
250+
251+
"""Backward pagination argument for returning at most last edges"""
252+
last: Int
253+
254+
"""Backward pagination argument for returning at most last edges"""
255+
before: String
256+
257+
"""Sort argument for data ordering"""
258+
sort: SortConnectionReferenceEnum = CREATED_AT_DESC
259+
): ReferenceConnection
240260
insights(content: String!): ZettelInsight!
241261
note(id: ID!): ZettelNote
242262
notes(
@@ -258,6 +278,33 @@ type QueryZettel {
258278
search(text: String!, limit: Int): [ZettelNote!]!
259279
}
260280

281+
type Reference {
282+
id: ID!
283+
reference: String!
284+
notes: [ZettelNote!]!
285+
}
286+
287+
"""A connection to a list of items."""
288+
type ReferenceConnection {
289+
"""Total object count."""
290+
count: Int!
291+
292+
"""Information to aid in pagination."""
293+
pageInfo: PageInfo!
294+
295+
"""Information to aid in pagination."""
296+
edges: [ReferenceEdge!]!
297+
}
298+
299+
"""An edge in a connection."""
300+
type ReferenceEdge {
301+
"""The item at the end of the edge"""
302+
node: Reference!
303+
304+
"""A cursor for use in pagination"""
305+
cursor: String!
306+
}
307+
261308
type Tag {
262309
id: ID!
263310
name: String!
@@ -282,6 +329,7 @@ type ZettelNote implements Node {
282329
embedding: [Float!]
283330
insights: [String!]
284331
division: [String!]
332+
references: [Reference!]!
285333
tags: [Tag!]!
286334
}
287335

@@ -364,4 +412,5 @@ input ZettelNoteInput {
364412
content: String
365413
insights: [String!]
366414
division: [String!]
415+
references: [String!]
367416
}

apps/tereza/src/app/my/@sidebar/default.tsx

+4
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,10 @@ const LINKS: {
4747
href: '/my/zettel/new',
4848
label: 'New',
4949
},
50+
{
51+
href: '/my/zettel/references',
52+
label: 'References',
53+
},
5054
{
5155
href: '/my/zettel/all',
5256
label: 'All',

apps/tereza/src/app/my/zettel/ZettelHome.tsx

+48-20
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,29 @@
11
'use client';
22

33
import * as React from 'react';
4-
import { Input, Stack } from '@ttoss/ui';
54
import {
65
type PreloadedQuery,
76
graphql,
87
usePreloadedQuery,
98
useQueryLoader,
109
} from 'react-relay';
10+
import { Search } from '@ttoss/components';
1111
import {
1212
SerializablePreloadedQuery,
1313
useSerializablePreloadedQuery,
1414
} from 'src/relay/useSerializablePreloadedQuery';
15+
import { Stack } from '@ttoss/ui';
1516
import { ZettelHomeSearchQuery } from './__generated__/ZettelHomeSearchQuery.graphql';
1617
import Link from 'next/link';
1718
import ZettelHomeQueryNode, {
1819
ZettelHomeQuery,
1920
} from './__generated__/ZettelHomeQuery.graphql';
2021

22+
type SearchResult = {
23+
id: string;
24+
title?: string | null;
25+
};
26+
2127
const zettelHomeSearchQuery = graphql`
2228
query ZettelHomeSearchQuery($searchText: String!) {
2329
zettel {
@@ -29,7 +35,22 @@ const zettelHomeSearchQuery = graphql`
2935
}
3036
`;
3137

32-
const SearchResults = ({
38+
const SearchResults = ({ results = [] }: { results?: SearchResult[] }) => {
39+
return (
40+
<>
41+
{results?.map((result) => {
42+
const href = `/my/zettel/${result?.id}`;
43+
return (
44+
<Link key={result?.id} href={href}>
45+
{result?.title || '(No title)'}
46+
</Link>
47+
);
48+
})}
49+
</>
50+
);
51+
};
52+
53+
const HandleSearch = ({
3354
searchQueryRef,
3455
}: {
3556
searchQueryRef: PreloadedQuery<ZettelHomeSearchQuery>;
@@ -39,7 +60,9 @@ const SearchResults = ({
3960
searchQueryRef
4061
);
4162

42-
return <pre>{JSON.stringify(data.zettel?.search, null, 2)}</pre>;
63+
const results = [...(data.zettel?.search || [])];
64+
65+
return <SearchResults results={results} />;
4366
};
4467

4568
export const ZettelHome = ({
@@ -73,40 +96,45 @@ export const ZettelHome = ({
7396
queryRef
7497
);
7598

76-
const notes = data.zettel?.notes?.edges?.map((edge) => {
77-
return { ...edge?.node, title: edge?.node?.title || '(No title)' };
78-
});
99+
const defaultResults =
100+
data.zettel?.notes?.edges.map((edge) => {
101+
return edge?.node;
102+
}) || [];
79103

80-
const [searchText, setSearchText] = React.useState<string>('');
104+
const [searchText, setSearchText] = React.useState<string | undefined>('');
81105

82106
const [searchQueryRef, search, disposeSearchQuery] =
83107
useQueryLoader<ZettelHomeSearchQuery>(zettelHomeSearchQuery);
84108

109+
const [isPending, startTransition] = React.useTransition();
110+
85111
React.useEffect(() => {
86112
if (searchText) {
87-
search({ searchText });
113+
startTransition(() => {
114+
search({ searchText });
115+
});
88116
}
89117

90118
return disposeSearchQuery;
91119
}, [disposeSearchQuery, search, searchText]);
92120

93121
return (
94122
<Stack>
95-
<Input
123+
<Search
124+
sx={{
125+
marginBottom: 'lg',
126+
}}
96127
value={searchText}
97-
onChange={(e) => {
98-
setSearchText(e.target.value);
128+
onChange={(newSearchText) => {
129+
setSearchText(newSearchText as string);
99130
}}
131+
loading={isPending}
100132
/>
101-
{searchQueryRef && <SearchResults searchQueryRef={searchQueryRef} />}
102-
{notes?.map((note) => {
103-
const href = `/my/zettel/${note?.id}`;
104-
return (
105-
<Link key={note?.id} href={href}>
106-
{note?.title}
107-
</Link>
108-
);
109-
})}
133+
{searchQueryRef ? (
134+
<HandleSearch searchQueryRef={searchQueryRef} />
135+
) : (
136+
<SearchResults results={defaultResults} />
137+
)}
110138
</Stack>
111139
);
112140
};

apps/tereza/src/app/my/zettel/[id]/editor/ZettelEditor.tsx

+6
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@ export const ZettelEditor = ({
4646
}
4747
insights
4848
division
49+
references {
50+
reference
51+
}
4952
}
5053
`,
5154
query.zettel?.note
@@ -61,6 +64,9 @@ export const ZettelEditor = ({
6164
}),
6265
insights: [...(data?.insights ?? [])],
6366
division: [...(data?.division ?? [])],
67+
references: (data?.references ?? []).map((reference) => {
68+
return reference.reference;
69+
}),
6470
};
6571

6672
return <ZettelNoteForm note={note} />;

0 commit comments

Comments
 (0)