Page Menu
Home
Sealhub
Search
Configure Global Search
Log In
Files
F9583791
collection.jsx
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
1 KB
Referenced Files
None
Subscribers
None
collection.jsx
View Options
const
React
=
require
(
"react"
);
const
CachedHttp
=
require
(
"./cached-http.js"
);
function
Collection
(
{
collection
,
query_store
,
get_forced_filter
=
()
=>
{},
get_forced_format
=
()
=>
{},
get_forced_sort
=
()
=>
{},
},
component
)
{
return
class
Component
extends
React
.
Component
{
constructor
()
{
super
();
this
.
state
=
{
loading
:
true
,
resources
:
[],
};
}
componentDidMount
()
{
this
.
refreshComponent
();
query_store
.
on
(
"change"
,
()
=>
this
.
refreshComponent
());
}
componentDidUpdate
(
prevProps
,
prevState
)
{
const
serialized_last_filter
=
JSON
.
stringify
(
get_forced_filter
(
prevProps
)
);
const
serialized_current_filter
=
JSON
.
stringify
(
get_forced_filter
(
this
.
props
)
);
if
(
serialized_last_filter
!==
serialized_current_filter
)
{
this
.
refreshComponent
();
}
}
refreshComponent
(
options
)
{
const
default_options
=
{
force
:
false
,
show_loading
:
true
,
};
const
{
force
,
show_loading
}
=
Object
.
assign
(
{},
default_options
,
options
);
if
(
force
)
CachedHttp
.
flush
();
if
(
show_loading
)
this
.
setState
({
loading
:
true
});
CachedHttp
.
get
(
`/api/v1/collections/
${
collection
}
`
,
{
filter
:
Object
.
assign
(
{},
query_store
.
getQuery
().
filter
,
get_forced_filter
(
this
.
props
)
),
format
:
get_forced_format
(
this
.
props
),
sort
:
get_forced_sort
(
this
.
props
),
}).
then
(
resources
=>
{
this
.
setState
({
resources
,
loading
:
false
});
});
}
render
()
{
return
React
.
createElement
(
component
,
{
collection
,
query_store
,
resources
:
this
.
state
.
resources
,
loading
:
this
.
state
.
loading
,
metadata
:
this
.
props
.
metadata
,
refresh
:
this
.
refreshComponent
.
bind
(
this
),
});
}
};
}
module
.
exports
=
Collection
;
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sat, Oct 11, 10:47 (1 d, 16 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
984238
Default Alt Text
collection.jsx (1 KB)
Attached To
Mode
rS Sealious
Attached
Detach File
Event Timeline
Log In to Comment