Skip to content

Commit 0ffcaa8

Browse files
committed
feat(lists): Allow updating list name
1 parent 11bf04c commit 0ffcaa8

File tree

6 files changed

+67
-26
lines changed

6 files changed

+67
-26
lines changed

apps/spuxx-client/src/features/lists/components/list-settings.component.tsx

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,19 @@
11
import { List } from '@/services/api/lists/lists.types';
22
import { intl } from '@spuxx/js-utils';
33
import { Accordion, Input } from '@spuxx/solid';
4-
import { Component, mergeProps } from 'solid-js';
4+
import { Accessor, Component, mergeProps } from 'solid-js';
55

66
interface Props {
7-
list: List;
7+
list: Accessor<List>;
8+
onUpdate: (list: List) => void;
89
}
910

1011
export const ListSettings: Component<Props> = (props) => {
1112
const p = mergeProps<[Partial<Props>, Props]>({}, props);
12-
// eslint-disable-next-line no-console
13-
console.log(p);
13+
14+
const patch = (patch: Partial<List>) => {
15+
p.onUpdate({ ...p.list(), ...patch });
16+
};
1417

1518
return (
1619
<Accordion>
@@ -21,7 +24,10 @@ export const ListSettings: Component<Props> = (props) => {
2124
<Input
2225
label={intl('lists.component.settings.name.label')}
2326
size="full"
24-
value={props.list.name}
27+
value={p.list().name}
28+
onChange={(value) => {
29+
patch({ name: value });
30+
}}
2531
/>
2632
</Accordion.Item>
2733
</Accordion>
Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,32 @@
11
import { List } from '@/services/api/lists/lists.types';
22
import { Heading, Icon } from '@spuxx/solid';
3-
import { Component } from 'solid-js';
3+
import { Component, createSignal, mergeProps } from 'solid-js';
44
import { ListItems } from './list-items.component';
55
import { ListSettings } from './list-settings.component';
6+
import { Api } from '@/services/api';
7+
import styles from './list-view.module.css';
68

79
interface Props {
810
list: List;
911
}
1012

1113
export const ListView: Component<Props> = (props) => {
14+
const p = mergeProps<[Partial<Props>, Props]>({}, props);
15+
const [list, setList] = createSignal<List>(p.list);
16+
17+
const handleUpdate = (updatedList: List) => {
18+
setList(updatedList);
19+
Api.updateList({ args: { list: list() } });
20+
};
21+
1222
return (
1323
<>
14-
<Heading level={2}>
15-
<Icon icon={props.list.icon} />
16-
{props.list.name}
24+
<Heading level={2} class={styles.heading}>
25+
<Icon icon={list().icon} />
26+
{list().name}
1727
</Heading>
18-
<ListItems list={props.list} />
19-
<ListSettings list={props.list} />
28+
<ListItems list={list()} />
29+
<ListSettings list={list} onUpdate={handleUpdate} />
2030
</>
2131
);
2232
};
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
.heading {
2+
display: flex;
3+
align-items: center;
4+
5+
justify-content: center;
6+
margin-bottom: var(--spx-spacing-md);
7+
8+
iconify-icon {
9+
margin-right: var(--spx-spacing-sm);
10+
}
11+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
.container {
2+
width: 100%;
3+
}
4+
5+
.loader {
6+
position: absolute;
7+
top: 50%;
8+
left: 50%;
9+
transform: translate(-50%, -50%);
10+
}

apps/spuxx-client/src/features/lists/pages/list.page.tsx

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,39 @@
11
import { Api } from '@/services/api';
2-
import { List } from '@/services/api/lists/lists.types';
32
import { Params, useParams } from '@solidjs/router';
4-
import { HttpRequestStatus } from '@spuxx/js-utils';
3+
import { HttpRequest, HttpRequestStatus } from '@spuxx/js-utils';
54
import { Container, Icon } from '@spuxx/solid';
65
import { Component, createEffect, createSignal, Show } from 'solid-js';
76
import { ListView } from '../components/list-view.component';
7+
import styles from './list.module.css';
88

99
export const ListPage: Component = () => {
1010
const params = useParams<Params>();
11-
const [list, setList] = createSignal<List | null>(null);
12-
const [status, setStatus] = createSignal<HttpRequestStatus>(
13-
HttpRequestStatus.pending
14-
);
11+
12+
const [request, setRequest] = createSignal<HttpRequest | null>(null);
13+
1514
createEffect(async () => {
16-
setStatus(HttpRequestStatus.pending);
1715
const request = Api.findListById({ args: { id: params.id } });
1816
await request.promise;
19-
setStatus(request.status);
20-
setList(request.transformedResult);
17+
setRequest(request);
2118
});
2219

23-
createEffect(() => {});
20+
if (request()) return null;
2421

2522
return (
26-
<Container class="text-center m-auto w-2xl">
27-
<Show when={status() === HttpRequestStatus.pending}>
23+
<Container class={styles.container}>
24+
<Show
25+
when={!request() || request()!.status === HttpRequestStatus.pending}
26+
>
2827
{/* TODO: Move to Loader component in @spuxx/solid? */}
29-
<Icon icon="svg-spinners:ring-resize" class="text-2xl" />
28+
<Icon icon="svg-spinners:ring-resize" class={styles.loader} />
3029
</Show>
31-
<Show when={status() === HttpRequestStatus.success && list()}>
32-
<ListView list={list()!} />
30+
<Show
31+
when={
32+
request()?.status === HttpRequestStatus.success &&
33+
request()?.transformedResult
34+
}
35+
>
36+
<ListView list={request()!.transformedResult} />
3337
</Show>
3438
</Container>
3539
);

apps/spuxx-client/src/stores/current-list.store.ts

Whitespace-only changes.

0 commit comments

Comments
 (0)