Skip to content

Commit 7420a94

Browse files
committed
fixup readonly, fixup query types
microsoft/TypeScript#34777
1 parent 31ad3de commit 7420a94

File tree

10 files changed

+165
-161
lines changed

10 files changed

+165
-161
lines changed

app/src/components/editor/layout/LayoutEditor.tsx

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,8 @@ export default function LayoutEditor({ appState }: { appState: AppState }) {
1818
}
1919

2020
function LayoutSurface({ ctx, deckId }: { ctx: Ctx; deckId: ID_of<Deck> }) {
21-
const slides = useQuery<Slide>(...queries.slides(ctx, deckId)).data;
22-
const selectedSlideIds = useQuery<ID_of<Slide>>(
23-
...queries.selectedSlides(ctx, deckId)
24-
).data;
21+
const slides = useQuery(queries.slides(ctx, deckId)).data;
22+
const selectedSlideIds = useQuery(queries.selectedSlides(ctx, deckId)).data;
2523
const set = useMemo<Set<ID_of<Slide>>>(
2624
() => new Set(selectedSlideIds),
2725
[selectedSlideIds]

app/src/components/editor/markdown/styling_menu/FontColorButton.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ type Props = {
1515
};
1616

1717
export default function FontColorButton({ ctx, state, theme }: Props) {
18-
const recentColors = useQueryA<[string], string>(
19-
...queries.recentColors(ctx, theme?.id || config.defaultThemeId)
18+
const recentColors = useQueryA(
19+
queries.recentColors(ctx, theme?.id || config.defaultThemeId)
2020
).data;
2121
// useBind(["transaction"], state);
2222
// useQuery(["recentColors"], theme);

app/src/components/editor/markdown/styling_menu/StylingMenu.tsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,7 @@ export default function StylingMenu({ appState }: Props) {
2222
const ctx = appState.ctx;
2323

2424
const theme = first(
25-
useQuery<Theme>(
26-
...queries.themeFromDeck(appState.ctx, appState.current_deck_id)
27-
).data
25+
useQuery(queries.themeFromDeck(appState.ctx, appState.current_deck_id)).data
2826
);
2927

3028
const addImage = () => {

app/src/components/editor/well/SlideWell.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ function SlideWell({
2222
appState: AppState;
2323
}) {
2424
// TODO: paginated fetch
25-
const slideIds = useQueryA<[ID_of<SlideType>], ID_of<SlideType>>(
26-
...queries.slideIds(appState.ctx, appState.current_deck_id)
25+
const slideIds = useQueryA(
26+
queries.slideIds(appState.ctx, appState.current_deck_id)
2727
).data;
2828
const orientHorizontally = useMatchMedia(
2929
"(max-width: " + mediaCuts.horizontal + "px)"

app/src/components/editor/well/WellContextMenu.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export default function WellContextMenu({
2121
}
2222
onClick={(e) => {
2323
// TODO: index based or... slide id base?
24-
mutations.addSlideAfter(appState.ctx, index);
24+
mutations.addSlideAfter(appState.ctx, index, appState.current_deck_id);
2525
e.stopPropagation();
2626
}}
2727
>

app/src/components/editor/well/WellSlide.tsx

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,15 @@ function WellSlide(props: {
3737
// TODO: these types should be part of `queries.` so the caller doesn't
3838
// need to provide them
3939
const markdown = first(
40-
useQuery<Markdown>(...queries.markdown(props.appState.ctx, props.id)).data
40+
useQuery(queries.markdown(props.appState.ctx, props.id)).data
4141
);
42-
const theme = useQuery<Theme>(
43-
...queries.themeFromDeck(props.appState.ctx, props.appState.current_deck_id)
44-
).data;
45-
const selectedSlides = useQueryA<[ID_of<Slide>], ID_of<Slide>>(
46-
...queries.selectedSlides(props.appState.ctx, props.id)
42+
const theme = first(
43+
useQuery(
44+
queries.themeFromDeck(props.appState.ctx, props.appState.current_deck_id)
45+
).data
46+
);
47+
const selectedSlides = useQueryA(
48+
queries.selectedSlides(props.appState.ctx, props.id)
4749
).data;
4850

4951
const previewTheme = props.appState.previewTheme;
@@ -184,15 +186,15 @@ function WellSlide(props: {
184186
selected: props.deck.mostRecentlySelectedSlide === props.index,
185187
[styles.root]: true,
186188
[styles.in]: dropClass === styles.in,
187-
[previewTheme.getFontClass(theme)]: true,
189+
[fns.getFontClass(previewTheme, theme)]: true,
188190
})}
189191
onClick={() => {
190192
commit(props.deck.setSelectedSlide(props.index, true), [
191193
persistLog,
192194
undoLog,
193195
]);
194196
}}
195-
style={{ backgroundColor: previewTheme.getSlideColorStyle(theme) }}
197+
style={{ backgroundColor: fns.getSlideColorStyle(previewTheme, theme) }}
196198
>
197199
<div className={styles.markdownContainer} ref={setRef}></div>
198200
<WellSlideDrawingPreview

app/src/domain/fns.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,17 @@ const fns = {
1717
return undefined;
1818
},
1919

20+
getSlideColorStyle(
21+
previewTheme: Theme,
22+
pickedTheme?: Theme
23+
): string | undefined {
24+
return undefined;
25+
},
26+
27+
getFontClass(previewTheme: Theme, pickedTheme?: Theme): string | undefined {
28+
return undefined;
29+
},
30+
2031
mdStringAsDom(content: string) {
2132
return toDOM(content);
2233
},

app/src/domain/queries.ts

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import { Ctx, first, pick0 } from "../hooks";
1+
import { Ctx, first, pick0, Query } from "../hooks";
22
import { ID_of } from "../id";
3-
import { Deck, Slide, Theme } from "./schema";
3+
import { Deck, Markdown, Presenter, Slide, TableName, Theme } from "./schema";
44

55
const queries = {
66
// TODO: we can collapse all "same calls" in the same tick. to just do 1 query
@@ -16,22 +16,22 @@ const queries = {
1616
["undo_stack"],
1717
"SELECT 1 FROM undo_stack WHERE deck_id = ? LIMIT 1",
1818
[id],
19-
] as const,
19+
] as Query<boolean, TableName>,
2020
canRedo: (ctx: Ctx, id: ID_of<Deck>) =>
2121
[
2222
ctx,
2323
["redo_stack"],
2424
"SELECT 1 FROM undo_stack WHERE deck_id = ? LIMIT 1",
2525
[id],
26-
] as const,
26+
] as Query<boolean, TableName>,
2727

2828
slides: (ctx: Ctx, id: ID_of<Deck>) =>
2929
[
3030
ctx,
3131
["slide"],
3232
'SELECT * FROM slide WHERE deck_id = ? ORDER BY "order" ASC',
3333
[id],
34-
] as const,
34+
] as Query<Slide, TableName>,
3535

3636
slideIds: (ctx: Ctx, id: ID_of<Deck>) =>
3737
[
@@ -40,23 +40,24 @@ const queries = {
4040
'SELECT id FROM slide WHERE deck_id = ? ORDER BY "order" ASC',
4141
[id],
4242
(x: [ID_of<Slide>]) => x[0],
43-
] as const,
43+
] as Query<[ID_of<Slide>], TableName, ID_of<Slide>>,
4444

4545
chosenPresenter: (ctx: Ctx, id: ID_of<Deck>) =>
4646
[
4747
ctx,
4848
["deck", "presenter"],
4949
"SELECT presenter.* FROM presenter, deck WHERE deck.id = ? AND presenter.name = deck.chosen_presenter",
5050
[id],
51-
] as const,
51+
] as Query<Presenter, TableName>,
5252

5353
selectedSlides: (ctx: Ctx, id: ID_of<Deck>) =>
5454
[
5555
ctx,
56-
["selected_slide"],
56+
["slide"],
5757
"SELECT slide_id FROM selected_slide WHERE deck_id = ?",
5858
[id],
59-
] as const,
59+
(x: [ID_of<Slide>]) => x[0],
60+
] as Query<[ID_of<Slide>], TableName, ID_of<Slide>>,
6061

6162
recentColors: (ctx: Ctx, id: ID_of<Theme>) =>
6263
[
@@ -65,26 +66,29 @@ const queries = {
6566
"SELECT color FROM recent_color WHERE theme_id = ?",
6667
[id],
6768
(x: [string]) => x[0],
68-
] as const,
69+
] as Query<[string], TableName, string>,
6970

7071
theme: (ctx: Ctx, id: ID_of<Theme>) =>
71-
[ctx, ["theme"], "SELECT * FROM theme WHERE id = ?", [id]] as const,
72+
[ctx, ["theme"], "SELECT * FROM theme WHERE id = ?", [id]] as Query<
73+
Theme,
74+
TableName
75+
>,
7276

7377
themeFromDeck: (ctx: Ctx, id: ID_of<Deck>) =>
7478
[
7579
ctx,
7680
["theme", "deck"],
7781
"SELECT theme.* FROM theme JOIN deck ON theme.id = deck.theme_id WHERE deck.id = ?",
7882
[id],
79-
] as const,
83+
] as Query<Theme, TableName>,
8084

8185
markdown: (ctx: Ctx, id: ID_of<Slide>) =>
8286
[
8387
ctx,
8488
["markdown"],
8589
"SELECT * FROM markdown WHERE slide_id = ?",
8690
[id],
87-
] as const,
88-
};
91+
] as Query<Markdown, TableName>,
92+
} as const;
8993

9094
export default queries;

0 commit comments

Comments
 (0)