mirror of
https://github.com/XFox111/TabsAsideExtension.git
synced 2026-04-22 07:58:01 +03:00
58d8e864e0
* feat: add ability to hide collections #211 (#213) * feat: add ability to hide collections #211 * fix: hide/unhide collection label is swapped * fix: missing useCallback dependency * fix: add selected tabs to existing collection adds all tabs in current window #215 (#216) * fix: add selected tabs to existing collection adds all tabs in current window #215 * fix: force selected tabs only for adding tabs to groups * feat: compact collection view (#214) * feat: compact collection view #201 * loc: compact view localization * fix(loc): missing "color" translation in edit dialog * feat: add ability to edit saved tabs (#218) * feat: adds option to edit saved tabs #217 * loc: translations for #217 * build(deps): Bump the react group with 2 updates (#221) Bumps the react group with 2 updates: [react](https://github.com/facebook/react/tree/HEAD/packages/react) and [react-dom](https://github.com/facebook/react/tree/HEAD/packages/react-dom). Updates `react` from 19.2.1 to 19.2.3 - [Release notes](https://github.com/facebook/react/releases) - [Changelog](https://github.com/facebook/react/blob/main/CHANGELOG.md) - [Commits](https://github.com/facebook/react/commits/v19.2.3/packages/react) Updates `react-dom` from 19.2.1 to 19.2.3 - [Release notes](https://github.com/facebook/react/releases) - [Changelog](https://github.com/facebook/react/blob/main/CHANGELOG.md) - [Commits](https://github.com/facebook/react/commits/v19.2.3/packages/react-dom) --- updated-dependencies: - dependency-name: react dependency-version: 19.2.3 dependency-type: direct:production update-type: version-update:semver-patch dependency-group: react - dependency-name: react-dom dependency-version: 19.2.3 dependency-type: direct:production update-type: version-update:semver-patch dependency-group: react ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * build(deps): Bump the deps group with 4 updates (#220) Bumps the deps group with 4 updates: [@fluentui/react-components](https://github.com/microsoft/fluentui), [@eslint/js](https://github.com/eslint/eslint/tree/HEAD/packages/js), [eslint](https://github.com/eslint/eslint) and [typescript-eslint](https://github.com/typescript-eslint/typescript-eslint/tree/HEAD/packages/typescript-eslint). Updates `@fluentui/react-components` from 9.72.8 to 9.72.9 - [Release notes](https://github.com/microsoft/fluentui/releases) - [Commits](https://github.com/microsoft/fluentui/compare/@fluentui/react-components_v9.72.8...@fluentui/react-components_v9.72.9) Updates `@eslint/js` from 9.39.1 to 9.39.2 - [Release notes](https://github.com/eslint/eslint/releases) - [Commits](https://github.com/eslint/eslint/commits/v9.39.2/packages/js) Updates `eslint` from 9.39.1 to 9.39.2 - [Release notes](https://github.com/eslint/eslint/releases) - [Commits](https://github.com/eslint/eslint/compare/v9.39.1...v9.39.2) Updates `typescript-eslint` from 8.49.0 to 8.51.0 - [Release notes](https://github.com/typescript-eslint/typescript-eslint/releases) - [Changelog](https://github.com/typescript-eslint/typescript-eslint/blob/main/packages/typescript-eslint/CHANGELOG.md) - [Commits](https://github.com/typescript-eslint/typescript-eslint/commits/v8.51.0/packages/typescript-eslint) --- updated-dependencies: - dependency-name: "@fluentui/react-components" dependency-version: 9.72.9 dependency-type: direct:production update-type: version-update:semver-patch dependency-group: deps - dependency-name: "@eslint/js" dependency-version: 9.39.2 dependency-type: direct:development update-type: version-update:semver-patch dependency-group: deps - dependency-name: eslint dependency-version: 9.39.2 dependency-type: direct:development update-type: version-update:semver-patch dependency-group: deps - dependency-name: typescript-eslint dependency-version: 8.51.0 dependency-type: direct:development update-type: version-update:semver-minor dependency-group: deps ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * chore: Bump version from 3.2.3 to 3.3.0 --------- Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
158 lines
5.1 KiB
TypeScript
158 lines
5.1 KiB
TypeScript
import { getCollectionTitle } from "@/entrypoints/sidepanel/utils/getCollectionTitle";
|
|
import { track } from "@/features/analytics";
|
|
import { useGroupColors } from "@/hooks/useGroupColors";
|
|
import { CollectionItem, GroupItem } from "@/models/CollectionModels";
|
|
import * as fui from "@fluentui/react-components";
|
|
import { Circle20Filled, CircleOff20Regular, Pin20Filled, Rename20Regular } from "@fluentui/react-icons";
|
|
import { ReactElement } from "react";
|
|
import { useStyles_EditDialog } from "./EditDialog.styles";
|
|
|
|
export default function EditDialog(props: GroupEditDialogProps): ReactElement
|
|
{
|
|
const [title, setTitle] = useState<string>(
|
|
(props.type === "collection"
|
|
? props.collection?.title :
|
|
(props.group?.pinned !== true ? props.group?.title : ""))
|
|
?? ""
|
|
);
|
|
|
|
const [color, setColor] = useState<`${Browser.tabGroups.Color}` | undefined | "pinned">(
|
|
props.type === "collection"
|
|
? props.collection?.color :
|
|
props.group?.pinned === true ? "pinned" : (props.group?.color ?? "blue")
|
|
);
|
|
|
|
const cls = useStyles_EditDialog();
|
|
const colorCls = useGroupColors();
|
|
const horizontalNavigationAttributes = fui.useArrowNavigationGroup({ axis: "horizontal" });
|
|
|
|
const onSubmit = (e: React.FormEvent<HTMLFormElement>) =>
|
|
{
|
|
e.preventDefault();
|
|
handleSave();
|
|
};
|
|
|
|
const handleSave = () =>
|
|
{
|
|
if (props.type === "collection" ? props.collection !== null : props.group !== null)
|
|
track("item_edited", { type: props.type });
|
|
else
|
|
track("item_created", { type: props.type });
|
|
|
|
if (props.type === "collection")
|
|
props.onSave({
|
|
type: "collection",
|
|
timestamp: props.collection?.timestamp ?? Date.now(),
|
|
color: (color === "pinned") ? undefined : color!,
|
|
title: title ? title : undefined,
|
|
items: props.collection?.items ?? []
|
|
});
|
|
else if (color === "pinned")
|
|
props.onSave({
|
|
type: "group",
|
|
pinned: true,
|
|
items: props.group?.items ?? []
|
|
});
|
|
else
|
|
props.onSave({
|
|
type: "group",
|
|
pinned: false,
|
|
color: color!,
|
|
title: title ? title : undefined,
|
|
items: props.group?.items ?? []
|
|
});
|
|
};
|
|
|
|
return (
|
|
<fui.DialogSurface className={ fui.mergeClasses(cls.surface, (color && color !== "pinned") && colorCls[color]) }>
|
|
<form onSubmit={ onSubmit }>
|
|
<fui.DialogBody>
|
|
<fui.DialogTitle>
|
|
{
|
|
props.type === "collection" ?
|
|
i18n.t(`dialogs.edit.title.${props.collection ? "edit" : "new"}_collection`) :
|
|
i18n.t(`dialogs.edit.title.${props.group ? "edit" : "new"}_group`)
|
|
}
|
|
</fui.DialogTitle>
|
|
|
|
<fui.DialogContent>
|
|
<div className={ cls.content }>
|
|
<fui.Field label={ i18n.t("dialogs.edit.collection_title") }>
|
|
<fui.Input
|
|
contentBefore={ <Rename20Regular /> }
|
|
disabled={ color === "pinned" }
|
|
placeholder={
|
|
props.type === "collection" ? getCollectionTitle(props.collection, true) : ""
|
|
}
|
|
value={ color === "pinned" ? i18n.t("groups.pinned") : title }
|
|
onChange={ (_, e) => setTitle(e.value) } />
|
|
</fui.Field>
|
|
<fui.Field label={ i18n.t("dialogs.edit.color") }>
|
|
<div className={ cls.colorPicker } { ...horizontalNavigationAttributes }>
|
|
{ (props.type === "group" && (!props.hidePinned || props.group?.pinned)) &&
|
|
<fui.ToggleButton
|
|
checked={ color === "pinned" }
|
|
onClick={ () => setColor("pinned") }
|
|
icon={ <Pin20Filled /> }
|
|
shape="circular"
|
|
>
|
|
{ i18n.t("groups.pinned") }
|
|
</fui.ToggleButton>
|
|
}
|
|
{ props.type === "collection" &&
|
|
<fui.ToggleButton
|
|
checked={ color === undefined }
|
|
onClick={ () => setColor(undefined) }
|
|
icon={ <CircleOff20Regular /> }
|
|
shape="circular"
|
|
>
|
|
{ i18n.t("colors.none") }
|
|
</fui.ToggleButton>
|
|
}
|
|
{ Object.keys(colorCls).map(i =>
|
|
<fui.ToggleButton
|
|
checked={ color === i }
|
|
onClick={ () => setColor(i as `${Browser.tabGroups.Color}`) }
|
|
className={ fui.mergeClasses(cls.colorButton, colorCls[i as `${Browser.tabGroups.Color}`]) }
|
|
icon={ {
|
|
className: cls.colorButton_icon,
|
|
children: <Circle20Filled />
|
|
} }
|
|
key={ i }
|
|
shape="circular"
|
|
>
|
|
{ i18n.t(`colors.${i as `${Browser.tabGroups.Color}`}`) }
|
|
</fui.ToggleButton>
|
|
) }
|
|
</div>
|
|
</fui.Field>
|
|
</div>
|
|
</fui.DialogContent>
|
|
|
|
<fui.DialogActions>
|
|
<fui.DialogTrigger disableButtonEnhancement>
|
|
<fui.Button appearance="primary" as="button" type="submit">{ i18n.t("common.actions.save") }</fui.Button>
|
|
</fui.DialogTrigger>
|
|
<fui.DialogTrigger disableButtonEnhancement>
|
|
<fui.Button appearance="subtle">{ i18n.t("common.actions.cancel") }</fui.Button>
|
|
</fui.DialogTrigger>
|
|
</fui.DialogActions>
|
|
</fui.DialogBody>
|
|
</form>
|
|
</fui.DialogSurface>
|
|
);
|
|
}
|
|
|
|
export type GroupEditDialogProps =
|
|
{
|
|
type: "collection";
|
|
collection?: CollectionItem;
|
|
onSave: (item: CollectionItem) => void;
|
|
} |
|
|
{
|
|
type: "group";
|
|
hidePinned?: boolean;
|
|
group?: GroupItem;
|
|
onSave: (item: GroupItem) => void;
|
|
};
|