Skip to content

Commit

Permalink
ar(feat) [DPCP-38] [DPCP-39] [DPCP-46]: Abstract Views (#27)
Browse files Browse the repository at this point in the history
* ar(feat) [DPCP-38] [DPCP-39] [DPCP-46]: Abstract Views

* ar(feat) [DPCP-38] [DPCP-39] [DPCP-46]: Abstract Views

* ar(feat) [DPCP-38] [DPCP-39] [DPCP-46]: Abstract Views

* ar(feat) [DPCP-38] [DPCP-39] [DPCP-46]: Abstract Views

* ar(feat) [DPCP-38] [DPCP-39] [DPCP-46]: Abstract Views

* ar(feat) [DPCP-38] [DPCP-39] [DPCP-46]: Abstract Views

* ar(feat) [DPCP-38] [DPCP-39] [DPCP-46]: Abstract Views

* ar(feat) [DPCP-38] [DPCP-39] [DPCP-46]: Abstract Views

* ar(feat) [DPCP-38] [DPCP-39] [DPCP-46]: Abstract Views

* ar(feat) [DPCP-38] [DPCP-39] [DPCP-46]: Abstract Views

* ar(feat) [DPCP-38] [DPCP-39] [DPCP-46]: Abstract Views

* ar(feat) [DPCP-38] [DPCP-39] [DPCP-46]: Abstract Views

* ar(feat) [DPCP-38] [DPCP-39] [DPCP-46]: Abstract Views

* ar(feat) [DPCP-38] [DPCP-39] [DPCP-46]: Abstract Views

* ar(feat) [DPCP-38] [DPCP-39] [DPCP-46]: Abstract Views

* ar(feat) [DPCP-38] [DPCP-39] [DPCP-46]: Abstract Views
  • Loading branch information
angeloreale authored Aug 5, 2024
1 parent c562f2b commit 0ec3ea3
Show file tree
Hide file tree
Showing 15 changed files with 348 additions and 202 deletions.
1 change: 1 addition & 0 deletions .env.public
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ NEXT_PUBLIC_NEXUS_BASE_PATH=
NEXT_PUBLIC_NEXUS_NAME=Nexus
NEXT_PUBLIC_NEXUS_LOGO_PATH=
NEXT_PUBLIC_NEXUS_DEFAULT_IMAGE_PATH=
NEXT_PUBLIC_MAPBOX_TOKEN=

# config
ENABLE_LOG=true
Expand Down
2 changes: 1 addition & 1 deletion lib/state/context-rm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { createContext } from 'react';

export const RMContext = createContext<IRMContext>({
initd: false,
characters: [],
listings: [],
setter: undefined,
history: [],
});
2 changes: 1 addition & 1 deletion lib/types/contexts.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export interface IGlobalContext extends History {
// to-do: characters type annotations
export interface IRMContext extends History {
initd?: boolean;
characters?: INCharacter[];
listings?: INCharacter[];
}

export interface IHypnosPublicContext extends History {
Expand Down
13 changes: 12 additions & 1 deletion next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,18 @@ const nextConfig = {
],
},
async redirects() {
return [];
return [
{
source: '/services/hypnos',
destination: '/services/hypnos/list',
permanent: false,
},
{
source: '/services/rickmorty',
destination: '/services/rickmorty/list',
permanent: false,
},
];
},
};

Expand Down
11 changes: 7 additions & 4 deletions src/app/components/client/blocks/topnav-view.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,17 +66,20 @@ export const VTopNav = ({ user }: VTopNavProps) => {
<DPTypo variant={TypographyVariant.SMALL}>
Welcome, {coercedName}
</DPTypo>
<InternalLink href="/services/rickmorty">
<InternalLink className="block" href="/services/rickmorty">
Rick Morty
</InternalLink>
<InternalLink href="/services/hypnos">
<InternalLink className="block" href="/services/hypnos">
hypnos
</InternalLink>
</div>
<VSignIn className="col-span-full col-start-0 md:col-span-3 md:col-start-9 lg:col-start-10 lg:col-span-2" user={_user} />
<DPGrid full bleed={EBleedVariant.ZERO} variant={EGridVariant.TWELVE_COLUMNS} className="col-span-full col-start-0 md:col-span-4 md:col-start-12 lg:col-span-4 lg:col-start-12">
<VSignIn className="col-span-full col-start-0 md:col-span-3 md:col-start-6 lg:col-start-8 lg:col-span-2" user={_user} />
<DPGrid full bleed={EBleedVariant.ZERO} variant={EGridVariant.TWELVE_COLUMNS} className="col-span-full col-start-0 md:col-span-6 md:col-start-12 lg:col-span-6 lg:col-start-12">
<div className="flex w-full sm:justify-end">
<AudioPlayer prompt="" theme={theme} />
<DPButton className="ml-a1" theme={theme} icon={ESystemIcon['card']} onClick={() => navigate(document.location.href.replace(/(map|calendar)/, 'list'))} />
<DPButton className="ml-a1" theme={theme} icon={ESystemIcon['map']} onClick={() => navigate(document.location.href.replace(/(list|calendar)/, 'map'))} />
<DPButton className="ml-a1" theme={theme} icon={ESystemIcon['calendar']} onClick={() => navigate(document.location.href.replace(/(list|map)/, 'calendar'))} />
<DPButton className="ml-a1" theme={theme} icon={ESystemIcon['lightbulb']} onClick={handleThemeSwitch} />
</div>
</DPGrid>
Expand Down
97 changes: 97 additions & 0 deletions src/app/components/client/elements/calendar-view.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
// hypnos-list-view.tsx
// @ts-nocheck
'use client';
import type { ICard } from '@dreampipcom/oneiros';
import type { IDPayload } from '@types';

import { useContext, useEffect, useRef, useMemo } from 'react';

import { clsx } from 'clsx';
import Image from 'next/image';
import { AuthContext, GlobalContext } from '@state';
import { navigate, addToFavorites } from '@gateway';
import { CalendarView } from "@dreampipcom/oneiros";

// to-do: character type annotations
interface VCalendarProps {
listings: ICard[];
favListing: (conf?: any) => any;
fetchListings: (conf?: any) => any;
loadListings: (conf?: any) => any;
decListings: (conf?: any) => any;
unloadListings: (conf?: any) => any;
favoriteType?: string;
listingContext: any;
}

type VHPNPCalendarProps = VCalendarProps;

export const VHPNPCalendar = ({ listings = () => {}, fetchListings = () => {}, favListing = () => {}, loadListings = () => {}, decListings = () => {}, unloadListings = () => {}, listingContext = {}, favoriteType }: VHPNPCalendarProps) => {
const [_isListingsLoaded, _loadListings] = loadListings({});
const [, _decListings] = decListings({});
const [, _unloadListings] = unloadListings({});
const [, _favListing] = favListing({});

const _listingContext = useContext(listingContext);

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

const globalContext = useContext(GlobalContext);
const { theme } = globalContext;

const initd = useRef(false);

if (!listingContext) return;

const { listings: currentListings }: { listings?: ICard[] } = _listingContext;


const dispatchAddToFavorites = async (cid?: number) => {
const func = async (payload: IDPayload) => {
const res = await addToFavorites({ listings: [cid], type: favoriteType });
const op_2 = await fetchListings();
_loadListings({ listings: op_2 });
};
_favListing({ email, cid }, func);
};

useEffect(() => {
if (authd && listings && !_isListingsLoaded && !initd.current) {
_loadListings({
listings: listings as ICard[],
});
initd.current = true;
}
}, [listings, _isListingsLoaded, _loadListings, authd]);

useEffect(() => {
if (authd && _isListingsLoaded) {
_decListings({ action: {} });

return () => {
// to-do decorate clean up
};
}
}, [_isListingsLoaded, authd]);

useEffect(() => {
if (!_isListingsLoaded) return;
return () => {
_unloadListings();
};
}, []);

if (!authd || !listings) return;

if (!_isListingsLoaded && !listings) return <span>Loading...</span>;

if (authd) {
return (
<article>
<CalendarView cards={currentListings} theme={theme} />
</article>
);
}

return <button onClick={() => navigate('/api/auth/signin')}>Sign in</button>;
};
86 changes: 0 additions & 86 deletions src/app/components/client/elements/hypnos-list-view.tsx

This file was deleted.

5 changes: 3 additions & 2 deletions src/app/components/client/elements/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ export { VNavBar } from './navbar-view';
export { VUserSettings } from './usersettings-view';
export { VSignIn } from './signin-view';
export { VSignUp } from './signup-view';
export { VRMList } from './rm-list-view';
export { DPLinkDec as InternalLink } from './link-decorator';
export { VHPNPList } from './hypnos-list-view';
export { VHPNPList as ListView } from './list-view';
export { VHPNPCalendar as CalendarView } from './calendar-view';
export { VHPNPMap as MapView } from './map-view';
97 changes: 97 additions & 0 deletions src/app/components/client/elements/list-view.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
// hypnos-list-view.tsx
// @ts-nocheck
'use client';
import type { ICard } from '@dreampipcom/oneiros';
import type { IDPayload } from '@types';

import { useContext, useEffect, useRef, useMemo } from 'react';

import { clsx } from 'clsx';
import Image from 'next/image';
import { AuthContext, GlobalContext } from '@state';
import { navigate, addToFavorites } from '@gateway';
import { CardGrid as DPCardGrid } from "@dreampipcom/oneiros";

// to-do: character type annotations
interface VCalendarProps {
listings: ICard[];
favListing: (conf?: any) => any;
fetchListings: (conf?: any) => any;
loadListings: (conf?: any) => any;
decListings: (conf?: any) => any;
unloadListings: (conf?: any) => any;
favoriteType?: string;
listingContext: any;
}

type VHPNPListingProps = VListingListProps;

export const VHPNPList = ({ listings, fetchListings, favListing, loadListings, decListings, unloadListings, listingContext, favoriteType }: VHPNPListingProps) => {
const [_isListingsLoaded, _loadListings] = loadListings({});
const [, _decListings] = decListings({});
const [, _unloadListings] = unloadListings({});
const [, _favListing] = favListing({});

const _listingContext = useContext(listingContext);

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

const globalContext = useContext(GlobalContext);
const { theme } = globalContext;

const initd = useRef(false);

if (!listingContext) return;

const { listings: currentListings }: { listings?: ICard[] } = _listingContext;


const dispatchAddToFavorites = async (cid?: number) => {
const func = async (payload: IDPayload) => {
const res = await addToFavorites({ listings: [cid], type: favoriteType });
const op_2 = await fetchListings();
_loadListings({ listings: op_2 });
};
_favListing({ email, cid }, func);
};

useEffect(() => {
if (authd && listings && !_isListingsLoaded && !initd.current) {
_loadListings({
listings: listings as ICard[],
});
initd.current = true;
}
}, [listings, _isListingsLoaded, _loadListings, authd]);

useEffect(() => {
if (authd && _isListingsLoaded) {
_decListings({ action: {} });

return () => {
// to-do decorate clean up
};
}
}, [_isListingsLoaded, authd]);

useEffect(() => {
if (!_isListingsLoaded) return;
return () => {
_unloadListings();
};
}, []);

if (!authd || !listings) return;

if (!_isListingsLoaded && !listings) return <span>Loading...</span>;

if (authd) {
return (
<article>
<DPCardGrid cards={currentListings} theme={theme} onLikeCard={dispatchAddToFavorites} />
</article>
);
}

return <button onClick={() => navigate('/api/auth/signin')}>Sign in</button>;
};
Loading

0 comments on commit 0ec3ea3

Please sign in to comment.