Skip to content

Commit

Permalink
Merge branch 'main' of github.com:a-type/biscuits
Browse files Browse the repository at this point in the history
  • Loading branch information
a-type committed Sep 29, 2024
2 parents c03d035 + 8fd5bbd commit 538ca2c
Show file tree
Hide file tree
Showing 16 changed files with 2,224 additions and 3,777 deletions.
64 changes: 32 additions & 32 deletions apps/gnocchi/verdant/src/migrations/skipToV34.ts
Original file line number Diff line number Diff line change
@@ -1,39 +1,39 @@
import v34Schema, {
MigrationTypes as V34Types,
MigrationTypes as V34Types,
} from '../client/schemaVersions/v34.js';
import { createMigration } from '@verdant-web/store';
import { createMinimalGraphQLClient, graphql } from '@biscuits/client';
import { createMinimalGraphQLClient, graphql } from '@biscuits/graphql';
import { API_HOST_HTTP } from '../config.js';

export default createMigration<V34Types>(v34Schema, async ({ mutations }) => {
await mutations.collaborationInfo.put({});
try {
const client = createMinimalGraphQLClient({
origin: API_HOST_HTTP,
});
const result = await client.query({
query: graphql(`
query DefaultCategories {
foodCategories {
id
name
sortKey
}
}
`),
});
if (!result.data) {
if (result.error) throw result.error;
throw new Error('No data returned');
}
for (const defaultCategory of result.data.foodCategories) {
await mutations.categories.put({
id: defaultCategory.id.toString(),
name: defaultCategory.name,
sortKey: defaultCategory.sortKey,
});
}
} catch (error) {
console.error(error);
}
await mutations.collaborationInfo.put({});
try {
const client = createMinimalGraphQLClient({
origin: API_HOST_HTTP,
});
const result = await client.query({
query: graphql(`
query DefaultCategories {
foodCategories {
id
name
sortKey
}
}
`),
});
if (!result.data) {
if (result.error) throw result.error;
throw new Error('No data returned');
}
for (const defaultCategory of result.data.foodCategories) {
await mutations.categories.put({
id: defaultCategory.id.toString(),
name: defaultCategory.name,
sortKey: defaultCategory.sortKey,
});
}
} catch (error) {
console.error(error);
}
});
72 changes: 36 additions & 36 deletions apps/gnocchi/verdant/src/migrations/v5.ts
Original file line number Diff line number Diff line change
@@ -1,45 +1,45 @@
import v4Schema, {
MigrationTypes as V4Types,
MigrationTypes as V4Types,
} from '../client/schemaVersions/v4.js';
import v5Schema, {
MigrationTypes as V5Types,
MigrationTypes as V5Types,
} from '../client/schemaVersions/v5.js';
import { createMigration } from '@verdant-web/store';
import { createMinimalGraphQLClient, graphql } from '@biscuits/client';
import { createMinimalGraphQLClient, graphql } from '@biscuits/graphql';
import { API_HOST_HTTP } from '../config.js';

export default createMigration<V4Types, V5Types>(
v4Schema,
v5Schema,
async ({ mutations }) => {
try {
const client = createMinimalGraphQLClient({
origin: API_HOST_HTTP,
});
const result = await client.query({
query: graphql(`
query DefaultCategories {
foodCategories {
id
name
sortKey
}
}
`),
});
if (!result.data) {
if (result.error) throw result.error;
throw new Error('No data returned');
}
for (const defaultCategory of result.data.foodCategories) {
await mutations.categories.put({
id: defaultCategory.id.toString(),
name: defaultCategory.name,
sortKey: defaultCategory.sortKey,
});
}
} catch (error) {
console.error(error);
}
},
v4Schema,
v5Schema,
async ({ mutations }) => {
try {
const client = createMinimalGraphQLClient({
origin: API_HOST_HTTP,
});
const result = await client.query({
query: graphql(`
query DefaultCategories {
foodCategories {
id
name
sortKey
}
}
`),
});
if (!result.data) {
if (result.error) throw result.error;
throw new Error('No data returned');
}
for (const defaultCategory of result.data.foodCategories) {
await mutations.categories.put({
id: defaultCategory.id.toString(),
name: defaultCategory.name,
sortKey: defaultCategory.sortKey,
});
}
} catch (error) {
console.error(error);
}
},
);
83 changes: 30 additions & 53 deletions apps/gnocchi/web/src/components/addBar/AddPane.tsx
Original file line number Diff line number Diff line change
@@ -1,37 +1,12 @@
import { recipeSavePromptState } from '@/components/recipes/savePrompt/state.js';
import { AddToListDialog } from '@/components/recipes/viewer/AddToListDialog.jsx';
import useMergedRef from '@/hooks/useMergedRef.js';
import { Input } from '@a-type/ui/components/input';
import { useSize } from '@a-type/ui/hooks';
import { isUrl, preventDefault, stopPropagation } from '@a-type/utils';
import {
showSubscriptionPromotion,
useHasServerAccess,
} from '@biscuits/client';
import { Recipe } from '@gnocchi.biscuits/verdant';
import { preventDefault, stopPropagation } from '@a-type/utils';
import classNames from 'classnames';
import {
UseComboboxState,
UseComboboxStateChangeOptions,
useCombobox,
} from 'downshift';
import {
Suspense,
forwardRef,
useCallback,
useEffect,
useRef,
useState,
useTransition,
} from 'react';
import { Suspense, forwardRef, useEffect, useRef, useState } from 'react';
import { AddInput } from './AddInput.jsx';
import { SuggestionGroup } from './SuggestionGroup.jsx';
import {
SuggestionData,
suggestionToString,
useAddBarCombobox,
useAddBarSuggestions,
} from './hooks.js';
import { useAddBarCombobox, useAddBarSuggestions } from './hooks.js';
import { AddBarProps } from './AddBar.jsx';
import { ScrollArea } from '@a-type/ui/components/scrollArea';

Expand Down Expand Up @@ -156,31 +131,33 @@ const AddPaneImpl = forwardRef<
onScroll={stopPropagation}
background="white"
>
{showSuggested && (
<SuggestionGroup
title="Suggested"
suggestions={mainSuggestions}
highlightedIndex={highlightedIndex}
getItemProps={getItemProps}
/>
)}
{showExpiring && (
<SuggestionGroup
title="Expiring Soon"
suggestions={expiresSoonSuggestions}
getItemProps={getItemProps}
highlightedIndex={highlightedIndex}
/>
)}
{!noSuggestions && (
<SuggestionGroup
title={inputValue ? 'Matches' : 'Favorites'}
suggestions={matchSuggestions}
highlightedIndex={highlightedIndex}
getItemProps={getItemProps}
/>
)}
{noSuggestions && <div>No suggestions</div>}
<div className="flex flex-col gap-4 items-stretch">
{showSuggested && (
<SuggestionGroup
title="Suggested"
suggestions={mainSuggestions}
highlightedIndex={highlightedIndex}
getItemProps={getItemProps}
/>
)}
{showExpiring && (
<SuggestionGroup
title="Expiring Soon"
suggestions={expiresSoonSuggestions}
getItemProps={getItemProps}
highlightedIndex={highlightedIndex}
/>
)}
{!noSuggestions && (
<SuggestionGroup
title={inputValue ? 'Matches' : 'Favorites'}
suggestions={matchSuggestions}
highlightedIndex={highlightedIndex}
getItemProps={getItemProps}
/>
)}
{noSuggestions && <div>No suggestions</div>}
</div>
</ScrollArea>
{addingRecipe && (
<AddToListDialog
Expand Down
104 changes: 54 additions & 50 deletions apps/gnocchi/web/src/components/groceries/items/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,60 +4,64 @@ import { fractionToText } from '@a-type/utils';
import pluralize from 'pluralize';

export function useItemDisplayText(item: Item) {
const override = item.get('textOverride');
const quantity = item.get('totalQuantity');
const override = item.get('textOverride');
const quantity = item.get('totalQuantity');

if (override) {
if (quantity === 1) return override;
return `${fractionToText(quantity)} ${pluralize(override)}`;
}
if (override) {
if (quantity === 1) return override;
return `${fractionToText(quantity)} ${pluralize(override)}`;
}

const inputs = item.get('inputs');
const inputs = item.get('inputs');

const pluralizedUnit = item.get('unit')
? item.get('totalQuantity') === 1
? item.get('unit')
: pluralize(item.get('unit'))
: '';
const pluralizedName =
item.get('totalQuantity') === 1 || item.get('unit')
? item.get('food')
: pluralize(item.get('food'));
// try as much as we can to show the original text, not parsed.
// If there's only one input and no multiplier or quantity editing
// has happened, we can do that.
const showOnlyInput =
inputs.length === 1 &&
(inputs.get(0).get('multiplier') === null ||
inputs.get(0).get('multiplier') === 1) &&
(inputs.get(0).get('quantity') === null ||
inputs.get(0).get('quantity') === quantity);
const displayString = showOnlyInput
? `${inputs.get(0).get('text')}`
: `${fractionToText(quantity)} ${
pluralizedUnit && `${pluralizedUnit} `
}${pluralizedName}`;
const pluralizedUnit = item.get('unit')
? item.get('totalQuantity') === 1
? item.get('unit')
: pluralize(item.get('unit'))
: '';
const pluralizedName =
item.get('totalQuantity') === 1 || item.get('unit')
? item.get('food')
: pluralize(item.get('food'));
// try as much as we can to show the original text, not parsed.
// If there's only one input and no multiplier or quantity editing
// has happened, we can do that.
const showOnlyInput =
inputs.length === 1 &&
(inputs.get(0).get('multiplier') === null ||
inputs.get(0).get('multiplier') === 1) &&
(inputs.get(0).get('quantity') === null ||
inputs.get(0).get('quantity') === quantity);
const displayString = showOnlyInput
? `${inputs.get(0).get('text')}`
: `${fractionToText(quantity)} ${
pluralizedUnit && `${pluralizedUnit} `
}${pluralizedName}`;

return displayString;
return displayString;
}
export function useItemSubline(item: Item) {
const { comment, textOverride } = hooks.useWatch(item);
hooks.useWatch(item.get('inputs'));
if (comment) {
return comment;
}
// items with a text override show their original as subline
if (textOverride) {
const firstInput = item.get('inputs').get(0);
if (!firstInput) return undefined;
const firstInputText = firstInput.get('text');
if (
firstInputText.trim().toLowerCase() === textOverride.trim().toLowerCase()
) {
return undefined;
}
const numInputs = item.get('inputs').length;
return firstInputText + (numInputs > 1 ? `, ...` : '');
}
return undefined;
const { comment, textOverride } = hooks.useWatch(item);
hooks.useWatch(item.get('inputs'));
if (comment) {
return comment;
}
// items with a text override show their original as subline
if (textOverride) {
const firstInput = item.get('inputs').get(0);
if (!firstInput) return undefined;
const firstInputText =
firstInput.get('text') +
(firstInput.get('multiplier')
? ` (x${firstInput.get('multiplier')})`
: '');
if (
firstInputText.trim().toLowerCase() === textOverride.trim().toLowerCase()
) {
return undefined;
}
const numInputs = item.get('inputs').length;
return firstInputText + (numInputs > 1 ? `, ...` : '');
}
return undefined;
}
Loading

0 comments on commit 538ca2c

Please sign in to comment.