Skip to content

Commit

Permalink
example: reload issues in list
Browse files Browse the repository at this point in the history
The demo shows how the Models SDK can be used to show changes to the
issue data rendered in the exanded drawer. We have not integrated Models
to render changes to the list view yet. In the meantime, we simply
reload the issues for the list view from the server.
  • Loading branch information
mschristensen committed May 28, 2024
1 parent f491d9f commit 76dd3fd
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 1 deletion.
17 changes: 16 additions & 1 deletion examples/livesync/components/Project/Project.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,27 @@
'use client';

import { useEffect, useState } from 'react';
import { Drawer } from '../Drawer';
import { Table, IssueType } from '../Table';
import { fetchIssues } from './actions';

interface Props {
issues: IssueType[];
id: number;
}

export const Project = ({ issues, id }: Props) => {
export const Project = ({ issues: initialIssues, id }: Props) => {
const [issues, setIssues] = useState<IssueType[]>(initialIssues);

useEffect(() => {
async function reload() {
const newIssues = await fetchIssues(id);
setIssues(newIssues);
}

reload();
});

return (
<Drawer projectId={id}>
<Table rows={issues} />
Expand Down
27 changes: 27 additions & 0 deletions examples/livesync/components/Project/actions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
'use server';

import { sql } from '@/data';
import { IssueType } from '../Table';

export const fetchIssues = async (id: number) => {
const issues = await sql<IssueType[]>`
SELECT
i.id,
i.name,
i.due_date,
i.status,
i.owner_id,
i.story_points,
i.description,
u.first_name as owner_first_name,
u.last_name as owner_last_name,
u.color as owner_color
FROM issues i
LEFT OUTER JOIN users u
ON u.id = i.owner_id
WHERE project_id = ${id}
ORDER BY i.id DESC
`;

return Array.from(issues);
};

0 comments on commit 76dd3fd

Please sign in to comment.