@@ -19,9 +19,11 @@ export type AssetMeta = AssetLocationAndInfo & {
1919export function useAttachments ( {
2020 projectId,
2121 outcome,
22+ useFallback,
2223} : {
2324 projectId : string
2425 outcome : ComputedOutcome
26+ useFallback : boolean
2527} ) {
2628 if ( ! isWeaveContext ( ) ) {
2729 return {
@@ -30,17 +32,25 @@ export function useAttachments({
3032 error : null ,
3133 }
3234 }
33- const cellIdWrapper = CellIdWrapper . fromCellIdString ( projectId )
34- const wal : WAL = {
35- hrl : [ cellIdWrapper . getDnaHash ( ) , decodeHashFromBase64 ( outcome . actionHash ) ] ,
36- context : 'outcome' ,
37- }
3835 const [ attachmentWALs , setAttachmentWALs ] = useState < WAL [ ] | null > ( null )
3936 const [ attachmentsInfo , setAttachmentsInfo ] = useState < AssetMeta [ ] > ( [ ] )
4037 const [ error , setError ] = useState ( null )
4138 const subscriptionRef = useRef < any > ( null )
4239
4340 useEffect ( ( ) => {
41+ if ( useFallback ) {
42+ setAttachmentWALs ( [ ] )
43+ setAttachmentsInfo ( [ ] )
44+ return
45+ }
46+ const cellIdWrapper = CellIdWrapper . fromCellIdString ( projectId )
47+ const wal : WAL = {
48+ hrl : [
49+ cellIdWrapper . getDnaHash ( ) ,
50+ decodeHashFromBase64 ( outcome . actionHash ) ,
51+ ] ,
52+ context : 'outcome' ,
53+ }
4454 const fetchAssetInfo = async ( ) => {
4555 const weaveClient = getWeaveClient ( )
4656
@@ -49,7 +59,7 @@ export function useAttachments({
4959 subscriptionRef . current &&
5060 typeof subscriptionRef . current === 'function'
5161 ) {
52- const unsubscribe = subscriptionRef . current ;
62+ const unsubscribe = subscriptionRef . current
5363 unsubscribe ( )
5464 }
5565 subscriptionRef . current = null
@@ -96,12 +106,12 @@ export function useAttachments({
96106 subscriptionRef . current &&
97107 typeof subscriptionRef . current === 'function'
98108 ) {
99- const unsubscribe = subscriptionRef . current ;
109+ const unsubscribe = subscriptionRef . current
100110 unsubscribe ( )
101111 }
102112 subscriptionRef . current = null
103113 }
104- } , [ projectId , outcome . actionHash ] ) // Dependencies that should trigger a refetch
114+ } , [ projectId , outcome ? .actionHash ] ) // Dependencies that should trigger a refetch
105115
106116 return { attachmentWALs, attachmentsInfo, error }
107117}
0 commit comments