Skip to content

Commit

Permalink
Improve Navbar & CI
Browse files Browse the repository at this point in the history
  • Loading branch information
lucemans committed Dec 18, 2024
1 parent 390bd19 commit b968893
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 10 deletions.
9 changes: 8 additions & 1 deletion web/specs/example.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ test.describe.serial('item flows', () => {

await page.waitForTimeout(500);

const itemId = await page
.getByTestId('new-item-id-input')
.textContent();

const newItemIdInput = await page
.getByTestId('new-item-id-input')
.inputValue();
Expand All @@ -46,8 +50,11 @@ test.describe.serial('item flows', () => {

await page.getByRole('button', { name: 'Save' }).click();

// wait till navigated to /item/:itemId
await page.waitForURL(WEB_URL + '/item/' + itemId);

h1 = await page.locator('h1');
await expect(h1).toHaveText(DEFAULT_ITEM_NAME);
await expect(h1).toHaveText(DEFAULT_ITEM_NAME, { timeout: 5000 });
});

test('search item', async () => {
Expand Down
12 changes: 11 additions & 1 deletion web/src/api/item/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,18 @@ export const useDeleteItem = (
};

// Edit item
export const useEditItem = () => {
export const useEditItem = (
properties: UseMutationOptions<
boolean,
Error,
{
item_id: string;
data: paths['/item/{item_id}']['patch']['requestBody']['content']['application/json; charset=utf-8'];
}
>
) => {
return useMutation({
...properties,
mutationFn: async ({
item_id,
data,
Expand Down
2 changes: 1 addition & 1 deletion web/src/components/settings/nav.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@ export const SettingsNav = () => {
'Instance',
[
['/settings/search', 'Search', <LuSearch />],
['/settings/storage', 'Storage', <LuHardDrive />],
[
'/settings/intelligence',
'Intelligence',
<LuBrain />,
],
['/settings/storage', 'Storage', <LuHardDrive />],
],
],
[
Expand Down
17 changes: 10 additions & 7 deletions web/src/routes/item/$itemId/edit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {
useDeleteItem,
useEditItem,
} from '@/api/item';
import { DynamicIcon } from '@/components/DynamicIcon';
import { BaseInput } from '@/components/input/BaseInput';
import { ItemIntelligentSuggest } from '@/components/item/ItemIntelligentSuggest';
import { EditMediaGallery } from '@/components/media/EditMediaGallery';
Expand All @@ -35,7 +36,6 @@ import {
ItemUpdatePayload,
} from '@/util/item';
import { queryClient } from '@/util/query';
import { DynamicIcon } from '@/components/DynamicIcon';

const EMPTY_VALUE = '$$EMPTY$$';

Expand Down Expand Up @@ -194,7 +194,14 @@ export const Route = createFileRoute('/item/$itemId/edit')({
const { itemId } = useParams({ from: '/item/$itemId/edit' });
const { data: item } = useSuspenseQuery(getItemById(itemId));
const { data: media } = useSuspenseQuery(getItemMedia(itemId));
const { mutateAsync: editItem } = useEditItem();
const { mutateAsync: editItem } = useEditItem({
onSuccess: async (data, variables, context) => {
navigate({
to: '/item/$itemId',
params: { itemId },
});
},
});
const { data: itemFields } = useSuspenseQuery(getItemFields(itemId));
const { data: instanceSettings } = useSuspenseQuery(
getInstanceSettings()
Expand Down Expand Up @@ -267,14 +274,10 @@ export const Route = createFileRoute('/item/$itemId/edit')({
data: diff,
},
{
onSuccess: async (data, variables, context) => {
onSuccess: () => {
toast.success('Item saved', {
id: toastId,
});
navigate({
to: '/item/$itemId',
params: { itemId },
});
},
onError(error, variables, context) {
toast.error('Failed to save item', {
Expand Down

0 comments on commit b968893

Please sign in to comment.