Skip to content

Commit

Permalink
Replace provideLocal with app-level provide
Browse files Browse the repository at this point in the history
Cleanup
  • Loading branch information
bperel committed Aug 22, 2024
1 parent e89d7a3 commit 4a02ca5
Show file tree
Hide file tree
Showing 60 changed files with 187 additions and 216 deletions.
1 change: 1 addition & 0 deletions apps/dumili/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"@vueuse/integrations": "^10.11.1",
"bootstrap": "^5.3.3",
"bootstrap-vue-next": "^0.24.9",
"dayjs": "^1.11.13",
"js-cookie": "^3.0.5",
"page-flip": "^2.0.7",
"pinia": "^2.2.2",
Expand Down
20 changes: 14 additions & 6 deletions apps/dumili/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions apps/dumili/src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,19 @@
</template>

<script setup lang="ts">
import { provideLocal } from "@vueuse/core";
import Cookies from "js-cookie";
import { stores as webStores } from "~web";
import useDumiliSocket, {
dumiliSocketInjectionKey,
} from "./composables/useDumiliSocket";
import { buildWebStorage } from "~socket.io-client-services/index";
provideLocal(
getCurrentInstance()!.appContext.app.provide(
dumiliSocketInjectionKey,
useDumiliSocket({
cacheStorage: buildWebStorage(sessionStorage),
onConnectError: () => {
isLoadingUser.value = false;
user.value = null;
Expand Down
4 changes: 1 addition & 3 deletions apps/dumili/src/components/Entry.vue
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,6 @@
</b-row>
</template>
<script setup lang="ts">
import { injectLocal } from "@vueuse/core";
import { dumiliSocketInjectionKey } from "~/composables/useDumiliSocket";
import { suggestions } from "~/stores/suggestions";
import { user } from "~/stores/ui";
Expand All @@ -159,7 +157,7 @@ const props = defineProps<{
const { entry, editable } = toRefs(props);
const { getIndexationSocket } = injectLocal(dumiliSocketInjectionKey)!;
const { getIndexationSocket } = inject(dumiliSocketInjectionKey)!;
const { indexation, acceptedStories, acceptedStoryKinds, entriesFirstPages } =
storeToRefs(suggestions());
Expand Down
4 changes: 1 addition & 3 deletions apps/dumili/src/components/IssueSuggestionList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@
</template>

<script lang="ts" setup>
import { injectLocal } from "@vueuse/core";
import { dumiliSocketInjectionKey } from "~/composables/useDumiliSocket";
import { suggestions } from "~/stores/suggestions";
Expand All @@ -31,7 +29,7 @@ const { indexation } = storeToRefs(suggestionsStore);
import { issueSuggestion } from "~prisma/client_dumili";
const { getIndexationSocket } = injectLocal(dumiliSocketInjectionKey)!;
const { getIndexationSocket } = inject(dumiliSocketInjectionKey)!;
const issue = computed(() => suggestionsStore.acceptedIssue);
Expand Down
2 changes: 1 addition & 1 deletion apps/dumili/src/components/IssueSuggestionModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ import { dmSocketInjectionKey } from "~web/src/composables/useDmSocket";
const { t: $t } = useI18n();
const {
coverId: { services: coverIdServices },
} = injectLocal(dmSocketInjectionKey)!;
} = inject(dmSocketInjectionKey)!;
const { getIndexationSocket } = injectLocal(dumiliSocketInjectionKey)!;
const { hasPendingIssueSuggestions, indexation } = storeToRefs(suggestions());
Expand Down
4 changes: 1 addition & 3 deletions apps/dumili/src/components/StorySearch.vue
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,12 @@
</template>

<script setup lang="ts">
import { injectLocal } from "@vueuse/core";
import { SimpleStory } from "~dm-types/SimpleStory";
import { dmSocketInjectionKey } from "~web/src/composables/useDmSocket";
const {
coa: { services: coaServices },
} = injectLocal(dmSocketInjectionKey)!;
} = inject(dmSocketInjectionKey)!;
const emit = defineEmits<{
(e: "story-selected", searchResult: SimpleStory): void;
Expand Down
4 changes: 1 addition & 3 deletions apps/dumili/src/components/StorySuggestionList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@
</template>

<script lang="ts" setup>
import { injectLocal } from "@vueuse/core";
import { dumiliSocketInjectionKey } from "~/composables/useDumiliSocket";
import { suggestions } from "~/stores/suggestions";
import { SimpleStory } from "~dm-types/SimpleStory";
Expand All @@ -37,7 +35,7 @@ const props = defineProps<{
const { entry } = toRefs(props);
const { getIndexationSocket } = injectLocal(dumiliSocketInjectionKey)!;
const { getIndexationSocket } = inject(dumiliSocketInjectionKey)!;
const indexationSocket = computed(async () =>
getIndexationSocket(entry.value.indexationId),
Expand Down
4 changes: 1 addition & 3 deletions apps/dumili/src/components/TextEditor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,12 @@
<script setup lang="ts">
const { t: $t } = useI18n();
import { injectLocal } from "@vueuse/core";
import { suggestions } from "~/stores/suggestions";
import { dmSocketInjectionKey } from "~web/src/composables/useDmSocket";
const {
coa: { services: coaServices },
} = injectLocal(dmSocketInjectionKey)!;
} = inject(dmSocketInjectionKey)!;
const textContentError = ref("");
const { acceptedStories, acceptedIssue: issue } = storeToRefs(suggestions());
Expand Down
4 changes: 2 additions & 2 deletions apps/dumili/src/components/UploadWidget.vue
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ import "@uppy/dashboard/dist/style.css";
import Uppy from "@uppy/core";
import Dashboard from "@uppy/dashboard";
import XHR from "@uppy/xhr-upload";
// import { injectLocal } from "@vueuse/core";
//
// import { dmSocketInjectionKey } from "~web/src/composables/useDmSocket";
// const {
// coverId: { socket: coverIdSocket },
// } = injectLocal(dmSocketInjectionKey)!;
// } = inject(dmSocketInjectionKey)!;
const props = defineProps<{
folderName: string;
Expand Down
21 changes: 9 additions & 12 deletions apps/dumili/src/composables/useHint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,15 @@ export default () => {
return;
}
await Promise.all(
results.covers.map(
({ issuecode, publicationcode, issuenumber /*, id: coverId*/ }) =>
getIndexationSocket(
indexation.value!.id,
).services.acceptIssueSuggestion({
source: "ai",
issuecode,
publicationcode,
issuenumber,
// coverId,
indexationId: indexation.value!.id,
}),
results.covers.map(({ issuecode /*, id: coverId*/ }) =>
getIndexationSocket(
indexation.value!.id,
).services.acceptIssueSuggestion({
source: "ai",
issuecode,
// coverId,
indexationId: indexation.value!.id,
}),
),
);

Expand Down
4 changes: 1 addition & 3 deletions apps/dumili/src/pages/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,12 @@
</template>

<script setup lang="ts">
import { injectLocal } from "@vueuse/core";
import { dumiliSocketInjectionKey } from "~/composables/useDumiliSocket";
import { IndexationWithFirstPage } from "~dumili-services/indexations/types";
const router = useRouter();
const {
indexations: { services: indexationsServices },
} = injectLocal(dumiliSocketInjectionKey)!;
} = inject(dumiliSocketInjectionKey)!;
const currentIndexations = ref<IndexationWithFirstPage[] | null>(null);
const modal = ref(false);
Expand Down
9 changes: 4 additions & 5 deletions apps/edgecreator/api/_utils.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import { inducks_issue } from "~prisma-schemas/schemas/coa";
import { prismaClient as prismaCoa } from "~prisma-schemas/schemas/coa/client";

export const getSvgPath = async (isExport: boolean, issuecode: string) => {
const issue = await inducks_issue.findFirstOrThrow({
const issue = await prismaCoa.inducks_issue.findFirstOrThrow({
where: { issuecode },
select: { publicationcode: true, issuenumber: true },
});
const [countrycode, magazinecode] = issue.publicationcode.split("/");
return `${process.cwd()}/../${process.env.EDGES_PATH!}/${countrycode}/gen/${
isExport ? "" : "_"
}${magazinecode}.${issue.issuenumber}.svg`;
return `${process.cwd()}/../${process.env.EDGES_PATH!}/${countrycode}/gen/${isExport ? "" : "_"
}${magazinecode}.${issue.issuenumber}.svg`;
};
7 changes: 3 additions & 4 deletions apps/edgecreator/api/services/upload/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export default (io: Server) => {
socket.on("uploadFromBase64", async (parameters, callback) => {
const { issuecode, data } = parameters;
const { publicationcode, issuenumber } =
await prismaClient.inducks_issue.findFirstOrThrow({
await prismaCoa.inducks_issue.findFirstOrThrow({
where: { issuecode },
});
const [countrycode, magazinecode] = publicationcode.split("/");
Expand Down Expand Up @@ -146,9 +146,8 @@ const getTargetFilename = async (
"jpg",
);
} else {
return `${edgesPath}/${country}/elements/${
filename.includes(magazine) ? filename : `${magazine}.${filename}`
}`;
return `${edgesPath}/${countrycode}/elements/${filename.includes(magazinecode) ? filename : `${magazinecode}.${filename}`
}`;
}
}
};
Expand Down
18 changes: 8 additions & 10 deletions apps/edgecreator/src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
</template>

<script setup lang="ts">
import { provideLocal } from "@vueuse/core";
import Cookies from "js-cookie";
import type { useSocket } from "~socket.io-client-services/index";
Expand Down Expand Up @@ -34,20 +33,19 @@ const onConnectError = (e: Error) => {
location.replace(
`${import.meta.env.VITE_DM_URL as string}/login?redirect=${
window.location.href
}`,
}`
);
}
};
provideLocal(
getCurrentInstance()!.appContext.app.provide(
edgecreatorSocketInjectionKey,
useEdgecreatorSocket(
inject("edgecreatorSocket") as ReturnType<typeof useSocket>,
{
session,
onConnectError,
},
),
}
)
);
const dmSocket = useDmSocket(
Expand All @@ -56,10 +54,10 @@ const dmSocket = useDmSocket(
cacheStorage: buildWebStorage(sessionStorage),
session,
onConnectError,
},
}
);
provideLocal(dmSocketInjectionKey, dmSocket);
getCurrentInstance()!.appContext.app.provide(dmSocketInjectionKey, dmSocket);
const route = useRoute();
const user = computed(() => webStores.collection().user);
Expand All @@ -77,15 +75,15 @@ watch(
!userPermissions.value?.some(
({ privilege, role }) =>
role === "EdgeCreator" &&
["Edition", "Admin"].includes(privilege as string),
["Edition", "Admin"].includes(privilege as string)
)
) {
location.replace("/");
}
}
}
},
{ immediate: true },
{ immediate: true }
);
</script>

Expand Down
8 changes: 3 additions & 5 deletions apps/edgecreator/src/components/from-dm/Issue.vue
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,13 @@ const {
}>();
const publicationname = computed(
() => publicationcode.value && coa().publicationNames[publicationcode.value],
() => publicationcode.value && coa().publicationNames[publicationcode.value]
);
const publicationcode = computed(
() =>
coa().issuecodeDetails[issuecode] &&
coa().issuecodeDetails[issuecode].publicationcode,
() => coa().issuecodeDetails[issuecode]?.publicationcode
);
const issuenumber = computed(
() => coa().issuecodeDetails[issuecode].issuenumber,
() => coa().issuecodeDetails[issuecode].issuenumber
);
</script>

Expand Down
Loading

0 comments on commit 4a02ca5

Please sign in to comment.