Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rebase/20240720 #19

Merged
merged 28 commits into from
Jul 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
dba8c33
ar preg nothing
angeloreale Jul 20, 2024
48070f7
ar preg nothing
angeloreale Jul 20, 2024
e9a90ef
ar preg nothing
angeloreale Jul 24, 2024
119691a
ar(fix) migration noise
angeloreale Jul 29, 2024
18ef945
ar(fix) migration noise
angeloreale Jul 29, 2024
0f5676a
Merge branch 'dev' into rebase/20240720
angeloreale Jul 29, 2024
e9fa194
ar(fix) migration noise
angeloreale Jul 29, 2024
65adced
ar(fix) migration noise
angeloreale Jul 29, 2024
57babc1
ar(fix) migration noise
angeloreale Jul 29, 2024
7e16f64
ar(fix) migration noise
angeloreale Jul 29, 2024
6e49d5c
ar(fix) migration noise
angeloreale Jul 29, 2024
7f6c5bd
ar(fix) migration noise
angeloreale Jul 29, 2024
1b07fd1
ar(fix) migration noise
angeloreale Jul 29, 2024
4ae78fc
ar(fix) migration noise
angeloreale Jul 29, 2024
8e631b2
ar(fix) migration noise
angeloreale Jul 29, 2024
0b052e8
ar(fix) migration noise
angeloreale Jul 29, 2024
6a19540
ar(fix) migration noise
angeloreale Jul 29, 2024
4e30da2
ar(fix) migration noise
angeloreale Jul 29, 2024
f221f10
ar(fix) migration noise
angeloreale Jul 29, 2024
9dd126a
ar(fix) migration noise
angeloreale Jul 29, 2024
1d2842c
ar(fix) migration noise
angeloreale Jul 29, 2024
24205a6
ar(fix) migration noise
angeloreale Jul 29, 2024
80ca1ec
ar(fix) migration noise
angeloreale Jul 29, 2024
79330d9
ar(fix) migration noise
angeloreale Jul 29, 2024
1c2c64f
ar(fix) migration noise
angeloreale Jul 29, 2024
f19db75
ar(fix) migration noise
angeloreale Jul 29, 2024
a8496c6
ar(fix) migration noise
angeloreale Jul 29, 2024
d97573e
ar(fix) migration noise
angeloreale Jul 29, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 12 additions & 5 deletions lib/auth/constants.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
// constants.ts TS-Doc?

export const providers = [
{ id: 'email', name: 'Email', type: 'email' },
{ id: 'github', name: 'GitHub', type: 'oauth' },
Expand Down Expand Up @@ -27,17 +26,25 @@ const methods = {
},
getCsrf: async () => {
try {
const response = await fetch(`${process.env.NEXT_PUBLIC_NEXUS_HOST}/api/auth/csrf`);
const response = await fetch(`${process.env.NEXT_PUBLIC_NEXUS_HOST}/api/auth/csrf`, { credentials: 'include' });
const csrf = await response.json();
return csrf.csrfToken;
} catch (e) {
console.error(e);
}
},
getSession: async () => {
getSession: async (params = { cookies: '' }) => {
try {
const response = await fetch(`${process.env.NEXT_PUBLIC_NEXUS_HOST}/api/auth/session`);
const session = await response.json();
const response = await fetch(`${process.env.NEXT_PUBLIC_NEXUS_HOST}/api/auth/session`, {
method: 'GET',
headers: {
Accept: 'application/json',
'Content-Type': 'application/json',
Cookie: params?.cookies,
},
credentials: 'include',
});
const session = await response?.json();
return session;
} catch (e) {
console.error(e);
Expand Down
9 changes: 4 additions & 5 deletions lib/model/decorators/hypnos-public-decorator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import type { ICard } from '@dreampipcom/oneiros';
/* private */
const decorateListing = (listing: Record<string, any>, uMeta: any): ICard => {
const decd: ICard = {
id: `list__card--${listing?.title?.es}`,
id: `${listing.id}`,
className: '',
title: `${listing?.title?.es}`,
where: `${listing?.location?.name}`,
Expand All @@ -16,18 +16,17 @@ const decorateListing = (listing: Record<string, any>, uMeta: any): ICard => {
link: 'https://www.dreampip.com',
badgeLink: 'https://www.dreampip.com',
rating: '3/5',
selected: false,
selected: uMeta?.favorites?.includes(listing.id),
} as Record<string, any> as ICard;
// decd.favorite = undefined;
// if (uMeta?.rickmorty?.favorites?.characters?.includes(character?.id)) decd.favorite = true;
// else decd.favorite = false;

return decd;
};

/* public */
export const decorateHypnosPublicListings = async (listings: Record<string, any>[], uid: string): Promise<ICard[]> => {
export const decorateHypnosPublicListings = async (listings: Record<string, any>[], uMeta: any): Promise<ICard[]> => {
// const uMeta: UserSchema = await getUserMeta({ email: uid });
const decd: ICard[] = listings?.map((card) => decorateListing(card, { email: uid }));
const decd: ICard[] = listings?.map((card) => decorateListing(card, uMeta));
return decd;
};
29 changes: 21 additions & 8 deletions lib/model/decorators/rm-decorator.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,33 @@
/* eslint @typescript-eslint/consistent-type-assertions:0 */
// rm-decorator.ts input: rm meta; output: decorated rm meta;
'use server';
import type { IDCharacter, INCharacter } from '@types';
import type { ICard } from '@dreampipcom/oneiros';
import type { INCharacter } from '@types';

/* private */
const decorateCharacter = (character: INCharacter, uMeta: any): IDCharacter => {
const decd: IDCharacter = { ...character };
decd.favorite = undefined;
if (uMeta?.rickmorty?.favorites?.characters?.includes(character?.id)) decd.favorite = true;
else decd.favorite = false;
const decorateCharacter = (character: INCharacter, uMeta: any): ICard => {
const decd: ICard = {
id: `list__char--${character?.name}`,
className: '',
// onLike: () => {},
title: `${character?.name}`,
where: `${character?.location?.name}`,
when: `${character?.status}`,
image: `${character?.image}`,
price: '299€',
link: 'https://www.dreampip.com',
badgeLink: 'https://www.dreampip.com',
rating: '3/5',
selected: uMeta?.favorites?.includes(character.id),
} as Record<string, any> as ICard;

return decd;
};

/* public */
export const decorateRMCharacters = async (characters: INCharacter[], uid: string): Promise<IDCharacter[]> => {
export const decorateRMCharacters = async (characters: INCharacter[], uMeta: any): Promise<ICard[]> => {
// const uMeta: UserSchema = await getUserMeta({ email: uid });
const decd: IDCharacter[] = characters.map((char) => decorateCharacter(char, { email: uid }));
const decd: ICard[] = characters.map((char) => decorateCharacter(char, uMeta));
console.log({ characters, uMeta, decd });
return decd;
};
1 change: 1 addition & 0 deletions lib/model/interfaces/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ export { DATABASE_STRING, DATABASE_USERS_STRING, DATABASE_ORGS_STRING } from './
export { getCharacters as getRMCharacters } from './services/rickmorty/rm-connector';

export { getPublicListings as getHypnosPublicListings } from './services/hypnos/public/hypnos-public-connector';
export { updateUserFavoriteListings } from './services/hypnos/private/hypnos-private-user-connector';
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
// hypnos-private-user-like-listing.ts
// rm-connector.ts
// to-do: use prisma for graph type
import type { ICard } from '@dreampipcom/oneiros';

import { cookies } from 'next/headers';
// const CHARS = `
// query {
// characters() {
// info {
// count
// }
// results {
// id
// name
// status
// origin {
// name
// }
// location {
// name
// }
// image
// }
// }
// }
// `;

async function fetchREPL({ paramsStr, method, listings }: any) {
// to-do: might be worth hardcoding the api in case too many middleware requests are billed
try {
const cookieStore = cookies();
const cookieString = cookieStore.toString();
const payload = JSON.stringify({ listings });
const req = await fetch(`${process.env.API_HOST}/api/v1/user${paramsStr}`, {
method,
headers: {
'Content-Type': 'application/json',
cookies: cookieString,
},
body: payload,
credentials: 'include',
});
const json = await req.json();
return json;
} catch (e) {
return { ok: false, status: 500, message: JSON.stringify(e), data: [] };
}
}

export const updateUserFavoriteListings: ({ paramsStr }: any) => Promise<ICard[]> = async ({ listings }) => {
const entries = await fetchREPL({ paramsStr: '', method: 'PATCH', listings });
const response = entries?.data;
return response;
};
2 changes: 2 additions & 0 deletions lib/model/interfaces/services/hypnos/private/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// index.ts
export { updateUserFavoriteListings } from './hypnos-private-user-connector';
2 changes: 2 additions & 0 deletions lib/model/interfaces/services/index.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
// index.ts
import * as rickmorty from './rickmorty';
import * as hypnosPublic from './hypnos/public';
import * as hypnosPrivate from './hypnos/private';

const services = {
rickmorty,
hypnosPublic,
hypnosPrivate,
};

export default services;
1 change: 1 addition & 0 deletions lib/state/context-auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { createContext } from 'react';
export const AuthContext = createContext<IAuthContext>({
authd: false,
name: '',
user: {},
setter: undefined,
history: [],
});
4 changes: 2 additions & 2 deletions lib/types/contexts.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export interface History {
}

export interface INCharacter {
id: number;
id: string;
name: string;
status: string;
image: string;
Expand All @@ -31,7 +31,7 @@ export interface IAuthContext extends History {
authd?: boolean;
name?: string;
email?: string;
meta?: UserSchema;
user?: UserSchema;
}

export interface IGlobalContext extends History {
Expand Down
8 changes: 4 additions & 4 deletions lib/types/users.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ export interface UserDecoration {
/* temp optional */
username?: string;
bio?: string;
organizations: DUserOrgAmbiRelation[];
rickmorty: {
favorites: {
characters: INCharacter['id'][];
organizations?: DUserOrgAmbiRelation[];
rickmorty?: {
favorites?: {
characters?: INCharacter['id'][];
};
};
}
Expand Down
8 changes: 4 additions & 4 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"prepare": "husky"
},
"dependencies": {
"@dreampipcom/oneiros": "0.0.5",
"@dreampipcom/oneiros": "0.0.6",
"@sentry/nextjs": "7.118.0",
"next": "14.2.4",
"react": "18",
Expand Down
7 changes: 4 additions & 3 deletions src/app/components/client/blocks/topnav-view.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,10 @@ export const VTopNav = ({ user }: VTopNavProps) => {
if (!isUserLoaded && _user && !initd.current) {
loadUser({
authd: true,
name: user?.name || user?.email,
avatar: user?.image,
email: user?.email,
name: _user?.name || _user?.email,
avatar: _user?.image,
email: _user?.email,
user: _user,
});
initd.current = true;
}
Expand Down
8 changes: 4 additions & 4 deletions src/app/components/client/elements/hypnos-list-view.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ type VHPNPListingProps = VListingListProps;
export const VHPNPList = ({ listings }: VHPNPListingProps) => {
const hypnosPublicContext = useContext(HypnosPublicContext);

const { authd, email } = useContext(AuthContext);
const { authd, email, user } = useContext(AuthContext);

const globalContext = useContext(GlobalContext);
const { theme } = globalContext;
Expand All @@ -37,9 +37,9 @@ export const VHPNPList = ({ listings }: VHPNPListingProps) => {

const dispatchAddToFavorites = async (cid?: number) => {
const func = async (payload: IDPayload) => {
await addToFavorites();
await addToFavorites({ listings: [cid] });
const op_2 = await loadHypnosPublicListings();
loadListings({ characters: op_2 });
loadListings({ listings: op_2 });
};
favListing({ email, cid }, func);
};
Expand Down Expand Up @@ -77,7 +77,7 @@ export const VHPNPList = ({ listings }: VHPNPListingProps) => {
if (authd) {
return (
<article>
<DPCardGrid cards={currentListings} theme={theme} />
<DPCardGrid cards={currentListings} theme={theme} onLikeCard={dispatchAddToFavorites} />
</article>
);
}
Expand Down
23 changes: 8 additions & 15 deletions src/app/components/client/elements/rm-list-view.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// list-view.tsx
'use client';
import type { ICard } from '@dreampipcom/oneiros';
import type { INCharacter, IDPayload } from '@types';

import { useContext, useEffect, useRef, useMemo } from 'react';
Expand All @@ -13,7 +14,7 @@ import { CardGrid as DPCardGrid } from "@dreampipcom/oneiros";

// to-do: character type annotations
interface VCharactersListProps {
characters: INCharacter[];
characters: ICard[];
}

type VRMListProps = VCharactersListProps;
Expand All @@ -35,9 +36,9 @@ export const VRMList = ({ characters }: VRMListProps) => {

const dispatchAddToFavorites = async (cid?: number) => {
const func = async (payload: IDPayload) => {
await addToFavorites();
await addToFavorites({ listings: [cid] });
const op_2 = await getChars();
loadChars({ characters: op_2 });
loadChars({ listings: op_2 });
};
favChar({ email, cid }, func);
};
Expand Down Expand Up @@ -69,20 +70,12 @@ export const VRMList = ({ characters }: VRMListProps) => {
}, []);

const adaptedCharsToCards = useMemo(() => {
return chars?.map((char) => ({
id: `list__char--${char?.name}`,
className: '',
const res = chars?.map((char) => ({
...char,
onLike: () => {},
title: `${char?.name}`,
where: `${char?.location?.name}`,
when: `${char?.status}`,
image: `${char?.image}`,
price: '299€',
link: 'https://www.dreampip.com',
badgeLink: 'https://www.dreampip.com',
rating: '3/5',
selected: false,
}))
console.log({ chars, res })
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit

return res
}, [chars]);

if (!authd || !characters) return;
Expand Down
1 change: 1 addition & 0 deletions src/app/components/client/elements/signup-view.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ export const VSignUp = ({ providers, user }: VSignUpProps) => {
name: user?.name || user?.email,
avatar: user?.image,
email: user?.email,
user,
});
initd.current = true;
}
Expand Down
2 changes: 1 addition & 1 deletion src/app/components/server/blocks/hypnos-public-list.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
'use server';
import type { ICard } from '@dreampipcom/oneiros';
import { VHPNPList } from '@elements/client';
import { loadHypnosPublicListings } from '@gateway';
import { loadHypnosPublicListings, addToFavorites } from '@gateway';
import { HypnosPublicProvider } from '@state';

export const CHPNPList = async () => {
Expand Down
4 changes: 2 additions & 2 deletions src/app/components/server/blocks/rm-list.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
// list-controller.tsx
'use server';
import type { INCharacter } from '@types';
import type { ICard } from '@dreampipcom/oneiros';
import { VRMList } from '@elements/client';
import { loadChars } from '@gateway';
import { RickMortyProvider } from '@state';

export const CRMList = async () => {
const characters: INCharacter[] = await loadChars();
const characters: ICard[] = await loadChars();

return (
<RickMortyProvider>
Expand Down
Loading
Loading