Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add fallback behavior for showOpenFilePicker and showSaveFilePicker #967

Merged
merged 4 commits into from
Jan 16, 2025

Conversation

josxha
Copy link
Contributor

@josxha josxha commented Jan 16, 2025

Launch Checklist

  • Briefly describe the changes in this PR.
  • Link to related issues.
  • Include before/after visuals or gifs if this PR includes visual changes.
  • Write tests for all new functionality.
  • Add an entry to CHANGELOG.md under the ## main section.

Description

showOpenFilePicker and showSaveFilePicker are undefined on Firefox. With this pr, Maputnik uses the old behavior as a fallback. It keeps the naming "open" and "save" instead of "upload" and "download" to underline that the style stays within the browser and no actual upload happens.

@zstadler Could you give it a try, please?

Related Issue

Visual Changes

The "Save as" button gets hidden if showSaveFilePicker is not available since it would have no use.

Chrome Firefox

@josxha josxha changed the title add fallback behavior add fallback behavior for showOpenFilePicker and showSaveFilePicker Jan 16, 2025
@zstadler
Copy link
Collaborator

LGTM!

className="maputnik-big-button"
onClick={this.onOpenFile}><MdFileUpload/> {t("Open Style")}
</InputButton>
{typeof window.showOpenFilePicker === "function" ? (
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we use if-else here? I think it will be clearer...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this the syntax you want to go with?

  <div>
      {(() => {
        if (typeof window.showOpenFilePicker === "function") {
          return (
            <InputButton
                  className="maputnik-big-button"
                  onClick={this.onOpenFile}><MdFileUpload/> {t("Open Style")}
                </InputButton>
          )
        } else {
          return (
            <FileReaderInput onChange={this.onFileChanged} tabIndex={-1} aria-label={t("Open Style")}>
                  <InputButton className="maputnik-upload-button"><MdFileUpload /> {t("Open Style")}</InputButton>
                </FileReaderInput>
          )
        }
      })()}
    </div>

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the lambda mandatory? I recall that react has a simpler way to add if inside the render method...?

Copy link
Contributor Author

@josxha josxha Jan 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure how? I can't find anything about it in the react docs nor stackoverflow. Using a tenary operator appears to be the shortest way. Alternatively, we could move the html block before the return statement and use it from a variable.

@codecov-commenter
Copy link

Codecov Report

Attention: Patch coverage is 16.00000% with 21 lines in your changes missing coverage. Please review.

Project coverage is 58.94%. Comparing base (af01346) to head (dfbdfd6).
Report is 3 commits behind head on main.

Files with missing lines Patch % Lines
src/components/ModalOpen.tsx 23.52% 13 Missing ⚠️
src/components/ModalExport.tsx 0.00% 8 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #967      +/-   ##
==========================================
- Coverage   59.84%   58.94%   -0.91%     
==========================================
  Files         104      104              
  Lines        3011     3057      +46     
  Branches      680      687       +7     
==========================================
  Hits         1802     1802              
- Misses       1209     1255      +46     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@HarelM HarelM merged commit 405b8aa into maplibre:main Jan 16, 2025
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Cannot open local style file using Firefox
4 participants