-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ar(feat) [DPCP-38] [DPCP-39] [DPCP-46]: Abstract Views (#27)
* 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
1 parent
c562f2b
commit 0ec3ea3
Showing
15 changed files
with
348 additions
and
202 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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>; | ||
}; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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>; | ||
}; |
Oops, something went wrong.