aboutsummaryrefslogtreecommitdiff
path: root/extension/src/components/BMEditor.tsx
blob: d66763e8cffa8ef9fdb6307edbaa4d3f3094dab9 (plain) (blame)
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
import React, {useContext, useEffect, useState} from "react";
import CloseIcon from "../assets/close.svg?react"
import {ActiveEdit} from "./Body.tsx";
import {getBrowser} from "../main.tsx";
import RadioButtonGroup from "./RadioButtonGroup.tsx";
import BMIcon from "./BMIcon.tsx";
import IconPicker from "./IconPicker.tsx";




function BMEditor() {
    const [activeEdit, setActiveEdit] = useContext(ActiveEdit);

    useEffect(() => {
        if (!activeEdit) return;
    }, [activeEdit]);

    function handleTitleChange(e: React.ChangeEvent<HTMLInputElement>) {
        getBrowser().bookmarks.update(activeEdit!.id, {title: e.target.value})
    }

    function handleURLChange(e: React.ChangeEvent<HTMLInputElement>) {
        getBrowser().bookmarks.update(activeEdit!.id, {url: e.target.value})
    }

    let isFolder = activeEdit && activeEdit.children /*&& activeEdit.children.length > 0;*/
    return (
        <div id="settings-menu" className={activeEdit ? "open" : "closed"}>
            <button id="settings-close" onClick={_ => setActiveEdit(null)}>
                <CloseIcon/>
            </button>

            {activeEdit && (<>
                <h1>Edit {isFolder ? "Folder" : "Bookmark"}</h1>

                <h3>Name</h3>
                <input type={"text"} defaultValue={activeEdit?.title} onBlur={handleTitleChange}/>

                {!isFolder && (<>
                    <h3>URL</h3>
                    <input type={"url"} defaultValue={activeEdit?.url} onBlur={handleURLChange}/>
                </>)}

                <h3>Icon</h3>
                <IconPicker bmData={activeEdit}/>

            </>)}
        </div>
    );
}

export default BMEditor;