This repository was archived by the owner on Apr 3, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathFileContainer.tsx
More file actions
80 lines (70 loc) · 1.77 KB
/
FileContainer.tsx
File metadata and controls
80 lines (70 loc) · 1.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
// Basic container for dashboard files
// Created by Hanyuan Li, @hanyuone (09/2021)
// # # #
// Wraps the contents of a file stored on the CMS into its own
// functional component, with hovering capabilities
import React from "react";
import styled, { css } from "styled-components";
import { useNavigate } from "react-router-dom";
import Renamable from "./Renamable";
type Props = {
name: string;
id: string;
selectedFile: string | null;
setSelectedFile: (id: string) => void;
};
type styledProps = {
active: boolean;
};
// Carry over styled component from FileRenderer.tsx
const IconContainer = styled.div<styledProps>`
--background-color: grey;
width: 55px;
height: 75px;
background: var(--background-color);
display: flex;
flex-direction: column;
text-align: center;
margin-bottom: 10px;
cursor: pointer;
border: ${(props) =>
props.active ? "3px solid red" : "3px solid var(--background-color)"};
`;
function FileContainer({ name, id, selectedFile, setSelectedFile }: Props) {
const handleClick = () => {
console.log(id);
setSelectedFile(id);
};
const navigate = useNavigate();
const handleDoubleClick = () => {
console.log(id);
setSelectedFile(id);
if (selectedFile !== null) {
navigate("/editor/" + selectedFile, {
replace: false,
state: {
filename: name,
},
}),
[navigate];
}
};
return (
<div
style={{
display: "flex",
flexDirection: "column",
alignItems: "center",
padding: "35px",
}}
>
<IconContainer
onClick={handleClick}
onDoubleClick={handleDoubleClick}
active={selectedFile == id}
/>
<Renamable name={name} id={id} />
</div>
);
}
export default FileContainer;