Skip to content

Commit

Permalink
minor asset improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
indpurvesh committed Nov 16, 2024
1 parent be733b3 commit 3cc8be9
Show file tree
Hide file tree
Showing 9 changed files with 65 additions and 67 deletions.
15 changes: 8 additions & 7 deletions react-admin/src/pages/asset/AssetTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -91,15 +91,16 @@ function AssetTable() {

<div className="">
<AssetUploadModal
onCloseModal={onCloseUploadModal}
isOpen={isUploadAssetModalOpen}
submitHandler={submitHandler}
handleSubmit={handleSubmit}
register={register}
onCloseModal={onCloseUploadModal}
isOpen={isUploadAssetModalOpen}
submitHandler={submitHandler}
handleSubmit={handleSubmit}
register={register}
/>
<CreateFolderModal
onCloseModal={onCloseCreateFolderModal}
isOpen={isCreateFolderModalOpen}
parent_id={asset_id}
onCloseModal={onCloseCreateFolderModal}
isOpen={isCreateFolderModalOpen}
/>
</div>
</div>
Expand Down
7 changes: 5 additions & 2 deletions react-admin/src/pages/asset/CreateFolderModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,21 @@ import {useCreateFolder} from "./hooks/useCreateFolder";
type CreateFolderModalProps = {
isOpen: any,
onCloseModal: any,
parent_id?: string,
}

export const CreateFolderModal = (({
isOpen,
onCloseModal,
isOpen,
onCloseModal,
parent_id
}: CreateFolderModalProps) => {
const [t] = useTranslation("global");
const { mutate } = useCreateFolder()


const submitHandler: SubmitHandler<CreateFolderType> = ((data: CreateFolderType) => {
onCloseModal()
data.parent_id = parent_id
mutate(data)
})

Expand Down
84 changes: 39 additions & 45 deletions react-admin/src/pages/asset/DisplayAsset.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ import {
FolderPlusIcon,
} from "@heroicons/react/24/outline";
import { useDeleteFolder } from "./hooks/useDeleteFolder";
import { RenameFolderModal } from "./RenameFolderModal";
import { RenameAssetModal } from "./RenameAssetModal";
import { useTranslation } from "react-i18next";
import {Link} from "react-router-dom";
import {Menu, MenuButton, MenuItem, MenuItems} from "@headlessui/react";

type DisplayAssetProp = {
asset: IAssetModel;
Expand Down Expand Up @@ -42,48 +43,42 @@ export const DisplayAsset = ({ asset, openFolder }: DisplayAssetProp) => {
<>
<div key={asset.id} className="border rounded p-3">
<div className="mb-2 flex">
<RenameFolderModal
<RenameAssetModal
key={asset.id}
asset={asset}
onCloseModal={onCloseRenameFolderModal}
isOpen={isRenameFolderModalOpen}
/>
<div className="hs-dropdown relative ml-auto inline-flex">
<button
id={`hs-dropdown-folder-options-${asset.id}`}
type="button"
className="hs-dropdown-toggle hover:bg-gray-50"
aria-haspopup="menu"
aria-expanded="false"
aria-label="Dropdown"
>
<Menu as="div" className="relative ml-auto inline-block">
<MenuButton className="flex">
<EllipsisHorizontalCircleIcon className="text-gray-400 w-6 h-6" />
</button>

<div
className="hs-dropdown-menu transition-[opacity,margin] duration hs-dropdown-open:opacity-100 opacity-0 hidden min-w-[38px] bg-white shadow-md rounded-lg p-1 space-y-0.5 mt-2 after:h-4 after:absolute after:-bottom-4 after:start-0 after:w-full before:h-4 before:absolute before:-top-4 before:start-0 before:w-full"
role="menu"
aria-orientation="vertical"
aria-labelledby="hs-dropdown-default"
</MenuButton>
<MenuItems
as="div"
className="absolute shadow-md z-30 py-1.5 rounded-md bg-white border border-gray-100 w-fit"
>
<a
className="flex items-center gap-x-3.5 py-2 px-3 rounded-lg text-sm text-gray-800 hover:bg-gray-100 focus:outline-none focus:bg-gray-100"
onClick={(e) =>
onRemoveAssetOnClick(e, asset.asset_type, asset.id)
}
href="#"
>
{t("remove")}
</a>
<a
onClick={openRenameFolderModal}
className="flex items-center gap-x-3.5 py-2 px-3 rounded-lg text-sm text-gray-800 hover:bg-gray-100 focus:outline-none focus:bg-gray-100"
href="#"
>
{t("rename")}
</a>
</div>
</div>
<MenuItem as="div" className="cursor-pointer">
<a
className="flex items-center gap-x-3.5 py-2 px-3 rounded-lg text-sm text-gray-800 hover:bg-gray-100 focus:outline-none focus:bg-gray-100"
onClick={(e) =>
onRemoveAssetOnClick(e, asset.asset_type, asset.id)
}
href="#"
>
{t("remove")}
</a>
</MenuItem>
<MenuItem as="div" className="cursor-pointer">
<a
onClick={openRenameFolderModal}
className="flex items-center gap-x-3.5 py-2 px-3 rounded-lg text-sm text-gray-800 hover:bg-gray-100 focus:outline-none focus:bg-gray-100"
href="#"
>
{t("rename")}
</a>
</MenuItem>
</MenuItems>
</Menu>
</div>
<div className="flex justify-center h-40 mb-3">
{asset.asset_type === "FOLDER" ? (
Expand All @@ -93,7 +88,7 @@ export const DisplayAsset = ({ asset, openFolder }: DisplayAssetProp) => {
) : (
<>
<img
src={`${backend_url}/${asset.path}`}
src={`${backend_url}${asset.path}`}
className="h-40"
alt={asset.name}
/>
Expand All @@ -105,19 +100,18 @@ export const DisplayAsset = ({ asset, openFolder }: DisplayAssetProp) => {
{asset.asset_type === "FOLDER" ? (
<>
<button
onClick={e => openFolder(e, asset.id)}
className="bg-gray-100 py-2 px-1 rounded w-full hover:bg-gray-200" type="button">
<Link to={`/admin/asset/${asset.id}`}>
{asset.name}
</Link>
onClick={(e) => openFolder(e, asset.id)}
className="bg-gray-100 py-2 px-1 rounded w-full hover:bg-gray-200"
type="button"
>
<Link to={`/admin/asset/${asset.id}`}>{asset.name}</Link>
</button>
</>
) : (
<>
<div className="text-ellipsis w-full overflow-hidden bg-gray-100 py-2 px-1 rounded">

{/** ADD COPY ICON AND Allow them to copy the file name **/}
{asset.name}
{/** ADD COPY ICON AND Allow them to copy the file name **/}
{asset.name}
</div>
</>
)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,17 @@ import IAssetModel from "../../types/asset/IAssetModel";
import {RenameFolderType} from "../../types/asset/RenameFolderType";
import {useRenameFolder} from "./hooks/useRenameFolder";

type RenameFolderModalProps = {
type RenameAssetModalProps = {
isOpen: any,
onCloseModal: any,
asset: IAssetModel
}

export const RenameFolderModal = (({
export const RenameAssetModal = (({
isOpen,
onCloseModal,
asset
}: RenameFolderModalProps) => {
}: RenameAssetModalProps) => {
const [t] = useTranslation("global");
const { mutate } = useRenameFolder()

Expand Down Expand Up @@ -70,7 +70,7 @@ export const RenameFolderModal = (({
duration-150 ease-linear bg-primary-600 border border-primary-600 rounded-lg
hover:bg-red-500"
>
{t("create")}
{t("rename")}
</button>
<button
type="button"
Expand Down
4 changes: 4 additions & 0 deletions react-admin/src/pages/asset/hooks/useCreateFolder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,17 @@ import { useMutation, useQueryClient } from "@tanstack/react-query";
import { useAxios } from "../../../hooks/useAxios";
import IAssetSave from "../../../types/asset/IAssetSave";
import {CreateFolderType} from "../../../types/asset/CreateFolderType";
import {isEmpty} from "lodash";

export const useCreateFolder = () => {
const client = useAxios();
const queryClient = useQueryClient();

return useMutation({
mutationFn: async (data: CreateFolderType) => {
if (isEmpty(data.parent_id)) {
delete data.parent_id
}
return await client.post("/create-folder", data);
},
onSuccess: (res) => {
Expand Down
3 changes: 2 additions & 1 deletion react-admin/src/types/asset/CreateFolderType.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export type CreateFolderType = {
name: String;
name: string;
parent_id?: string;
}

5 changes: 1 addition & 4 deletions src/api/handlers/asset/rename_asset_api_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,13 @@ pub async fn rename_asset_api_handler(

return Err(Error::BadRequest(error_response));
}



let asset_model = state.asset_service
.find_by_id(&state.db, &asset_id)
.await?;
let old_asset_path = format!(".{}",asset_model.path);
let new_asset_path = format!("/public/upload/{}", &payload.name);

println!("OLD: {old_asset_path}, new_asset: {new_asset_path}");

if fs::try_exists(&old_asset_path).await? {
fs::rename(&old_asset_path, &format!(".{}", new_asset_path)).await?;
}
Expand Down
4 changes: 2 additions & 2 deletions src/api/handlers/asset/store_asset_api_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,9 @@ pub async fn store_asset_api_handler(
.await?;

creatable_asset_model.parent_id = query_parent_id;
asset_file = format!("{}/{}", parent_asset.path, new_file_name.clone());
asset_file = format!("/{}/{}", parent_asset.path, new_file_name.clone());
} else {
asset_file = format!("public/upload/{}", new_file_name.clone());
asset_file = format!("/public/upload/{}", new_file_name.clone());
}

creatable_asset_model.name = new_file_name.clone();
Expand Down
2 changes: 0 additions & 2 deletions src/providers/avored_template_provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ impl AvoRedTemplateProvider {
reg.register_template_file("forgot-password", "./resources/mail/forgot-password.hbs")?;
reg.register_template_file("contact-us-email", "./resources/mail/contact-us-email.hbs")?;


println!("config {:?}", config);
let creds = Credentials::new(config.smtp_username, config.smtp_password);

let mailer: AsyncSmtpTransport<Tokio1Executor> =
Expand Down

0 comments on commit 3cc8be9

Please sign in to comment.