memos icon indicating copy to clipboard operation
memos copied to clipboard

Allow memo date change Firefox / Safari

Open RoccoSmit opened this issue 1 year ago • 1 comments

Describe the bug

in v0.22.4 the ability to update memo dates was reinstated. This feature works in Edge and Chrome but not Firefox or Safari

For Firefox this is due to needing a specific date string format provided as the datetime-local typed input value otherwise the time section of the datetime view is not populated. (Chromium based browsers don't have this issue because you can set the time on their calendar view, but you cant do this in Firefox of Safari)

This becomes an issue as Firefox only fires the change event needed to update the date time state if the complete date and time is set on the input

I dont have access to a Mac to debug and confirm this is the same reason for Safari not working, but a quick test showed Safari sets the date to undefined

POC to test this behaviour https://jsfiddle.net/95c2zae1/3/

Date format used when featured worked in v0.22.2 https://github.com/usememos/memos/blob/e4a09c407c6e2099462c0388e1441781829ad4b8/web/src/hooks/useDateTime.ts#L9

Date format used in v0.22.4 https://github.com/usememos/memos/blob/a94855516611ae56ff2ca9db9816866c3d18ab11/web/src/components/MemoEditor/index.tsx#L421

I've created a PR that will address fixing the date format https://github.com/usememos/memos/pull/3783

Steps to reproduce

1 -> Create memo using Firefox/Safari 2 -> Edit memo -> change date 3 -> date does not update on UI

The version of Memos you're using.

v0.22.4

Screenshots or additional context

No response

RoccoSmit avatar Aug 14 '24 11:08 RoccoSmit

Bump

30/08 Discord question re the issue https://discord.com/channels/1017113925776588902/1045138348165050409/1278800934012719104

RoccoSmit avatar Aug 30 '24 09:08 RoccoSmit

Actually, on Chrome for Android is not working either

ilteoood avatar Sep 10 '24 20:09 ilteoood

I can confirm that by editing a memo's date on Safari it will show Invalid instead of the picked date. If I save the post the app sets automatically the date to 1 January 1970.

lcfd avatar Sep 23 '24 10:09 lcfd

Note 1: the below should work as a temporary solution for Firefox and Safari(? untested) browsers, but it does not look like its a solution for chrome browsers on mobile (android)

Note 2: I only really care about the day of the memo not the time so this workaround is not suited if you are requiring time. In that case you are better off using a chromium browser to have time support.

Note 3: Please don't consider this a long term solution and close the issue 😅 The PR included in the issue looks like it is the correct way to fix this. I needed to get off 0.22.2 (last working date change) and onto 0.22.6 when it comes out (for the new partial string tags feature) hence the workaround while this issue is being reviewed

Go to settings -> system -> additional styles and add

input[type=datetime-local] {
    color: red;
    opacity: 100%;
}

When you edit a memo this will display the browser date picker rather than the Memos formatted representation of the date and it will set the colour to red so that I know its not ready to modify yet e.g. image

Next, go to settings -> system -> additional scripts and add

setInterval(() => {
    const matchingDates = document.querySelectorAll("input[type=datetime-local]");
    const matches = Array.prototype.slice.call(matchingDates);
                
    matches.forEach(match => {
        match.setAttribute("type", "date");
    })
}, 2000)

This will run a lookup every 2 seconds (2000 in code, fee free to modify milliseconds as needed) to see if a memo editor is open with an incompatible date time format. If one is found it change the format to date only.

In changing the format from date time to date only the CSS stops taking effect, moving the browser date picker back behind the Memos formatted representation of the date and then I know the date is ready to be set. e.g. image image image

I believe the 10am added to my dates are an adjustment for time zones

RoccoSmit avatar Sep 28 '24 01:09 RoccoSmit

Is this going to to be added in the next release? Great work by the way I really enjoy your tool :)

ulimanaio avatar Oct 04 '24 21:10 ulimanaio

https://github.com/user-attachments/assets/7adc14e0-224e-4b0b-9bf6-36419b39e253 your PR still could not fix my issue, that in ios safari, I could not change the date(the invalid date is fixed), i think it may because that the datetime-local is not support by safari-ios yet. https://developer.mozilla.org/en-US/docs/Web/API/HTMLInputElement/showPicker#browser_compatibility

raymondyan avatar Oct 10 '24 11:10 raymondyan

image I have make the change like this and it seems solve the issue above, i thought there is the conflict in the editor focus and datepicker focus. could you make the change into your PR as well.

raymondyan avatar Oct 10 '24 11:10 raymondyan

For now, I would recommend using the MUI/DateTimePicker to solve this issue. https://mui.com/x/api/date-pickers/date-time-picker/

johnnyjoygh avatar Oct 12 '24 08:10 johnnyjoygh

I'll give the MUI implementation a go on the weekend

RoccoSmit avatar Oct 17 '24 20:10 RoccoSmit

Update with https://github.com/usememos/memos/commit/cf1be81de244e30b0dc6b027150d6be0a379c08d

johnnyjoygh avatar Oct 19 '24 13:10 johnnyjoygh

:heart_eyes:

RoccoSmit avatar Oct 20 '24 02:10 RoccoSmit

Issue is not in English. It has been translated automatically.


:heart_eyes:

Issues-translate-bot avatar Oct 20 '24 02:10 Issues-translate-bot