-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* wip index * add ItemFeed * add passProps to Router * aliases * Created a module for Image upload (#8) * Add components (#7) * Add components * modify components.Index * modify components.Index * fmt --------- Co-authored-by: Elliot Braem <[email protected]> * version --------- Co-authored-by: Jiku Godwill Nsanwi <[email protected]> Co-authored-by: Zeeshan Ahmad <[email protected]>
- Loading branch information
1 parent
b484b1d
commit ce6604b
Showing
49 changed files
with
3,380 additions
and
289 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
node_modules/ | ||
node_modules/ | ||
build/ |
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,71 @@ | ||
const { Layout } = VM.require("${config_account}/widget/Layout") || { | ||
Layout: () => <>layout not found</>, | ||
}; | ||
|
||
const { Router } = VM.require("${config_account}/widget/Router") || { | ||
Router: () => <>router not found</>, | ||
}; | ||
|
||
const data = Social.index("post", "main", { order: "desc", limit: 1 }); | ||
|
||
const { accountId, blockHeight } = data && data.length && data[0]; | ||
|
||
// const item = { | ||
// path: `${accountId}/post/main`, | ||
// blockHeight: blockHeight, | ||
// type: "social", | ||
// }; | ||
|
||
// const item = { | ||
// path: `mob.near/post/main`, | ||
// blockHeight: "81101335", | ||
// type: "social", | ||
// }; | ||
|
||
const item = { | ||
path: "efiz.near/thing/core", | ||
}; | ||
|
||
const CSS = styled.div` | ||
width: 100%, | ||
height: 100vh; | ||
`; | ||
|
||
const Header = () => <div style={{ border: "solid" }}>header</div>; | ||
|
||
const Footer = () => <>built by everyone :)</>; | ||
|
||
const Sidebar = () => <>sidebar</>; | ||
|
||
const Content = () => ( | ||
<Layout blocks={{ Header, Footer }}> | ||
<div style={{ height: "60vh" }}> | ||
"mob.near/post/main@81101335" // this is a very personal thing... | ||
<p>{JSON.stringify(data)}</p> | ||
<Router | ||
config={{ | ||
param: "page", | ||
routes: { | ||
home: { | ||
path: "every.near/widget/every.thing.view", | ||
init: item, | ||
}, | ||
home: { | ||
path: "${config_account}/widget/Library", | ||
init: item, | ||
}, | ||
}, | ||
}} | ||
page={"home"} | ||
/> | ||
</div> | ||
</Layout> | ||
); | ||
|
||
return ( | ||
<CSS> | ||
<Layout variant="sidebar" blocks={{ Sidebar, Header, Footer }}> | ||
<Content /> | ||
</Layout> | ||
</CSS> | ||
); |
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,104 @@ | ||
const IPFSImageUpload = ({ | ||
key, | ||
name, | ||
className, | ||
img, | ||
setImg, | ||
msg, | ||
setMsg, | ||
onError, | ||
accepts, | ||
multiple, | ||
clickable, | ||
maxFiles, | ||
maxFileSize, | ||
minFileSize, | ||
dragActiveClassName, | ||
}) => { | ||
const attributes = { | ||
key, | ||
name, | ||
className, | ||
img, | ||
setImg, | ||
msg, | ||
setMsg, | ||
onError, | ||
accepts, | ||
multiple, | ||
clickable, | ||
maxFiles, | ||
maxFileSize, | ||
minFileSize, | ||
dragActiveClassName, | ||
}; | ||
const ipfsUrl = (cid) => `https://ipfs.near.social/ipfs/${cid}`; | ||
const uploadFile = (files) => { | ||
setMsg("Uploading..."); | ||
|
||
const file = files[0]; | ||
|
||
const uploadPromise = asyncFetch("https://ipfs.near.social/add", { | ||
method: "POST", | ||
headers: { | ||
"Content-Type": file.type, | ||
}, | ||
body: file, | ||
}) | ||
.then((response) => { | ||
if (!response.ok) { | ||
setMsg("Upload failed!"); | ||
return Promise.reject(new Error("Upload failed")); | ||
} | ||
return response.body; | ||
}) | ||
.then((data) => { | ||
console.log(data); | ||
setImg(data); | ||
}) | ||
.catch((error) => { | ||
console.error("Upload error:", error); | ||
setMsg("Upload failed!"); | ||
}) | ||
.finally(() => { | ||
setMsg("Replace Image"); | ||
}); | ||
|
||
uploadPromise | ||
.then(() => { | ||
console.log("Upload successful!"); | ||
}) | ||
.catch((error) => { | ||
console.error("Upload failed:", error); | ||
}); | ||
}; | ||
return ( | ||
<div className="d-inline-block" key={attributes.key}> | ||
{img?.cid && ( | ||
<div | ||
className="d-inline-block me-2 overflow-hidden align-middle" | ||
style={{ width: "2.5em", height: "2.5em" }} | ||
> | ||
<img | ||
className="rounded w-100 h-100" | ||
style={{ objectFit: "cover" }} | ||
src={ipfsUrl(img?.cid)} | ||
alt="upload preview" | ||
/> | ||
</div> | ||
)} | ||
<Files | ||
multiple={false} | ||
accepts={["image/*"]} | ||
minFileSize={1} | ||
clickable | ||
onChange={uploadFile} | ||
{...attributes} | ||
> | ||
{msg} | ||
</Files> | ||
</div> | ||
); | ||
}; | ||
|
||
return { IPFSImageUpload }; |
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,32 @@ | ||
const items = props.items; | ||
const renderItem = props.renderItem; | ||
const perPage = props.perPage || 10; | ||
|
||
const jItems = JSON.stringify(items); | ||
if (state.jItems !== jItems) { | ||
State.update({ | ||
items: 0, | ||
jItems, | ||
}); | ||
} | ||
|
||
const makeMoreItems = () => { | ||
State.update({ | ||
items: state.items + perPage, | ||
}); | ||
}; | ||
|
||
const Layout = props.Layout; | ||
|
||
const renderedItems = items.slice(0, state.items).map(renderItem); | ||
|
||
return ( | ||
<InfiniteScroll | ||
pageStart={0} | ||
loadMore={makeMoreItems} | ||
hasMore={state.items < items.length} | ||
loader={<div className="loader">Loading ...</div>} | ||
> | ||
{Layout ? <Layout>{renderedItems}</Layout> : <>{renderedItems}</>} | ||
</InfiniteScroll> | ||
); |
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,19 @@ | ||
const { Avatar } = VM.require("${config_account}/widget/components.ui.avatar"); | ||
const { AvatarGroup } = VM.require("${config_account}/widget/components.ui.avatar-group"); | ||
const { Badge } = VM.require("${config_account}/widget/components.ui.badge"); | ||
const { Button } = VM.require("${config_account}/widget/components.ui.button"); | ||
const { Chip } = VM.require("${config_account}/widget/components.ui.chip"); | ||
const { Container } = VM.require("${config_account}/widget/components.ui.container"); | ||
const { Logo } = VM.require("${config_account}/widget/components.ui.logo"); | ||
const { Tag } = VM.require("${config_account}/widget/components.ui.tag"); | ||
|
||
return { | ||
Avatar, | ||
AvatarGroup, | ||
Badge, | ||
Button, | ||
Chip, | ||
Container, | ||
Logo, | ||
Tag, | ||
}; |
Oops, something went wrong.