Skip to content

Commit

Permalink
whattheduck: Fix signup
Browse files Browse the repository at this point in the history
api: Fix country, magazine code and issuenumber not set
  • Loading branch information
bperel committed Oct 9, 2024
1 parent 8ee2f94 commit 33fbf5a
Show file tree
Hide file tree
Showing 32 changed files with 624 additions and 422 deletions.
5 changes: 0 additions & 5 deletions apps/dumili/src/composables/useDumiliSocket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import EdgeCreatorServices from "~dm-services/edgecreator/types";
import EdgesServices from "~dm-services/edges/types";
import EventsServices from "~dm-services/events/types";
import GlobalStatsServices from "~dm-services/global-stats/types";
import LoginServices from "~dm-services/login/types";
import PresentationTextServices from "~dm-services/presentation-text/types";
import PublicCollectionServices from "~dm-services/public-collection/types";
import StatsServices from "~dm-services/stats/types";
Expand Down Expand Up @@ -49,10 +48,6 @@ const defaultExport = (options: {
publicCollection: socket.addNamespace<PublicCollectionServices>(
PublicCollectionServices.namespaceEndpoint,
),
login: socket.addNamespace<LoginServices>(
LoginServices.namespaceEndpoint,
{},
),

bookcase: socket.addNamespace<BookcaseServices>(
BookcaseServices.namespaceEndpoint,
Expand Down
11 changes: 5 additions & 6 deletions apps/web/src/composables/useDmSocket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import EdgeCreatorServices from "~dm-services/edgecreator/types";
import EdgesServices from "~dm-services/edges/types";
import EventsServices from "~dm-services/events/types";
import GlobalStatsServices from "~dm-services/global-stats/types";
import LoginServices from "~dm-services/login/types";
import PresentationTextServices from "~dm-services/presentation-text/types";
import PublicCollectionServices from "~dm-services/public-collection/types";
import StatsServices from "~dm-services/stats/types";
Expand Down Expand Up @@ -62,7 +61,6 @@ const defaultExport = (
PublicCollectionServices.namespaceEndpoint,
),
app: socket.addNamespace<AppServices>(AppServices.namespaceEndpoint),
login: socket.addNamespace<LoginServices>(LoginServices.namespaceEndpoint),

bookcase: socket.addNamespace<BookcaseServices>(
BookcaseServices.namespaceEndpoint,
Expand Down Expand Up @@ -115,10 +113,11 @@ const defaultExport = (
CollectionServices.namespaceEndpoint,
{
session,
cache: {
storage: cacheStorage,
ttl: 1000, // 1 second only, because we want to always get the latest data but still cache in case of offline
},
// TODO cache is wrongly done on all endpoints if uncommented, it should be done only on retrieval endpoints
// cache: {
// storage: cacheStorage,
// ttl: 1000, // 1 second only, because we want to always get the latest data but still cache in case of offline
// },
},
),
coverId: socket.addNamespace<CoverIdServices>(
Expand Down
4 changes: 2 additions & 2 deletions apps/web/src/pages/demo.vue
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const { user } = storeToRefs(collection());
const router = useRouter();
const {
login: { services: loginServices },
auth: { services: authServices },
} = inject(socketInjectionKey)!;
watch(
Expand All @@ -28,7 +28,7 @@ watch(
);
(async () => {
const result = await loginServices.loginAsDemo();
const result = await authServices.loginAsDemo();
switch (result.error) {
case "No demo user found":
console.error(result.error);
Expand Down
2 changes: 1 addition & 1 deletion apps/web/src/pages/signup.vue
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ import Cookies from "js-cookie";
import type { ScopedError } from "~socket.io-services/types";
const { signup: userSignup, loadUser } = collection();
const { loadUser } = collection();
const { user } = storeToRefs(collection());
const router = useRouter();
Expand Down
43 changes: 9 additions & 34 deletions apps/web/src/stores/collection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import type {
purchase,
subscription,
} from "~prisma-schemas/schemas/dm";
import type { EventReturnType, ScopedError } from "~socket.io-services/types";
import type { EventReturnType } from "~socket.io-services/types";

import useCollection from "../composables/useCollection";
import { socketInjectionKey } from "../composables/useDmSocket";
Expand Down Expand Up @@ -41,7 +41,7 @@ export const collection = defineStore("collection", () => {
const {
collection: { services: collectionServices },
stats: { services: statsServices },
login: { services: loginServices },
auth: { services: authServices },
options: socketOptions,
} = inject(socketInjectionKey)!;

Expand All @@ -52,8 +52,8 @@ export const collection = defineStore("collection", () => {
>(null);

const collectionUtils = useCollection(
issues as ShallowRef<(issue & { issuecode: string })[]>,
),
issues as ShallowRef<(issue & { issuecode: string })[]>,
),
watchedPublicationsWithSales = shallowRef<string[] | null>(null),
purchases = shallowRef<purchase[] | null>(null),
watchedAuthors = shallowRef<authorUser[] | null>(null),
Expand Down Expand Up @@ -81,8 +81,8 @@ export const collection = defineStore("collection", () => {
>(null),
coaIssueCountsByPublicationcode = shallowRef<
| EventReturnType<
CollectionServices["getIssues"]
>["countByPublicationcode"]
CollectionServices["getIssues"]
>["countByPublicationcode"]
| null
>(null),
user = shallowRef<
Expand Down Expand Up @@ -120,7 +120,7 @@ export const collection = defineStore("collection", () => {
([publicationcode1], [publicationcode2]) =>
Math.sign(
totalPerPublicationUniqueIssuecodes.value[publicationcode2]! -
totalPerPublicationUniqueIssuecodes.value[publicationcode1]!,
totalPerPublicationUniqueIssuecodes.value[publicationcode1]!,
),
),
),
Expand Down Expand Up @@ -312,7 +312,7 @@ export const collection = defineStore("collection", () => {
onSuccess: (token: string) => void,
onError: (e: string) => void,
) => {
const response = await loginServices.login({
const response = await authServices.login({
username,
password,
});
Expand All @@ -322,30 +322,6 @@ export const collection = defineStore("collection", () => {
onSuccess(response as string);
}
},
signup = async (
username: string,
password: string,
password2: string,
email: string,
onSuccess: (token: string) => void,
onError: (e: ScopedError) => void,
) => {
const response = await collectionServices.createUser({
username,
password,
password2,
email,
});
if (response.error) {
if (response.selector) {
onError(response);
} else {
console.error(response.error, response.errorDetails);
}
} else {
onSuccess(response.token);
}
},
loadUser = async (afterUpdate = false) => {
if (!isLoadingUser.value && (afterUpdate || !user.value)) {
isLoadingUser.value = true;
Expand All @@ -371,7 +347,7 @@ export const collection = defineStore("collection", () => {
console.log(issues.value);
return {
...collectionUtils,
loginServices,
authServices,
issues,
publicationUrlRoot,
createPurchase,
Expand Down Expand Up @@ -404,7 +380,6 @@ export const collection = defineStore("collection", () => {
previousVisit,
purchases,
purchasesById,
signup,
subscriptions,
suggestions,
totalPerPublicationUniqueIssuecodes,
Expand Down
4 changes: 2 additions & 2 deletions apps/whattheduck/.env
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
BASE_URL=http://localhost:8003

VITE_DM_SOCKET_URL=https://api-websocket.ducksmanager.net
#VITE_DM_SOCKET_URL=https://api-websocket.ducksmanager.net

#VITE_DM_SOCKET_URL=http://localhost:3000
VITE_DM_SOCKET_URL=http://localhost:3000

VITE_DISCORD_URL=https://discord.gg/ruk3FsD
VITE_DM_URL=https://ducksmanager.net
Expand Down
1 change: 1 addition & 0 deletions apps/whattheduck/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@
"concurrently": "^9.0.1",
"eslint": "^9.12.0",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-import": "^2.31.0",
"eslint-plugin-i18next": "^6.1.0",
"eslint-plugin-prettier-vue": "^5.0.0",
"eslint-plugin-simple-import-sort": "^12.1.1",
Expand Down
2 changes: 1 addition & 1 deletion apps/whattheduck/src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<OfflineBanner :on-offline="routeMeta.onOffline" v-if="isOfflineMode" />

<ion-router-outlet
v-if="route.path === '/login' || route.path === '/test'"
v-if="['/login', '/signup', '/test'].includes(route.path)"
:style="{ 'margin-top': `${offlineBannerHeight}px` }"
id="main-content"
:class="{ 'greyed-out': bundleDownloadProgress !== undefined }"
Expand Down
160 changes: 84 additions & 76 deletions apps/whattheduck/src/components/List.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,83 +2,90 @@
<ion-content v-if="!items" ref="content">
{{ t('Chargement…') }}
</ion-content>
<ion-content v-else-if="!items.length" ref="content">
{{ t('Cette liste est vide.') }}
</ion-content>
<ion-content
v-else
ref="content"
class="no-padding"
scroll-events
@ion-scroll="onScroll"
@ion-scroll-end="isScrolling = false"
>
<template v-if="$slots['row-label']">
<RecycleScroller
:style="{ visibility: isCameraPreviewShown ? 'hidden' : 'visible' }"
class="scroller"
:items="filteredItems"
:item-size="32"
key-field="uniqueKey"
item-class="item-wrapper"
v-slot="{ item: { key, item, isOwned, nextItemType } }"
>
<Row
:id="key"
:type="itemType"
:class="{ [`is-next-item-${nextItemType}`]: !!nextItemType, 'is-owned': isOwned }"
>
<template #fill-bar v-if="item">
<slot name="fill-bar" :item="item" />
</template>
<template #prefix v-if="item">
<slot name="row-prefix" :item="item" />
</template>
<template #label>
<slot name="row-label" :item="item" />
</template>
<template #suffix>
<slot name="row-suffix" :item="item" />
</template>
</Row>
</RecycleScroller>
<div id="edit-issues-buttons" v-if="selectedIssuecodes">
<EditIssuesConfirmCancelButtons
:confirm-ios="pencilOutline"
:confirm-md="pencilSharp"
:cancel-ios="closeOutline"
:cancel-md="closeSharp"
@cancel="selectedIssuecodes = null"
@confirm="updateNavigationToSelectedIssuecodes"
/></div
></template>
<slot v-else name="default" />
<EditIssuesButton
v-if="!selectedIssuecodes && !isCameraPreviewShown"
@show-camera-preview="isCameraPreviewShown = true"
/>

<template v-if="isCameraPreviewShown">
<div :id="cameraPreviewElementId"></div>
<div class="overlay" ref="overlay">
<ion-button ref="takePhotoButton" @click="takePhoto().then(() => (isCameraPreviewShown = false))" size="large">
<ion-icon :ios="apertureOutline" :md="apertureSharp" />
</ion-button>
<ion-button size="large" color="danger" @click="isCameraPreviewShown = false">
<ion-icon :ios="closeOutline" :md="closeSharp" />
</ion-button></div
></template>

<div
v-show="isScrolling"
v-if="itemInCenterOfViewport"
id="scroll-text"
slot="fixed"
:style="{ top: `${scrollPositionPct}%` }"
<template v-else>
<ion-content v-if="!items.length" ref="content">
<slot v-if="$slots.empty" name="empty" />
<template v-else>{{ t('Cette liste est vide.') }}</template>
</ion-content>
<ion-content
v-else
ref="content"
class="no-padding"
scroll-events
@ion-scroll="onScroll"
@ion-scroll-end="isScrolling = false"
>
{{ getItemTextFn(itemInCenterOfViewport) }}
</div></ion-content
>
<template v-if="$slots['row-label']">
<RecycleScroller
:style="{ visibility: isCameraPreviewShown ? 'hidden' : 'visible' }"
class="scroller"
:items="filteredItems"
:item-size="32"
key-field="uniqueKey"
item-class="item-wrapper"
v-slot="{ item: { key, item, isOwned, nextItemType } }"
>
<Row
:id="key"
:type="itemType"
:class="{ [`is-next-item-${nextItemType}`]: !!nextItemType, 'is-owned': isOwned }"
>
<template #fill-bar v-if="item">
<slot name="fill-bar" :item="item" />
</template>
<template #prefix v-if="item">
<slot name="row-prefix" :item="item" />
</template>
<template #label>
<slot name="row-label" :item="item" />
</template>
<template #suffix>
<slot name="row-suffix" :item="item" />
</template>
</Row>
</RecycleScroller>
<div id="edit-issues-buttons" v-if="selectedIssuecodes">
<EditIssuesConfirmCancelButtons
:confirm-ios="pencilOutline"
:confirm-md="pencilSharp"
:cancel-ios="closeOutline"
:cancel-md="closeSharp"
@cancel="selectedIssuecodes = null"
@confirm="updateNavigationToSelectedIssuecodes"
/></div
></template>
<slot v-else name="default" />
</ion-content>
<EditIssuesButton
v-if="!selectedIssuecodes && !isCameraPreviewShown"
@show-camera-preview="isCameraPreviewShown = true"
/>

<template v-if="isCameraPreviewShown">
<div :id="cameraPreviewElementId"></div>
<div class="overlay" ref="overlay">
<ion-button
ref="takePhotoButton"
@click="takePhoto().then(() => (isCameraPreviewShown = false))"
size="large"
>
<ion-icon :ios="apertureOutline" :md="apertureSharp" />
</ion-button>
<ion-button size="large" color="danger" @click="isCameraPreviewShown = false">
<ion-icon :ios="closeOutline" :md="closeSharp" />
</ion-button></div
></template>

<div
v-show="isScrolling"
v-if="itemInCenterOfViewport"
id="scroll-text"
slot="fixed"
:style="{ top: `${scrollPositionPct}%` }"
>
{{ getItemTextFn(itemInCenterOfViewport) }}
</div>
</template>
</template>

<script setup lang="ts" generic="Item extends Required<any>">
Expand All @@ -94,6 +101,7 @@ import { app } from '~/stores/app';
defineSlots<{
'default'(): any;
'empty'(): any;
'fill-bar'(props: { item: Item }): any;
'row-prefix'(props: { item: Item }): any;
'row-label'(props: { item: Item }): any;
Expand Down
Loading

0 comments on commit 33fbf5a

Please sign in to comment.