Skip to content

Commit

Permalink
wrapQuery: drop deprecated useResult
Browse files Browse the repository at this point in the history
  • Loading branch information
erdnaxe committed Jun 21, 2024
1 parent c2e0638 commit 3dc646f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
2 changes: 1 addition & 1 deletion front/src/ctfnote/me.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ const MeSymbol: InjectionKey<Ref<Me | null>> = Symbol('me');

export function provideMe(refresh = false) {
const { result: me } = getMe(refresh);
provide(MeSymbol, me);
provide(MeSymbol, me as Ref<Me>);
return me;
}

Expand Down
11 changes: 8 additions & 3 deletions front/src/ctfnote/utils.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
import { OperationVariables } from '@apollo/client';
import { UseQueryReturn, useResult } from '@vue/apollo-composable';
import { UseQueryReturn } from '@vue/apollo-composable';
import ColorHash from 'color-hash';
import { DeepNonNullable, DeepRequired } from 'ts-essentials';
import { inject, InjectionKey, Ref } from 'vue';
import { computed, inject, InjectionKey } from 'vue';

export function wrapQuery<D, T, U extends OperationVariables>(
query: UseQueryReturn<T, U>,
def: D,
wrapper: (data: DeepRequired<DeepNonNullable<T>>) => D
) {
const result = useResult<T, D, D>(query.result as Ref<T>, def, wrapper);
const result = computed(() => {
if (query.result) {
return wrapper(query.result as DeepRequired<DeepNonNullable<T>>);
}
return def;
});

const onResult = function (cb: (arg: D) => void) {
query.onResult((data) => {
Expand Down

0 comments on commit 3dc646f

Please sign in to comment.