mirror of
https://github.com/ragestudio/comty.git
synced 2025-06-12 12:04:16 +00:00
implement ImageUploader
This commit is contained in:
parent
9ae0aefb4c
commit
42df9eab11
@ -1 +0,0 @@
|
|||||||
export { default as UnsplashBrowser } from "./unsplashBrowser"
|
|
@ -1,14 +0,0 @@
|
|||||||
import React from "react"
|
|
||||||
|
|
||||||
export default (props) => {
|
|
||||||
const [searchValue, setSearchValue] = React.useState("")
|
|
||||||
const [results, setResults] = React.useState([])
|
|
||||||
|
|
||||||
|
|
||||||
return <div className="unsplashBrowser">
|
|
||||||
<h1>Search in Unsplash™</h1>
|
|
||||||
<div>
|
|
||||||
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
}
|
|
@ -1,7 +1,6 @@
|
|||||||
import React from "react"
|
import React from "react"
|
||||||
import * as antd from "antd"
|
import * as antd from "antd"
|
||||||
|
import loadable from "@loadable/component"
|
||||||
import { UnsplashBrowser } from "./components"
|
|
||||||
|
|
||||||
import "./index.less"
|
import "./index.less"
|
||||||
|
|
||||||
@ -82,41 +81,9 @@ export default [
|
|||||||
"group": "aspect",
|
"group": "aspect",
|
||||||
"title": "Background image",
|
"title": "Background image",
|
||||||
"description": "Change background image of the application. You can use a local image or a remote image (URL).",
|
"description": "Change background image of the application. You can use a local image or a remote image (URL).",
|
||||||
"component": (props) => {
|
"component": loadable(() => import("../components/ImageUploader")),
|
||||||
const [validUrl, setValidUrl] = React.useState(true)
|
"props": {
|
||||||
|
"noPreview": true,
|
||||||
const submitUrl = (e) => {
|
|
||||||
const url = e.target.value
|
|
||||||
|
|
||||||
// validate if value recived is url
|
|
||||||
if (!url.match(/^(http(s)?:\/\/)?(www\.)?[a-zA-Z0-9]+\.[a-zA-Z]+(\.[a-zA-Z]+)?(\/.*)?$/)) {
|
|
||||||
setValidUrl(false)
|
|
||||||
antd.message.error("Invalid URL")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
props.ctx.dispatchUpdate(url)
|
|
||||||
}
|
|
||||||
|
|
||||||
const onClickSearchUnsplash = () => {
|
|
||||||
antd.message.warn("This feature is not implemented yet.")
|
|
||||||
return false
|
|
||||||
window.app.SidedrawerController.open("unsplashBrowser", UnsplashBrowser)
|
|
||||||
}
|
|
||||||
|
|
||||||
return <div className="backgroundImageSetting">
|
|
||||||
<antd.Input
|
|
||||||
placeholder="https://example.com/image.png"
|
|
||||||
onPressEnter={submitUrl}
|
|
||||||
status={validUrl ? "default" : "error"}
|
|
||||||
/>
|
|
||||||
or
|
|
||||||
<antd.Button
|
|
||||||
onClick={onClickSearchUnsplash}
|
|
||||||
>
|
|
||||||
Search on Unsplash
|
|
||||||
</antd.Button>
|
|
||||||
</div>
|
|
||||||
},
|
},
|
||||||
"emitEvent": "modifyTheme",
|
"emitEvent": "modifyTheme",
|
||||||
"emissionValueUpdate": (value) => {
|
"emissionValueUpdate": (value) => {
|
||||||
|
@ -0,0 +1,65 @@
|
|||||||
|
import React from "react"
|
||||||
|
import { Button, Input, Upload } from "antd"
|
||||||
|
import { Icons } from "components/Icons"
|
||||||
|
|
||||||
|
import "./index.less"
|
||||||
|
|
||||||
|
export default (props) => {
|
||||||
|
const [value, setValue] = React.useState(props.ctx.currentValue)
|
||||||
|
|
||||||
|
const uploadImage = async (req) => {
|
||||||
|
const formData = new FormData()
|
||||||
|
|
||||||
|
formData.append("files", req.file)
|
||||||
|
|
||||||
|
const request = await window.app.api.withEndpoints("main").post.upload(formData, undefined).catch((error) => {
|
||||||
|
console.error(error)
|
||||||
|
antd.message.error(error)
|
||||||
|
|
||||||
|
return false
|
||||||
|
})
|
||||||
|
|
||||||
|
if (request) {
|
||||||
|
setValue(request.files[0].url)
|
||||||
|
props.ctx.dispatchUpdate(request.files[0].url)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return <div className="imageUploader">
|
||||||
|
{
|
||||||
|
!props.noPreview && value && <div className="uploadPreview">
|
||||||
|
<img src={value} />
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
|
||||||
|
<Input.Group compact>
|
||||||
|
<Input
|
||||||
|
placeholder="Image URL..."
|
||||||
|
value={value}
|
||||||
|
onChange={(e) => setValue(e.target.value)}
|
||||||
|
onPressEnter={() => props.ctx.dispatchUpdate(value)}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<Button
|
||||||
|
icon={<Icons.Save />}
|
||||||
|
onClick={() => props.ctx.dispatchUpdate(value)}
|
||||||
|
/>
|
||||||
|
</Input.Group>
|
||||||
|
|
||||||
|
or
|
||||||
|
|
||||||
|
<Upload
|
||||||
|
customRequest={uploadImage}
|
||||||
|
multiple={false}
|
||||||
|
accept="image/*"
|
||||||
|
progress={false}
|
||||||
|
fileList={[]}
|
||||||
|
>
|
||||||
|
<Button
|
||||||
|
icon={<Icons.Upload />}
|
||||||
|
>
|
||||||
|
Upload
|
||||||
|
</Button>
|
||||||
|
</Upload>
|
||||||
|
</div>
|
||||||
|
}
|
@ -0,0 +1,32 @@
|
|||||||
|
.imageUploader {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
align-items: center;
|
||||||
|
|
||||||
|
.uploadPreview {
|
||||||
|
width: 100px;
|
||||||
|
margin-bottom: 10px;
|
||||||
|
|
||||||
|
img {
|
||||||
|
width: 100%;
|
||||||
|
height: 100%;
|
||||||
|
|
||||||
|
border-radius: 8px;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.ant-input-group {
|
||||||
|
display: inline-flex;
|
||||||
|
flex-direction: row;
|
||||||
|
width: 100%;
|
||||||
|
|
||||||
|
.ant-btn {
|
||||||
|
border-top-left-radius: 0;
|
||||||
|
border-bottom-left-radius: 0;
|
||||||
|
|
||||||
|
svg {
|
||||||
|
margin: 0!important;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1,5 +1,5 @@
|
|||||||
import AppSettings from "./app"
|
import AppSettings from "./app"
|
||||||
import AccountSettings from "./account"
|
import ProfileSettings from "./profile"
|
||||||
import SecuritySettings from "./security"
|
import SecuritySettings from "./security"
|
||||||
import NotificationsSettings from "./notifications"
|
import NotificationsSettings from "./notifications"
|
||||||
import ApparenceSettings from "./apparence"
|
import ApparenceSettings from "./apparence"
|
||||||
@ -11,10 +11,10 @@ export default {
|
|||||||
label: "App",
|
label: "App",
|
||||||
settings: AppSettings
|
settings: AppSettings
|
||||||
},
|
},
|
||||||
account: {
|
profile: {
|
||||||
icon: "User",
|
icon: "User",
|
||||||
label: "Profile",
|
label: "Profile",
|
||||||
settings: AccountSettings
|
settings: ProfileSettings
|
||||||
},
|
},
|
||||||
apparence: {
|
apparence: {
|
||||||
icon: "Eye",
|
icon: "Eye",
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
import React from "react"
|
import React from "react"
|
||||||
import { User } from "models"
|
import { User } from "models"
|
||||||
|
import loadable from "@loadable/component"
|
||||||
|
|
||||||
export default [
|
export default [
|
||||||
{
|
{
|
||||||
@ -94,10 +95,10 @@ export default [
|
|||||||
{
|
{
|
||||||
"id": "avatar",
|
"id": "avatar",
|
||||||
"group": "account.profile",
|
"group": "account.profile",
|
||||||
"component": "Input",
|
|
||||||
"icon": "Image",
|
"icon": "Image",
|
||||||
"title": "Avatar",
|
"title": "Avatar",
|
||||||
"description": "Change your avatar (Upload an image or use an URL)",
|
"description": "Change your avatar (Upload an image or use an URL)",
|
||||||
|
"component": loadable(() => import("../components/ImageUploader")),
|
||||||
"defaultValue": async () => {
|
"defaultValue": async () => {
|
||||||
const userData = await User.data()
|
const userData = await User.data()
|
||||||
return userData.avatar
|
return userData.avatar
|
||||||
@ -113,6 +114,7 @@ export default [
|
|||||||
})
|
})
|
||||||
|
|
||||||
if (result) {
|
if (result) {
|
||||||
|
app.message.success("Avatar updated")
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@ -121,10 +123,10 @@ export default [
|
|||||||
{
|
{
|
||||||
"id": "cover",
|
"id": "cover",
|
||||||
"group": "account.profile",
|
"group": "account.profile",
|
||||||
"component": "Input",
|
|
||||||
"icon": "Image",
|
"icon": "Image",
|
||||||
"title": "Cover",
|
"title": "Cover",
|
||||||
"description": "Change your profile cover (Upload an image or use an URL)",
|
"description": "Change your profile cover (Upload an image or use an URL)",
|
||||||
|
"component": loadable(() => import("../components/ImageUploader")),
|
||||||
"defaultValue": async () => {
|
"defaultValue": async () => {
|
||||||
const userData = await User.data()
|
const userData = await User.data()
|
||||||
return userData.cover
|
return userData.cover
|
||||||
@ -140,19 +142,12 @@ export default [
|
|||||||
})
|
})
|
||||||
|
|
||||||
if (result) {
|
if (result) {
|
||||||
|
app.message.success("Cover updated")
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"debounced": true,
|
"debounced": true,
|
||||||
},
|
},
|
||||||
{
|
|
||||||
"id": "cover",
|
|
||||||
"group": "account.profile",
|
|
||||||
"component": "ImageUpload",
|
|
||||||
"icon": "Image",
|
|
||||||
"title": "Cover",
|
|
||||||
"description": "Change your cover",
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
"id": "description",
|
"id": "description",
|
||||||
"group": "account.profile",
|
"group": "account.profile",
|
@ -10,7 +10,7 @@ export default [
|
|||||||
"title": "Change Password",
|
"title": "Change Password",
|
||||||
"description": "Change your password",
|
"description": "Change your password",
|
||||||
"icon": "Lock",
|
"icon": "Lock",
|
||||||
"component": loadable(() => import("./components/changePassword")),
|
"component": loadable(() => import("../components/changePassword")),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"id": "two-factor-authentication",
|
"id": "two-factor-authentication",
|
||||||
@ -26,7 +26,7 @@ export default [
|
|||||||
"title": "Sessions",
|
"title": "Sessions",
|
||||||
"description": "Manage your active sessions",
|
"description": "Manage your active sessions",
|
||||||
"icon": "Monitor",
|
"icon": "Monitor",
|
||||||
"component": loadable(() => import("./components/sessions")),
|
"component": loadable(() => import("../components/sessions")),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"id": "logout",
|
"id": "logout",
|
||||||
|
@ -298,6 +298,7 @@ const SettingItem = (props) => {
|
|||||||
{loading ? <div> Loading... </div> : React.createElement(SettingComponent, {
|
{loading ? <div> Loading... </div> : React.createElement(SettingComponent, {
|
||||||
...item.props,
|
...item.props,
|
||||||
ctx: {
|
ctx: {
|
||||||
|
currentValue: value,
|
||||||
dispatchUpdate,
|
dispatchUpdate,
|
||||||
onUpdateItem,
|
onUpdateItem,
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user