Skip to content

Commit

Permalink
fix: do not hide label when pinned
Browse files Browse the repository at this point in the history
  • Loading branch information
pengx17 committed Aug 29, 2021
1 parent ae63d8f commit 47013b4
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 18 deletions.
4 changes: 0 additions & 4 deletions src/PageTabs.css
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,6 @@
@apply max-w-40;
}

.logseq-tab[data-active="false"][data-pined="true"] .logseq-tab-title {
@apply max-w-0 px-0;
}

.logseq-tab[data-active="false"] button:hover {
visibility: hidden;
}
Expand Down
29 changes: 16 additions & 13 deletions src/PageTabs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,19 @@ const CloseSVG = () => (
</svg>
);

function isTabActive(tab: ITabInfo, activePage: ITabInfo | null) {
function isTabEqual(
tab: ITabInfo | null | undefined,
anotherTab: ITabInfo | null | undefined
) {
function isEqual(a?: string, b?: string) {
return a?.toLowerCase() === b?.toLowerCase();
}
return Boolean(
activePage &&
(isEqual(tab.name, activePage?.originalName) ||
isEqual(tab.name, activePage.name))
isEqual(tab?.originalName, anotherTab?.originalName) ||
isEqual(tab?.name, anotherTab?.name) ||
isEqual(tab?.uuid, anotherTab?.uuid) ||
// @ts-expect-error
tab?.alias?.includes(anotherTab?.id)
);
}

Expand Down Expand Up @@ -77,7 +82,7 @@ function Tabs({
style={{ width: "fit-content" }}
>
{tabs.map((tab, idx) => {
const isActive = isTabActive(tab, activePage);
const isActive = isTabEqual(tab, activePage);
const onClickTab = () =>
logseq.App.pushState("page", { name: tab.originalName });
const onClose: React.MouseEventHandler = (e) => {
Expand Down Expand Up @@ -189,8 +194,7 @@ export function PageTabs(): JSX.Element {
const newTabs = [...tabs];
newTabs.splice(idx, 1);
setTabs(newTabs);
if (tab.uuid === activePage?.uuid) {
console.log("closing tab");
if (isTabEqual(tab, activePage)) {
logseq.App.pushState("page", {
name: newTabs[Math.min(newTabs.length - 1, idx)].originalName,
});
Expand All @@ -199,10 +203,9 @@ export function PageTabs(): JSX.Element {

const onNewTab = React.useCallback(
(t: ITabInfo | null) => {
console.log("add");
setTabs((_tabs) => {
if (t) {
if (_tabs.every((_t) => _t.uuid !== t.uuid)) {
if (_tabs.every((_t) => !isTabEqual(t, _t))) {
return [..._tabs, t];
} else {
// If it is already in the tab, just make it active
Expand All @@ -227,10 +230,10 @@ export function PageTabs(): JSX.Element {
// if new active page is NOT in the tabs
// - if current active page is pined, insert new tab at the end
// - if there is no
if (tabs.every((t) => t.uuid !== activePage?.uuid)) {
if (tabs.every((t) => !isTabEqual(t, activePage))) {
newTabs = [...tabs];
const currentIndex = tabs.findIndex(
(t) => t.uuid === prevActivePageRef.current?.uuid
const currentIndex = tabs.findIndex((t) =>
isTabEqual(t, prevActivePageRef.current)
);
const currentPinned = tabs[currentIndex]?.pined;
if (currentIndex === -1 || currentPinned) {
Expand All @@ -249,7 +252,7 @@ export function PageTabs(): JSX.Element {
setTabs((_tabs) =>
sortTabs(
_tabs.map((ct) =>
ct.uuid === t.uuid ? { ...t, pined: !t.pined } : ct
isTabEqual(t, ct) ? { ...t, pined: !t.pined } : ct
)
)
);
Expand Down
1 change: 0 additions & 1 deletion src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,6 @@ export function useOpeningPageTabs() {
return [tabs, setTabs] as const;
}


export function useAdpatMainUIStyle() {
React.useEffect(() => {
const listener = () => {
Expand Down

0 comments on commit 47013b4

Please sign in to comment.